Ejemplo n.º 1
0
 public function hookCancelProduct($params)
 {
     include_once dirname(__FILE__) . '/LoyaltyStateModule.php';
     include_once dirname(__FILE__) . '/LoyaltyModule.php';
     if (!Validate::isLoadedObject($params['order']) || !Validate::isLoadedObject($order_detail = new OrderDetail((int) $params['id_order_detail'])) || !Validate::isLoadedObject($loyalty = new LoyaltyModule((int) LoyaltyModule::getByOrderId((int) $params['order']->id)))) {
         return false;
     }
     $loyalty_new = new LoyaltyModule();
     $loyalty_new->points = -1 * LoyaltyModule::getNbPointsByPrice(number_format($order_detail->total_price_tax_incl, 2, '.', ''));
     $loyalty_new->id_loyalty_state = (int) LoyaltyStateModule::getCancelId();
     $loyalty_new->id_order = (int) $params['order']->id;
     $loyalty_new->id_customer = (int) $loyalty->id_customer;
     $loyalty_new->add();
     return;
 }
Ejemplo n.º 2
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
 }
Ejemplo n.º 3
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;
 }