function add($autodate = true, $null_values = false) { parent::add($autodate, $null_values); $order = new Order($this->id_order); if (!empty($order->id_cart)) { $res = Db::getInstance()->executeS('SELECT `delivery_date`, `delivery_time_from`, `delivery_time_to` ' . 'FROM ' . _DB_PREFIX_ . 'cart_product ' . 'WHERE `id_cart` = ' . (int) $order->id_cart . ' AND `id_product` = ' . (int) $this->product_id . ' AND `id_product_attribute` = ' . (int) $this->product_attribute_id . ' AND `id_shop` = ' . (int) $this->id_shop . ' ' . 'LIMIT 1'); if (!empty($res)) { $res = $res[0]; if (!empty($res)) { $res = Db::getInstance()->executeS('UPDATE ' . _DB_PREFIX_ . 'order_detail SET ' . '`delivery_date` = \'' . $res['delivery_date'] . '\', `delivery_time_from` = \'' . $res['delivery_time_from'] . '\', `delivery_time_to` = \'' . $res['delivery_time_to'] . '\' ' . 'WHERE `id_order` = ' . (int) $this->id_order . ' AND `product_id` = ' . (int) $this->product_id . ' AND `product_attribute_id` = ' . (int) $this->product_attribute_id . ' AND `id_shop` = ' . (int) $this->id_shop . ' '); } } } }
public function update($null_values = false) { if (!($res = parent::update($null_values))) { return false; } Db::getInstance()->delete('order_detail_employee', 'id_order_detail=' . (int) $this->id); if ((int) $this->id_employee > 0) { Db::getInstance()->insert('order_detail_employee', array('id_employee' => (int) $this->id_employee, 'id_order_detail' => (int) $this->id)); } return $res; }
/** * 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; }