예제 #1
0
 public function updateDiscountsApplies()
 {
     \mod_discount\classes\BaseDiscount::prepareOption(array('reBuild' => 1));
     $baseDiscount = \mod_discount\classes\BaseDiscount::create();
     if (\mod_discount\classes\BaseDiscount::checkModuleInstall()) {
         if ($baseDiscount->discountProductVal > $baseDiscount->discountNoProductVal) {
             $discount['result_sum_discount'] = $baseDiscount->discountProductVal;
             $discount['type'] = 'product';
         } else {
             $discount['result_sum_discount'] = $baseDiscount->discountNoProductVal;
             $discount['type'] = 'user';
         }
         if ($discount['result_sum_discount'] > 0) {
             if ($discount['type'] != 'product') {
                 $baseDiscount->updateDiskApply($baseDiscount->discountMax['key']);
             } else {
                 $cartItems = \Cart\BaseCart::getInstance()->getItems();
                 $diff = 0;
                 foreach ($cartItems['data'] as $item) {
                     if (is_null($item->discountKey)) {
                         continue;
                     }
                     $appliesLeft = \mod_discount\classes\BaseDiscount::create()->getAppliesLeft($item->discountKey);
                     if ($appliesLeft === null) {
                         continue;
                     }
                     for ($i = 0; $i < $item->quantity; $i++) {
                         if ($appliesLeft-- > 0) {
                             \mod_discount\classes\BaseDiscount::create()->updateDiskApply($item->discountKey);
                         }
                     }
                     if ($appliesLeft < 0) {
                         $appliesLeft = abs($appliesLeft);
                         $diff += ($item->originPrice - $item->price) * $appliesLeft;
                     }
                 }
                 if ($diff > 0) {
                     \CMSFactory\Events::create()->setListener(function (\SOrders $order, $price) use($diff) {
                         if (Mod_discount::$orderPassOverloadControl == false) {
                             $price = $order->getTotalPrice() + $diff;
                             $discount = $order->getDiscount() - $diff;
                             $order->setTotalPrice($price)->save();
                             Mod_discount::$orderPassOverloadControl = true;
                         }
                     }, 'Cart:MakeOrder');
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * get comulativ discount sorting
  * @access private
  * @author DevImageCms
  * @param (float) price optional 
  * @param (float) userId optional 
  * @param (bool) new optional 
  * @return array
  * @copyright (c) 2013, ImageCMS
  */
 private function getComulativDiscount($option)
 {
     if (count($option) > 0) {
         \mod_discount\classes\BaseDiscount::prepareOption($option);
     }
     $this->baseDiscount = \mod_discount\classes\BaseDiscount::create();
     if (\mod_discount\classes\BaseDiscount::checkModuleInstall()) {
         usort($this->baseDiscount->discountType['comulativ'], function ($a, $b) {
             return strnatcmp($a["begin_value"], $b["begin_value"]);
         });
     }
     return $this->baseDiscount->discountType['comulativ'];
 }