Exemplo n.º 1
0
 /**
  * __construct base object loaded
  * @access private
  * @author DevImageCms
  * @param ---
  * @return ---
  * @copyright (c) 2013, ImageCMS
  */
 private function __construct()
 {
     $this->ci =& get_instance();
     $lang = new \MY_Lang();
     $lang->load('mod_discount');
     require_once __DIR__ . '/models/discount_model_front.php';
     $this->ci->discount_model_front = new \discount_model_front();
     $this->baseDiscount = \mod_discount\classes\BaseDiscount::create();
     $this->discountForProduct = array_merge($this->baseDiscount->discountType['product'], $this->baseDiscount->discountType['brand'], $this->createChildDiscount($this->baseDiscount->discountType['category']));
 }
Exemplo n.º 2
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');
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Helper function for checking that user-group have no discounts already
  * @param int $groupId id of group
  * @return boolean true if user-group have no discounts alreaty, false otherwise
  */
 public static function validateGroupDiscount($groupId)
 {
     $data = \mod_discount\classes\BaseDiscount::create()->discountType['group_user'];
     foreach ($data as $oneDiscountData) {
         if ($oneDiscountData['group_id'] == $groupId) {
             return FALSE;
         }
     }
     return TRUE;
 }
Exemplo n.º 4
0
 /**
  * is in project gift certificate
  * @deprecated since version 4.5.2
  * @copyright (c) 2013, ImageCMS
  */
 public function is_gift_certificat()
 {
     return $this->isGiftCertificat();
     $this->baseDiscount = \mod_discount\classes\BaseDiscount::create();
     foreach ($this->baseDiscount->discountType['all_order'] as $disc) {
         if ($disc['is_gift']) {
             return true;
             break;
         }
     }
     return false;
 }