/** * __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'])); }
/** * __construct base object loaded * @access private * @author DevImageCms * @param --- * @return --- * @copyright (c) 2013, ImageCMS */ private function __construct() { $this->ci =& get_instance(); if (\mod_discount\classes\BaseDiscount::checkModuleInstall()) { require_once __DIR__ . '/../models/discount_model_front.php'; $this->ci->discount_model_front = new \discount_model_front(); $lang = new \MY_Lang(); $lang->load('mod_discount'); $this->cart = \Cart\BaseCart::getInstance(); if (!self::$userId) { $this->userGroupId = $this->ci->dx_auth->get_role_id(); $this->userId = $this->ci->dx_auth->get_user_id(); } else { $this->userId = self::$userId; $this->userGroupId = $this->ci->db->where('id', $this->userId)->get('users')->row()->role_id; } if (!self::$ignoreCart) { $this->cartData = $this->getCartData(); } $this->amoutUser = $this->ci->discount_model_front->getAmoutUser($this->userId); $this->totalPrice = !self::$totalPrice ? $this->cart->getOriginTotalPrice() : self::$totalPrice; $this->allDiscount = $this->getAllDiscount(); $this->discountType = $this->collectType($this->allDiscount); $this->discountAllOrder = $this->getAllOrderDiscountNotRegister(); if ($this->userId) { $this->discountUser = $this->getUserDiscount(); $this->discountGroupUser = $this->getUserGroupDiscount(); $this->discountComul = $this->getComulativDiscount(); $this->discountAllOrder = $this->getAllOrderDiscountRegister(); } $this->discountProductVal = self::$ignoreCart ? null : $this->getDiscountProducts(); $this->discountMax = $this->getMaxDiscount(array($this->discountUser, $this->discountGroupUser, $this->discountComul, $this->discountAllOrder), $this->totalPrice); $this->discountNoProductVal = $this->getDiscountValue($this->discountMax, $this->totalPrice); } }
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'); } } } } }
/** * 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; }
/** * render gift input * @deprecated since version 4.5.2 * @copyright (c) 2013, ImageCMS */ public function render_gift_input($mes = null) { if (\mod_discount\classes\BaseDiscount::checkModuleInstall()) { if ($this->is_gift_certificat()) { \CMSFactory\assetManager::create()->setData(array('mes' => $mes))->render('gift', true); } } }