Esempio n. 1
0
    public function getProductsDetail()
    {
        global $cookie;
        if (!Module::isInstalled('agilemultipleseller')) {
            return parent::getProductsDetail();
        }
        if (intval($cookie->id_employee) == 0) {
            return parent::getProductsDetail();
        }
        if (intval($cookie->profile) != intval(Configuration::get('AGILE_MS_PROFILE_ID'))) {
            return parent::getProductsDetail();
        }
        $sql = 'SELECT *
		FROM `' . _DB_PREFIX_ . 'order_detail` od
		    LEFT JOIN `' . _DB_PREFIX_ . 'product_owner` po ON od.product_id = po.id_product
		WHERE od.`id_order` = ' . (int) $this->id . ' AND po.id_owner = ' . $cookie->id_employee;
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    }
Esempio n. 2
0
 /**
  * calculate the the quantity to cancel at shopgate
  *
  * @param \ShopgateOrder     $sgOrder this is the shopgate object which was stored into
  *                                     the database on addOrder request
  * @param array             $cancelledItems
  * @param                  $message
  * @param \ShopgateLogger  $log
  *
  * @return array
  * @throws \ShopgateLibraryException
  */
 private function getCancellationData(ShopgateOrder $sgOrder, $cancelledItems, &$message, ShopgateLogger $log)
 {
     if (version_compare(_PS_VERSION_, '1.5.0', '>=')) {
         $pItems = OrderDetailCore::getList($this->id_order);
     } else {
         $pOrder = new OrderCore($this->id_order);
         $pItems = $pOrder->getProductsDetail();
     }
     if (empty($pItems)) {
         $errorMessage = "No products found to shopgate order id_order:{$sgOrder->getOrderNumber()}";
         $message .= $errorMessage;
         // changed log type to debug to prevent the creation
         // of huge log files
         $log->log($errorMessage, ShopgateLogger::LOGTYPE_DEBUG);
         return array();
     }
     foreach ($sgOrder->getItems() as $sgItem) {
         foreach ($pItems as $pItem) {
             $qty = null;
             $fromHook = false;
             $sgItemNumber = $sgItem->getItemNumber();
             // generate the item number as we do it for items with attributes
             if (!empty($pItem['product_attribute_id'])) {
                 $prestaItemNumber = $pItem['product_id'] . '-' . $pItem['product_attribute_id'];
             } else {
                 $prestaItemNumber = $pItem['product_id'];
             }
             if ($sgItemNumber == $prestaItemNumber) {
                 // There is no opportunity to deliver this information to
                 // Shopgate. We need to add a message to the order.
                 $refundPriceData = Tools::getValue('partialRefundProduct');
                 $refundQtyData = Tools::getValue('partialRefundProductQuantity');
                 if (!empty($refundPriceData[$pItem['id_order_detail']])) {
                     $currency = new CurrencyCore(ConfigurationCore::get("PS_CURRENCY_DEFAULT"));
                     $noteMsg = "Please note that these information could not be transmitted to Shopgate.\n";
                     $refundPrice = $refundPriceData[$pItem['id_order_detail']];
                     $refundPriceMsg = "The price of the Product (id:{$pItem['product_id']}) was refunded({$refundPrice}{$currency->sign}).\n";
                     if (empty($this->comments)) {
                         $this->comments = array();
                     }
                     if (is_string($this->comments)) {
                         $data = base64_decode($this->comments);
                         if (method_exists("Tools", "jsonDecode")) {
                             $this->comments = Tools::jsonDecode($data);
                         } else {
                             $this->comments = json_decode($data);
                         }
                     }
                     if (is_array($this->comments)) {
                         $this->comments[] = $noteMsg;
                         $this->comments[] = $refundPriceMsg;
                     }
                 }
                 // if the hook was executed or cancel_order request was sent from
                 // shopgate, we get the right data from version 1.5.0
                 // for lower versions we got two cases:
                 // * cancel order request, we need to get the cancelled quantity
                 //   out of the database (here we need to calculate it as in 1.5.00)
                 // * if the hook was executed from prestashop, we get the actual cancelled
                 //   amount in the $_POST array (here there is no need to calculate the cancelled)
                 //   value, cause we got it at this point
                 if (empty($refundQtyData[$pItem['id_order_detail']]) && Tools::isSubmit('partialRefundProduct')) {
                     continue;
                 } else {
                     $qty = $refundQtyData[$pItem['id_order_detail']];
                 }
                 // try to retrieve an $_POST['cancelQuantity'] array
                 $cancelQuantity = Tools::getValue('cancelQuantity', null);
                 if (version_compare(_PS_VERSION_, '1.5.0', '>=') && empty($qty)) {
                     $qty = $sgItem->getQuantity() - $pItem['product_quantity'];
                 } elseif (!empty($cancelQuantity[$pItem['id_order_detail']]) && empty($qty)) {
                     $qty = $cancelQuantity[$pItem['id_order_detail']];
                     $fromHook = true;
                 }
                 if (empty($qty) && Tools::getValue('action') == "cron") {
                     $qty = $pItem['product_quantity_refunded'];
                 }
                 // nothing to cancel here
                 if (empty($qty) || $qty < 1) {
                     continue;
                 }
                 $cancelledItems[$sgItemNumber]['data']['item_number'] = $pItem['product_id'];
                 // if someone changed the quantity for this item in the past
                 // we stored it in the database
                 if (empty($cancelledItems[$sgItemNumber]['data']['quantity'])) {
                     $oldQty = 0;
                 } else {
                     $oldQty = $cancelledItems[$sgItemNumber]['data']['quantity'];
                 }
                 if (empty($cancelledItems[$sgItemNumber]['data']['quantity'])) {
                     $cancelledItems[$sgItemNumber]['data']['quantity'] = $qty;
                     $cancelledItems[$sgItemNumber]['data']['quantity_to_cancel'] = $qty;
                 } else {
                     // subtract the old quantity
                     if (version_compare(_PS_VERSION_, '1.5.0', '>=') || !$fromHook) {
                         if (Tools::isSubmit('partialRefundProduct')) {
                             $cancelQuantity = $qty;
                         } else {
                             $cancelQuantity = $qty - $oldQty;
                         }
                     } else {
                         $cancelQuantity = $qty;
                     }
                     if ($cancelQuantity < 0) {
                         $cancelQuantity *= -1;
                     }
                     if ($cancelQuantity > 0) {
                         $cancelledItems[$sgItemNumber]['data']['quantity'] += $cancelQuantity;
                         $cancelledItems[$sgItemNumber]['data']['quantity_to_cancel'] = $cancelQuantity;
                     } else {
                         $cancelledItems[$sgItemNumber]['data']['quantity_to_cancel'] = 0;
                     }
                 }
                 if ($cancelQuantity > 0) {
                     $message .= "reducing quantity ({$cancelledItems[$sgItemNumber]['data']['quantity_to_cancel']}) for the item {$sgItemNumber} \n";
                 }
             }
         }
     }
     return $cancelledItems;
 }