public function applyToItem(BusinessRuleProductInterface $item)
 {
     if ($item instanceof OrderedItem) {
         $item->count->set($this->getFieldValue('count'));
         $item->save();
     }
 }
Example #2
0
 public function isItemApplicable(BusinessRuleProductInterface $item)
 {
     if (!$this->condition) {
         return true;
     }
     return $this->condition->isProductMatching($item->getProduct());
 }
 public function applyToItem(BusinessRuleProductInterface $item)
 {
     $taxClassID = $this->getFieldValue('taxClassID', -1);
     if ($taxClassID > 0) {
         $product = $item->getProduct();
         if ($product instanceof Product) {
             // ff('setting custom tax class ID: '.$taxClassID);
             $product->setTemporaryTaxClass(TaxClass::getInstanceByID($taxClassID));
         }
     }
 }
 public function applyToItem(BusinessRuleProductInterface $item)
 {
     $count = $item->getCount();
     $itemPrice = $item->getPriceWithoutTax();
     $discountPrice = $itemPrice - $this->getDiscountAmount($itemPrice);
     $discountStep = max($this->getParam('discountStep'), 1);
     $applicableCnt = floor($count / $discountStep);
     $limit = $this->getParam('discountLimit');
     if ($this->getParam('isOrderLevel')) {
         if ($this->getContext()->getOrder()) {
             $step = 0;
             $previousItems = 0;
             $totalCount = 0;
             $stop = false;
             $items = $this->getContext()->getOrder()->getShoppingCartItems();
             usort($items, array($this, 'sortByPrice'));
             // calculate total number of applicable item products and how many have higher priority (have already been processed)
             foreach ($items as $orderedItem) {
                 if ($this->isItemApplicable($orderedItem)) {
                     $totalCount += $orderedItem->getCount();
                     if ($orderedItem === $item) {
                         $stop = true;
                     }
                     if ($stop) {
                         continue;
                     }
                     $previousItems += $orderedItem->getCount();
                 }
             }
             $limit -= $previousItems;
             $applicableCnt = floor($totalCount / $discountStep) - $previousItems;
             $applicableCnt = min($count, $applicableCnt);
             $applicableCnt = max(0, $applicableCnt);
         } else {
             $applicableCnt = 0;
         }
     }
     if (!is_null($limit)) {
         $applicableCnt = min($limit, $applicableCnt);
         $applicableCnt = max(0, $applicableCnt);
     }
     $subTotal = $applicableCnt * $discountPrice + ($count - $applicableCnt) * $itemPrice;
     $item->setItemPrice($subTotal / $count);
 }
 public function applyToItem(BusinessRuleProductInterface $item)
 {
     if ($item instanceof OrderedItem) {
         $item->setSumVariationDiscounts(true);
     }
 }