コード例 #1
0
 /**
  *  Action 'add' du module 'cart' permettant d'ajouter un article
  *      dans le panier virtuel de l'utilisateur
  *
  * @param sfWebRequest $request
  */
 public function executeAdd(sfWebRequest $request)
 {
     if ($this->hasRequestParameter('id') && $this->hasRequestParameter('quantity')) {
         // on recupere les parametres de la requête
         $id = $request->getParameter('id');
         $quantity = $request->getParameter('quantity');
         // on recupere l'article dans la base de données
         $item = Doctrine::getTable('IStoreItem')->find($id);
         if ($item !== null) {
             // on recupere la panier virtuel stockés dans la session
             $shoppingCart = $this->getUser()->getShoppingCart();
             // si le produit n'existe pas, on l'ajoute au panier
             $shoppingCartItem = $shoppingCart->getItem($id, self::$_itemClass);
             if ($shoppingCartItem === null) {
                 $shoppingCartItem = new sfShoppingCartItem(self::$_itemClass, $id);
                 $shoppingCartItem->setQuantity($quantity);
                 $shoppingCartItem->setPrice($item->getUnitCost());
                 $shoppingCart->addItem($shoppingCartItem);
             } else {
                 $shoppingCartItem->setQuantity($shoppingCartItem->getQuantity() + $quantity);
             }
         }
         // on redirige vers le panier
         $this->forward('cart', 'show');
     }
     $this->forward404();
 }
コード例 #2
0
ファイル: actions.class.php プロジェクト: rafix/dmshop
 public function executeAdd_to_cart(dmWebRequest $request)
 {
     $this->forward404Unless($product = dmDb::table('Product')->findOneById($request->getParameter('id')));
     $item = new sfShoppingCartItem('Product', $this->getRequestParameter('id'));
     $item->setQuantity(1);
     $item->setPrice($product->getIsInAction() ? $product->getPriceAction() : $product->getPrice());
     $item->setName($product->getName());
     $shopping_cart = $this->getUser()->getShoppingCart();
     $shopping_cart->addItem($item);
     $this->redirectBack();
 }
コード例 #3
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = new sfShoppingCart();
     // item 1
     $item = new sfShoppingCartItem();
     $item->setId(1);
     $item->setPrice(14.4);
     $item->setQuantity(8);
     $item->setWeight(14.5);
     $item->setClass('IStoreShoppingCartItem');
     $this->object->addItem($item);
     // item 1
     $item = new sfShoppingCartItem();
     $item->setId(2);
     $item->setPrice(299.9);
     $item->setQuantity(3);
     $item->setWeight(8);
     $item->setClass('IStoreShoppingCartItem');
     $this->object->addItem($item);
 }
コード例 #4
0
 /**
  * Test de la méthode qui modifie le prix d'un article
  */
 public function testSetPrice()
 {
     $this->object->setPrice(17.8);
     $value = $this->object->getPrice();
     $this->assertEquals($value, 17.8);
 }