Esempio n. 1
0
 /**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $stubDispatcher = $this->getMockBuilder('\\Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $stubDispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($dummy, $cartEvent) {
         $ci = new CartItem();
         $ci->setId(3)->setPrice(123)->setPromo(0);
         $cartEvent->setCartItem($ci);
     }));
     $stubFacade->expects($this->any())->method('getDispatcher')->will($this->returnValue($stubDispatcher));
     $stubSession = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock();
     $stubSession->expects($this->any())->method('get')->will($this->onConsecutiveCalls(-1, 3));
     $stubRequest = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $stubRequest->expects($this->any())->method('getSession')->will($this->returnValue($stubSession));
     $stubFacade->expects($this->any())->method('getRequest')->will($this->returnValue($stubRequest));
     return $stubFacade;
 }
Esempio n. 2
0
 /**
  * Duplicate the current existing cart. Only the token is changed
  *
  * @param string $token
  * @param Customer $customer
  * @param Currency $currency
  * @param EventDispatcherInterface $dispatcher
  * @return Cart
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function duplicate($token, Customer $customer = null, Currency $currency = null, EventDispatcherInterface $dispatcher = null)
 {
     if (!$dispatcher) {
         return false;
     }
     $cartItems = $this->getCartItems();
     $cart = new Cart();
     $cart->setAddressDeliveryId($this->getAddressDeliveryId());
     $cart->setAddressInvoiceId($this->getAddressInvoiceId());
     $cart->setToken($token);
     $discount = 0;
     if (null === $currency) {
         $currencyQuery = CurrencyQuery::create();
         $currency = $currencyQuery->findPk($this->getCurrencyId()) ?: $currencyQuery->findOneByByDefault(1);
     }
     $cart->setCurrency($currency);
     if ($customer) {
         $cart->setCustomer($customer);
         if ($customer->getDiscount() > 0) {
             $discount = $customer->getDiscount();
         }
     }
     $cart->save();
     foreach ($cartItems as $cartItem) {
         $product = $cartItem->getProduct();
         $productSaleElements = $cartItem->getProductSaleElements();
         if ($product && $productSaleElements && $product->getVisible() == 1 && ($productSaleElements->getQuantity() >= $cartItem->getQuantity() || $product->getVirtual() === 1 || !ConfigQuery::checkAvailableStock())) {
             $item = new CartItem();
             $item->setCart($cart);
             $item->setProductId($cartItem->getProductId());
             $item->setQuantity($cartItem->getQuantity());
             $item->setProductSaleElements($productSaleElements);
             $prices = $productSaleElements->getPricesByCurrency($currency, $discount);
             $item->setPrice($prices->getPrice())->setPromoPrice($prices->getPromoPrice())->setPromo($productSaleElements->getPromo());
             $item->save();
             $dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem));
         }
     }
     try {
         $this->delete();
     } catch (\Exception $e) {
         // just fail silently in some cases
     }
     return $cart;
 }
Esempio n. 3
0
 /**
  * try to attach a new item to an existing cart
  *
  * @param EventDispatcherInterface $dispatcher
  * @param \Thelia\Model\Cart       $cart
  * @param int                      $productId
  * @param ProductSaleElements      $productSaleElements
  * @param float                    $quantity
  * @param ProductPriceTools        $productPrices
  *
  * @return CartItem
  */
 protected function doAddItem(EventDispatcherInterface $dispatcher, CartModel $cart, $productId, ProductSaleElements $productSaleElements, $quantity, ProductPriceTools $productPrices)
 {
     $cartItem = new CartItem();
     $cartItem->setDisptacher($dispatcher);
     $cartItem->setCart($cart)->setProductId($productId)->setProductSaleElementsId($productSaleElements->getId())->setQuantity($quantity)->setPrice($productPrices->getPrice())->setPromoPrice($productPrices->getPromoPrice())->setPromo($productSaleElements->getPromo())->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60 * 60 * 24 * 30))->save();
     return $cartItem;
 }
Esempio n. 4
0
 public function fillCart()
 {
     $currency = CurrencyQuery::create()->findOne();
     //create a fake cart in database;
     $cart = new Cart();
     $cart->setToken(uniqid("createorder", true))->setCustomer($this->customer)->setCurrency($currency)->save();
     /* add 3 items */
     $productList = array();
     for ($i = 0; $i < 3; $i++) {
         $pse = ProductSaleElementsQuery::create()->filterByProduct(ProductQuery::create()->filterByVisible(1)->filterById($productList, Criteria::NOT_IN)->find())->filterByQuantity(5, Criteria::GREATER_EQUAL)->joinProductPrice('pp', Criteria::INNER_JOIN)->addJoinCondition('pp', 'currency_id = ?', $currency->getId(), null, \PDO::PARAM_INT)->withColumn('`pp`.price', 'price_PRICE')->withColumn('`pp`.promo_price', 'price_PROMO_PRICE')->findOne();
         $productList[] = $pse->getProductId();
         $cartItem = new CartItem();
         $cartItem->setCart($cart)->setProduct($pse->getProduct())->setProductSaleElements($pse)->setQuantity($i + 1)->setPrice($pse->getPrice())->setPromoPrice($pse->getPromoPrice())->setPromo($pse->getPromo())->setPriceEndOfLife(time() + 60 * 60 * 24 * 30)->save();
         $this->cartItems[] = $cartItem;
     }
     $this->request->getSession()->setCart($cart->getId());
     return $cart;
 }
Esempio n. 5
0
 /**
  * Filter the query by a related \Thelia\Model\CartItem object
  *
  * @param \Thelia\Model\CartItem|ObjectCollection $cartItem  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCartQuery The current query, for fluid interface
  */
 public function filterByCartItem($cartItem, $comparison = null)
 {
     if ($cartItem instanceof \Thelia\Model\CartItem) {
         return $this->addUsingAlias(CartTableMap::ID, $cartItem->getCartId(), $comparison);
     } elseif ($cartItem instanceof ObjectCollection) {
         return $this->useCartItemQuery()->filterByPrimaryKeys($cartItem->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByCartItem() only accepts arguments of type \\Thelia\\Model\\CartItem or Collection');
     }
 }
Esempio n. 6
0
 /**
  * Exclude object from result
  *
  * @param   ChildCartItem $cartItem Object to remove from the list of results
  *
  * @return ChildCartItemQuery The current query, for fluid interface
  */
 public function prune($cartItem = null)
 {
     if ($cartItem) {
         $this->addUsingAlias(CartItemTableMap::ID, $cartItem->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * @inheritdoc
  */
 public function getCartItemDiscount(CartItem $cartItem)
 {
     return $cartItem->getQuantity() * $this->amount;
 }
Esempio n. 8
0
 /**
  * @inheritdoc
  */
 public function getCartItemDiscount(CartItem $cartItem)
 {
     return $cartItem->getQuantity() * $cartItem->getPrice() * ($this->percentage / 100);
 }
 /**
  * Filter the query by a related \Thelia\Model\CartItem object
  *
  * @param \Thelia\Model\CartItem|ObjectCollection $cartItem The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildLegacyCartItemAttributeCombinationQuery The current query, for fluid interface
  */
 public function filterByCartItem($cartItem, $comparison = null)
 {
     if ($cartItem instanceof \Thelia\Model\CartItem) {
         return $this->addUsingAlias(LegacyCartItemAttributeCombinationTableMap::CART_ITEM_ID, $cartItem->getId(), $comparison);
     } elseif ($cartItem instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(LegacyCartItemAttributeCombinationTableMap::CART_ITEM_ID, $cartItem->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCartItem() only accepts arguments of type \\Thelia\\Model\\CartItem or Collection');
     }
 }
 /**
  * Declares an association between this object and a ChildCartItem object.
  *
  * @param                  ChildCartItem $v
  * @return                 \LegacyProductAttributes\Model\LegacyCartItemAttributeCombination The current object (for fluent API support)
  * @throws PropelException
  */
 public function setCartItem(ChildCartItem $v = null)
 {
     if ($v === null) {
         $this->setCartItemId(NULL);
     } else {
         $this->setCartItemId($v->getId());
     }
     $this->aCartItem = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildCartItem object, it will not be re-added.
     if ($v !== null) {
         $v->addLegacyCartItemAttributeCombination($this);
     }
     return $this;
 }
Esempio n. 11
0
 /**
  * @inheritdoc
  */
 public function getCartItemDiscount(CartItem $cartItem)
 {
     return $cartItem->getQuantity() * $cartItem->getRealTaxedPrice($this->facade->getDeliveryCountry()) * ($this->percentage / 100);
 }