Beispiel #1
0
 public function hookCancelProduct($params)
 {
     if (!Validate::isLoadedObject($params['order']) or !Validate::isLoadedObject($orderDetail = new OrderDetail(intval($params['id_order_detail'])))) {
         return false;
     }
     if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(intval(LoyaltyModule::getByOrderId(intval($params['order']->id)))))) {
         return false;
     }
     $loyalty->points = $loyalty->points - LoyaltyModule::getNbPointsByPrice($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100) * $orderDetail->product_quantity);
     $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId();
     return $loyalty->save();
     // Automatically "historize" the modification
 }
Beispiel #2
0
 public function hookUpdateOrderStatus($params)
 {
     include_once dirname(__FILE__) . '/LoyaltyStateModule.php';
     include_once dirname(__FILE__) . '/LoyaltyModule.php';
     if (!Validate::isLoadedObject($params['newOrderStatus'])) {
         die($this->l('Missing parameters'));
     }
     $new_order = $params['newOrderStatus'];
     $order = new Order((int) $params['id_order']);
     if ($order && !Validate::isLoadedObject($order)) {
         die($this->l('Incorrect Order object.'));
     }
     $this->instanceDefaultStates();
     if ($new_order->id == $this->loyaltyStateValidation->id_order_state || $new_order->id == $this->loyaltyStateCancel->id_order_state) {
         if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id)))) {
             return false;
         }
         if ((int) Configuration::get('PS_LOYALTY_NONE_AWARD') && $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
             return true;
         }
         if ($new_order->id == $this->loyaltyStateValidation->id_order_state) {
             $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
             if ((int) $loyalty->points < 0) {
                 $loyalty->points = abs((int) $loyalty->points);
             }
         } elseif ($new_order->id == $this->loyaltyStateCancel->id_order_state) {
             $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId();
             $loyalty->points = 0;
         }
         return $loyalty->save();
     }
     return true;
 }
Beispiel #3
0
 public static function registerDiscount($discount)
 {
     if (!Validate::isLoadedObject($discount)) {
         die(Tools::displayError('Incorrect object Discount.'));
     }
     $items = self::getAllByIdCustomer($discount->id_customer, NULL, true);
     foreach ($items as $item) {
         $f = new LoyaltyModule($item['id_loyalty']);
         $f->id_discount = $discount->id;
         $f->id_loyalty_state = LoyaltyStateModule::getConvertId();
         $f->save();
     }
 }
 public static function registerDiscount($cartRule)
 {
     if (!Validate::isLoadedObject($cartRule)) {
         die(Tools::displayError('Incorrect object CartRule.'));
     }
     $items = self::getAllByIdCustomer((int) $cartRule->id_customer, NULL, true);
     $associated = false;
     foreach ($items as $item) {
         $lm = new LoyaltyModule((int) $item['id_loyalty']);
         /* Check for negative points for this order */
         $negativePoints = (int) Db::getInstance()->getValue('SELECT SUM(points) points FROM ' . _DB_PREFIX_ . 'loyalty WHERE id_order = ' . (int) $f->id_order . ' AND id_loyalty_state = ' . (int) LoyaltyStateModule::getCancelId() . ' AND points < 0');
         if ($lm->points + $negativePoints <= 0) {
             continue;
         }
         $lm->id_cart_rule = (int) $cartRule->id;
         $lm->id_loyalty_state = (int) LoyaltyStateModule::getConvertId();
         $lm->save();
         $associated = true;
     }
     return $associated;
 }
Beispiel #5
0
 public function hookCancelProduct($params)
 {
     global $cookie;
     include_once dirname(__FILE__) . '/LoyaltyStateModule.php';
     include_once dirname(__FILE__) . '/LoyaltyModule.php';
     $orderDetail = '';
     if (!isset($params['order_detail']) || !Validate::isLoadedObject($params['order_detail'])) {
         if (Validate::isLoadedObject($orderDetail = new OrderDetail((int) $params['id_order_detail']))) {
             $orderDetail = get_object_vars($orderDetail);
         }
     } else {
         $orderDetail = get_object_vars($params['order_detail']);
     }
     if (!Validate::isLoadedObject($order = $params['order']) || !Validate::isLoadedObject($loyalty = new LoyaltyModule((int) LoyaltyModule::getByOrderId((int) $params['order']->id)))) {
         return false;
     }
     if (is_array($orderDetail) && count($orderDetail)) {
         $order->setProductPrices($orderDetail);
     } else {
         return false;
     }
     $qtyList = Tools::getValue('cancelQuantity');
     if (isset($qtyList[$orderDetail['id_order_detail']])) {
         $qtyList = abs((int) $qtyList[$orderDetail['id_order_detail']]);
     } else {
         $qtyList = (int) $orderDetail['product_quantity'];
     }
     $product_price = $order->getTaxCalculationMethod() == PS_TAX_EXC ? $orderDetail['product_price'] + $orderDetail['ecotax'] : $orderDetail['product_price_wt'];
     $points = (int) LoyaltyModule::getNbPointsByPrice(number_format($product_price, 2, '.', ''), (int) $params['order']->id_currency) * $qtyList;
     if (!$order->hasBeenDelivered()) {
         if ($points > $loyalty->points) {
             $points = (int) $loyalty->points;
         }
         $loyalty->points = $loyalty->points - $points;
         return $loyalty->save();
     } else {
         $loyaltyNew = new LoyaltyModule();
         $loyaltyNew->points = -1 * $points;
         $loyaltyNew->id_loyalty_state = (int) LoyaltyStateModule::getCancelId();
         $loyaltyNew->id_order = (int) $params['order']->id;
         $loyaltyNew->id_customer = (int) $loyalty->id_customer;
         return $loyaltyNew->add();
     }
     return false;
 }