Ejemplo n.º 1
0
 /**
  * Import a Cart to the Order
  *
  * @param Object\CoreShopCart $cart
  * @return bool
  * @throws \Exception
  */
 public function importCart(Object\CoreShopCart $cart)
 {
     $items = array();
     $i = 1;
     foreach ($cart->getItems() as $cartItem) {
         $item = new Object\CoreShopOrderItem();
         $item->setKey($i);
         $item->setParent(Object\Service::createFolderByPath($this->getFullPath() . "/items/"));
         $item->setPublished(true);
         $item->setProduct($cartItem->getProduct());
         $item->setWholesalePrice($cartItem->getProduct()->getWholesalePrice());
         $item->setRetailPrice($cartItem->getProduct()->getRetailPrice());
         $item->setTax($cartItem->getProduct()->getTax());
         $item->setPrice($cartItem->getProduct()->getProductPrice());
         $item->setAmount($cartItem->getAmount());
         $item->setExtraInformation($cartItem->getExtraInformation());
         $item->save();
         $items[] = $item;
         $i++;
     }
     $this->setDiscount($cart->getDiscount());
     $this->setPriceRule($cart->getPriceRule());
     $this->setItems($items);
     $this->save();
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Remove Rule from Cart
  *
  * @param CoreShopCart $cart
  * @return bool
  */
 public function unApplyRule(CoreShopCart $cart)
 {
     if ($this->getGift() instanceof CoreShopProduct) {
         $cart->updateQuantity($this->getGift(), 0, false);
     }
     return true;
 }
Ejemplo n.º 3
0
 public function getShipping(\Pimcore\Model\Object\CoreShopCart $cart)
 {
     $maxDelivery = 0;
     foreach ($cart->getItems() as $item) {
         $deliveryForItem = $this->getShippingForItem($item);
         if ($deliveryForItem > $maxDelivery) {
             $maxDelivery = $deliveryForItem;
         }
     }
     return $maxDelivery;
 }
Ejemplo n.º 4
0
 /**
  * Prepare a Cart
  *
  * @return CoreShopCart
  * @throws \Exception
  */
 public static function prepare()
 {
     $cartsFolder = Service::createFolderByPath("/coreshop/carts/" . date("Y/m/d"));
     $cart = CoreShopCart::create();
     $cart->setKey(uniqid());
     $cart->setParent($cartsFolder);
     $cart->setPublished(true);
     if (Tool::getUser() instanceof CoreShopUser) {
         $cart->setUser(Tool::getUser());
     }
     $cart->save();
     return $cart;
 }
Ejemplo n.º 5
0
 /**
  * Prepare Cart
  *
  * @return CoreShopCart|static
  */
 public static function prepareCart()
 {
     $cartSession = self::getSession();
     if ($cartSession->cartId) {
         $cart = CoreShopCart::getById($cartSession->cartId);
         if ($cart instanceof CoreShopCart) {
             return $cart;
         }
     }
     $cart = CoreShopCart::prepare();
     $cartSession->cartId = $cart->getId();
     return $cart;
 }
 /**
  * Calculate discount
  *
  * @param Model\Object\CoreShopCart $cart
  * @return int
  */
 public function getDiscount(Model\Object\CoreShopCart $cart)
 {
     $discount = $cart->getShipping();
     return $discount;
 }
 /**
  * Calculate discount
  *
  * @param Model\Object\CoreShopCart $cart
  * @return int
  */
 public function getDiscount(Model\Object\CoreShopCart $cart)
 {
     return $cart->getSubtotal() * ($this->getPercent() / 100);
 }