Easy Ajax in symfony | symfony | Web PHP Framework - 0 views
-
<?php foreach ($sf_user->getAttribute('cart') as $product_id => $quantity): ?> <div> <?php for ($i = 1; $i <= $quantity; $i++): ?> <?php echo image_tag('product'.$product_id, array( 'class' => 'cart-items', 'id' => 'item_'.$product_id.'_'.$i, 'style' => 'position:relative' )) ?> <?php endfor; ?> (<?php echo $quantity ?> <?php echo $products[$product_id] ?>) </div> <?php endforeach; ?> <?php if (!$sf_user->getAttribute('cart')): ?> nothing yet in your shopping cart. <?php endif; ?>
-
public function executeAdd() { $tmp = split('_', $this->getRequestParameter('id', '')); $product_id = $tmp[1]; $cart = $this->getUser()->getAttribute('cart'); if (!isset($cart[$product_id])) { $cart[$product_id] = 1; } else { ++$cart[$product_id]; } $this->getUser()->setAttribute('cart', $cart); $this->products = $this->getProducts(); }