protected function prepareCart() { $this->cart = $this->view->cart = Tool::prepareCart(); if ($this->session->user instanceof CoreShopUser && !$this->cart->getUser() instanceof CoreShopUser) { $this->cart->setUser($this->session->user); $this->cart->save(); } PriceRule::autoRemoveFromCart($this->cart); PriceRule::autoAddToCart($this->cart); }
/** * Check if Cart is Valid for Condition * * @param Cart $cart * @param PriceRule $priceRule * @param bool|false $throwException * @return bool * @throws \Exception */ public function checkCondition(Cart $cart, PriceRule $priceRule, $throwException = false) { $session = Tool::getSession(); //Check Total For Customer if ($session->user instanceof CoreShopUser) { $orders = $session->user->getOrders(); $cartRulesUsed = 0; foreach ($orders as $order) { if ($order->getPriceRule() instanceof PriceRule && $order->getPriceRule()->getId() == $priceRule->getId()) { $cartRulesUsed++; } } if ($cartRulesUsed >= $this->getTotal()) { if ($throwException) { throw new \Exception("You cannot use this voucher anymore (usage limit reached)"); } else { return false; } } } return true; }
/** * @see Object\ClassDefinition\Data::getDataFromResource * @param integer $data * @return Country */ public function getDataFromResource($data) { if (intval($data) > 0) { return PriceRule::getById($data); } return null; }
public function deleteAction() { $id = $this->getParam("id"); $priceRule = PriceRule::getById($id); if ($priceRule instanceof PriceRule) { $priceRule->delete(); $this->_helper->json(array("success" => true)); } $this->_helper->json(array("success" => false)); }
public function cartruleAction() { $this->enableLayout(); if ($this->getRequest()->isPost()) { $cartRule = PriceRule::getByCode($this->getParam("cartRule")); if ($cartRule instanceof PriceRule) { if ($cartRule->checkValidity()) { $this->cart->addCartRule($cartRule); } else { die("not valid"); } } else { die("not found"); } } $this->_redirect($this->getParam("redirect") ? $this->getParam("redirect") : $this->view->url(array("action" => "list"), "coreshop_cart")); }
/** * Changes the quantity of a Product in the Cart * * @param CoreShopProduct $product * @param int $amount * @param bool|true $autoAddCartRule * @return bool|CoreShopCartItem * @throws \Exception */ public function updateQuantity(CoreShopProduct $product, $amount = 0, $autoAddCartRule = true) { if (!$product instanceof CoreShopProduct) { throw new \Exception("\$product must be instance of CoreShopProduct"); } $item = $this->findItemForProduct($product); if ($item instanceof CoreShopCartItem) { if ($amount <= 0) { $this->removeItem($item); return false; } else { $item->setAmount($amount); $item->save(); } } else { $items = $this->getItems(); if (!is_array($items)) { $items = array(); } $item = new CoreShopCartItem(); $item->setKey(uniqid()); $item->setParent($this); $item->setAmount($amount); $item->setProduct($product); $item->setPublished(true); $item->save(); $items[] = $item; $this->setItems($items); $this->save(true); } if ($autoAddCartRule) { PriceRule::autoAddToCart(); } return $item; }