mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 11:43:16 +03:00
Replased SQL requests on object model
This commit is contained in:
parent
72913dee21
commit
3767445f68
@ -8,8 +8,8 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get customers history
|
* Get customers history
|
||||||
*
|
*
|
||||||
* @return string
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function customersHistory()
|
public static function customersHistory()
|
||||||
{
|
{
|
||||||
@ -122,6 +122,8 @@ class RetailcrmHistory
|
|||||||
* Update last sync id
|
* Update last sync id
|
||||||
*/
|
*/
|
||||||
Configuration::updateValue('RETAILCRM_LAST_CUSTOMERS_SYNC', $sinceid);
|
Configuration::updateValue('RETAILCRM_LAST_CUSTOMERS_SYNC', $sinceid);
|
||||||
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 'Nothing to sync';
|
return 'Nothing to sync';
|
||||||
}
|
}
|
||||||
@ -129,8 +131,8 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get orders history
|
* Get orders history
|
||||||
*
|
*
|
||||||
* @return string
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function ordersHistory()
|
public static function ordersHistory()
|
||||||
{
|
{
|
||||||
@ -193,14 +195,14 @@ class RetailcrmHistory
|
|||||||
$payment = $paymentCRM['type'];
|
$payment = $paymentCRM['type'];
|
||||||
} elseif (isset($order['payments']) && count($order['payments']) > 1) {
|
} elseif (isset($order['payments']) && count($order['payments']) > 1) {
|
||||||
foreach ($order['payments'] as $paymentCRM) {
|
foreach ($order['payments'] as $paymentCRM) {
|
||||||
if ($payment['status'] != 'paid') {
|
if ($paymentCRM['status'] != 'paid') {
|
||||||
$payment = $paymentCRM['type'];
|
$payment = $paymentCRM['type'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($payment, $payments) && $payments[$payment] != '') {
|
if (array_key_exists($payment, $payments) && !empty($payments[$payment])) {
|
||||||
if (Module::getInstanceByName($payments[$payment])) {
|
if (Module::getInstanceByName($payments[$payment])) {
|
||||||
$paymentType = Module::getModuleName($payments[$payment]);
|
$paymentType = Module::getModuleName($payments[$payment]);
|
||||||
} else {
|
} else {
|
||||||
@ -236,7 +238,7 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$deliveryType) {
|
if (!isset($deliveryType) || !$deliveryType) {
|
||||||
if ($deliveryDefault) {
|
if ($deliveryDefault) {
|
||||||
$deliveryType = $deliveryDefault;
|
$deliveryType = $deliveryDefault;
|
||||||
} else {
|
} else {
|
||||||
@ -384,19 +386,29 @@ class RetailcrmHistory
|
|||||||
);
|
);
|
||||||
|
|
||||||
$combinationPrice = Combination::getPrice($product_attribute_id);
|
$combinationPrice = Combination::getPrice($product_attribute_id);
|
||||||
$productPrice = $combinationPrice > 0 ? $product->getPrice()+ $combinationPrice : $product->getPrice();
|
$productPrice = $combinationPrice > 0 ? $product->getPrice() + $combinationPrice : $product->getPrice();
|
||||||
} else {
|
} else {
|
||||||
$productName = htmlspecialchars(strip_tags($product->name));
|
$productName = htmlspecialchars(strip_tags($product->name));
|
||||||
$productPrice = $product->getPrice();
|
$productPrice = $product->getPrice();
|
||||||
}
|
}
|
||||||
|
|
||||||
$product_list[] = array(
|
$product_list[] = array(
|
||||||
'product' => $product,
|
'id_product' => $product->id,
|
||||||
'product_attribute_id' => $product_attribute_id,
|
'id_product_attribute' => $product_attribute_id,
|
||||||
'product_price' => $product->price,
|
'price' => $product->price,
|
||||||
'product_price_inc_tax' => $productPrice,
|
'price_wt' => $productPrice,
|
||||||
'product_name' => $productName,
|
'name' => $productName,
|
||||||
'quantity' => $item['quantity']
|
'cart_quantity' => $item['quantity'],
|
||||||
|
'weight' => 0,
|
||||||
|
'weight_attribute' => 0,
|
||||||
|
'stock_quantity' => $item['quantity'],
|
||||||
|
'ecotax' => 0,
|
||||||
|
'id_shop' => Context::getContext()->shop->id,
|
||||||
|
'additional_shipping_cost' => 0,
|
||||||
|
'total_wt' => $productPrice * $item['quantity'],
|
||||||
|
'total' => $productPrice * $item['quantity'],
|
||||||
|
'wholesale_price' => $product->wholesale_price,
|
||||||
|
'id_supplier' => $product->id_supplier
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($item['discountTotal']) && self::$apiVersion == 5) {
|
if (isset($item['discountTotal']) && self::$apiVersion == 5) {
|
||||||
@ -407,8 +419,11 @@ class RetailcrmHistory
|
|||||||
$newOrder->add(false, false);
|
$newOrder->add(false, false);
|
||||||
|
|
||||||
if (isset($order['payments']) && !empty($order['payments'])) {
|
if (isset($order['payments']) && !empty($order['payments'])) {
|
||||||
foreach ($order['payments'] as $pay) {
|
foreach ($order['payments'] as $payment) {
|
||||||
if (!isset($pay['externalId']) && $pay['status'] == 'paid') {
|
if (!isset($payment['externalId'])
|
||||||
|
&& isset($payment['status'])
|
||||||
|
&& $payment['status'] == 'paid'
|
||||||
|
) {
|
||||||
$ptype = $payment['type'];
|
$ptype = $payment['type'];
|
||||||
$ptypes = $references->getSystemPaymentModules();
|
$ptypes = $references->getSystemPaymentModules();
|
||||||
if ($payments[$ptype] != null) {
|
if ($payments[$ptype] != null) {
|
||||||
@ -417,14 +432,13 @@ class RetailcrmHistory
|
|||||||
$payType = $pay['name'];
|
$payType = $pay['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$paymentType = Module::getModuleName($payments[$ptype]);
|
|
||||||
Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'order_payment`
|
$orderPayment = new OrderPayment();
|
||||||
(`payment_method`, `order_reference` , `amount`, `date_add`)
|
$orderPayment->payment_method = $payType;
|
||||||
VALUES
|
$orderPayment->order_reference = $newOrder->reference;
|
||||||
(\'' . $payType . '\',
|
$orderPayment->amount = $payment['amount'];
|
||||||
\'' . $newOrder->reference . '\',
|
$orderPayment->date_add = $payment['paidAt'];
|
||||||
\'' . $payment['amount'] . '\',
|
$orderPayment->save();
|
||||||
\'' . $payment['paidAt'] . '\')');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,38 +460,9 @@ class RetailcrmHistory
|
|||||||
/*
|
/*
|
||||||
* Create order details
|
* Create order details
|
||||||
*/
|
*/
|
||||||
$query = 'INSERT `'._DB_PREFIX_.'order_detail`
|
$orderDetail = new OrderDetail();
|
||||||
(
|
$orderDetail->createList($newOrder, $cart, $newOrder->current_state, $product_list);
|
||||||
`id_order`, `id_order_invoice`, `id_shop`, `product_id`, `product_attribute_id`,
|
$orderDetail->save();
|
||||||
`product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`,
|
|
||||||
`product_reference`, `total_price_tax_excl`, `total_price_tax_incl`,
|
|
||||||
`unit_price_tax_excl`, `unit_price_tax_incl`, `original_product_price`
|
|
||||||
)
|
|
||||||
|
|
||||||
VALUES';
|
|
||||||
|
|
||||||
$context = new Context();
|
|
||||||
foreach ($product_list as $product) {
|
|
||||||
$query .= '('
|
|
||||||
.(int) $newOrder->id.',
|
|
||||||
0,
|
|
||||||
'. Context::getContext()->shop->id.',
|
|
||||||
'.(int) $product['product']->id.',
|
|
||||||
'.$product['product_attribute_id'].',
|
|
||||||
'.implode('', array('\'', $product['product_name'], '\'')).',
|
|
||||||
'.(int) $product['quantity'].',
|
|
||||||
'.(int) $product['quantity'].',
|
|
||||||
'.$product['product_price'].',
|
|
||||||
'.implode('', array('\'', $product['product']->reference, '\'')).',
|
|
||||||
'.$product['product_price'].',
|
|
||||||
'.$product['product_price_inc_tax'].',
|
|
||||||
'.$product['product_price'].',
|
|
||||||
'.$product['product_price_inc_tax'].',
|
|
||||||
'.$product['product_price'].'
|
|
||||||
),';
|
|
||||||
}
|
|
||||||
|
|
||||||
Db::getInstance()->execute(rtrim($query, ','));
|
|
||||||
|
|
||||||
if (!empty($customerFix)) {
|
if (!empty($customerFix)) {
|
||||||
self::$api->customersFixExternalIds($customerFix);
|
self::$api->customersFixExternalIds($customerFix);
|
||||||
@ -496,55 +481,39 @@ class RetailcrmHistory
|
|||||||
$dtype = $order['delivery']['code'];
|
$dtype = $order['delivery']['code'];
|
||||||
$dcost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : null;
|
$dcost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : null;
|
||||||
|
|
||||||
if ($deliveries[$dtype] != null) {
|
if (isset($deliveries[$dtype]) && $deliveries[$dtype] != null) {
|
||||||
if ($deliveries[$dtype] != $orderToUpdate->id_carrier or $dcost != null) {
|
if ($deliveries[$dtype] != $orderToUpdate->id_carrier or $dcost != null) {
|
||||||
if ($dtype != null) {
|
if ($dtype != null) {
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'orders`
|
$orderCarrier = new OrderCarrier($orderToUpdate->id_order_carrier);
|
||||||
SET
|
$orderCarrier->id_carrier = $deliveries[$dtype];
|
||||||
`id_carrier` = \'' . $deliveries[$dtype] . '\'
|
|
||||||
WHERE
|
|
||||||
`id_order` = ' . (int)$order['externalId']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateCarrierFields = array();
|
|
||||||
if ($dtype != null) {
|
if ($dtype != null) {
|
||||||
$updateCarrierFields[] = '`id_carrier` = \'' . $deliveries[$dtype] . '\' ';
|
$orderCarrier->id_carrier = $deliveries[$dtype];
|
||||||
}
|
}
|
||||||
if ($dcost != null) {
|
if ($dcost != null) {
|
||||||
$updateCarrierFields[] = '`shipping_cost_tax_incl` = \'' . $dcost . '\' ';
|
$orderCarrier->shipping_cost_tax_incl = $dcost;
|
||||||
$updateCarrierFields[] = '`shipping_cost_tax_excl` = \'' . $dcost . '\' ';
|
$orderCarrier->shipping_cost_tax_excl = $dcost;
|
||||||
}
|
}
|
||||||
$updateCarrierFields = implode(', ', $updateCarrierFields);
|
|
||||||
|
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'order_carrier`
|
$orderCarrier->update();
|
||||||
SET
|
|
||||||
'.$updateCarrierFields.'
|
|
||||||
WHERE
|
|
||||||
`id_order` = \'' . $orderToUpdate->id . '\'');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* check payment type
|
* check payment type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!empty($order['paymentType']) && self::$apiVersion != 5) {
|
if (!empty($order['paymentType']) && self::$apiVersion != 5) {
|
||||||
$ptype = $order['paymentType'];
|
$ptype = $order['paymentType'];
|
||||||
|
|
||||||
if ($payments[$ptype] != null) {
|
if ($payments[$ptype] != null) {
|
||||||
$paymentType = Module::getModuleName($payments[$ptype]);
|
$paymentType = Module::getModuleName($payments[$ptype]);
|
||||||
if ($payments[$ptype] != $orderToUpdate->payment) {
|
if ($payments[$ptype] != $orderToUpdate->payment) {
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'orders`
|
$orderToUpdate->payment = $paymentType != null ? $paymentType : $payments[$ptype];
|
||||||
SET
|
$orderPayment = OrderPayment::getByOrderId($orderToUpdate->id);
|
||||||
`payment` = \'' . ($paymentType != null ? $paymentType : $payments[$ptype]). '\'
|
$orderPayment->payment_method = $payments[$ptype];
|
||||||
WHERE
|
$orderPayment->update();
|
||||||
`id_order` = ' . (int)$order['externalId']);
|
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'order_payment`
|
|
||||||
SET
|
|
||||||
`payment_method` = \'' . $payments[$ptype] . '\'
|
|
||||||
WHERE
|
|
||||||
`order_reference` = \'' . $orderToUpdate->reference . '\'');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!empty($order['payments']) && self::$apiVersion == 5) {
|
} elseif (!empty($order['payments']) && self::$apiVersion == 5) {
|
||||||
@ -562,19 +531,13 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$paymentType = Module::getModuleName($payments[$ptype]);
|
$paymentType = Module::getModuleName($payments[$ptype]);
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'orders`
|
$orderToUpdate->payment = $paymentType != null ? $paymentType : $payments[$ptype];
|
||||||
SET
|
$orderPayment = new OrderPayment();
|
||||||
`payment` = \'' . ($paymentType != null ? $paymentType : $payments[$ptype]). '\'
|
$orderPayment->payment_method = $payType;
|
||||||
WHERE
|
$orderPayment->order_reference = $orderToUpdate->reference;
|
||||||
`id_order` = ' . (int)$order['externalId']);
|
$orderPayment->amount = $payment['amount'];
|
||||||
|
$orderPayment->date_add = $payment['paidAt'];
|
||||||
Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'order_payment`
|
$orderPayment->save();
|
||||||
(`payment_method`, `order_reference` , `amount`, `date_add`)
|
|
||||||
VALUES
|
|
||||||
(\'' . $payType . '\',
|
|
||||||
\'' . $orderToUpdate->reference . '\',
|
|
||||||
\'' . $payment['amount'] . '\',
|
|
||||||
\'' . $payment['paidAt'] . '\')');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,11 +557,7 @@ class RetailcrmHistory
|
|||||||
$product_attribute_id = 0;
|
$product_attribute_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail`
|
self::deleteOrderDetailByProduct($orderToUpdate->id, $product_id, $product_attribute_id);
|
||||||
WHERE
|
|
||||||
`id_order` = '. $orderToUpdate->id .'
|
|
||||||
AND
|
|
||||||
`product_id` = '.$product_id. ' AND `product_attribute_id` = '.$product_attribute_id);
|
|
||||||
|
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
@ -647,22 +606,16 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
$productPrice = round($productPrice, 2);
|
$productPrice = round($productPrice, 2);
|
||||||
|
|
||||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'order_detail`
|
$orderDetail = new OrderDetail($orderItem['id_order_detail']);
|
||||||
SET
|
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||||
`unit_price_tax_incl` = '.$productPrice.'
|
|
||||||
WHERE
|
|
||||||
`id_order_detail` = '.$orderItem['id_order_detail']);
|
|
||||||
|
|
||||||
// quantity
|
// quantity
|
||||||
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
||||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'order_detail`
|
$orderDetail->product_quantity = $item['quantity'];
|
||||||
SET
|
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
||||||
`product_quantity` = '.$item['quantity'].',
|
|
||||||
`product_quantity_in_stock` = '.$item['quantity'].'
|
|
||||||
WHERE
|
|
||||||
`id_order_detail` = '.$orderItem['id_order_detail']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$orderDetail->update();
|
||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
}
|
}
|
||||||
@ -673,16 +626,6 @@ class RetailcrmHistory
|
|||||||
* Check new items
|
* Check new items
|
||||||
*/
|
*/
|
||||||
if (!empty($order['items'])) {
|
if (!empty($order['items'])) {
|
||||||
$query = 'INSERT `'._DB_PREFIX_.'order_detail`
|
|
||||||
(
|
|
||||||
`id_order`, `id_order_invoice`, `id_shop`, `product_id`, `product_attribute_id`,
|
|
||||||
`product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`,
|
|
||||||
`product_reference`, `total_price_tax_excl`, `total_price_tax_incl`,
|
|
||||||
`unit_price_tax_excl`, `unit_price_tax_incl`, `original_product_price`
|
|
||||||
)
|
|
||||||
|
|
||||||
VALUES';
|
|
||||||
|
|
||||||
foreach ($order['items'] as $key => $newItem) {
|
foreach ($order['items'] as $key => $newItem) {
|
||||||
$product_id = $newItem['offer']['externalId'];
|
$product_id = $newItem['offer']['externalId'];
|
||||||
$product_attribute_id = 0;
|
$product_attribute_id = 0;
|
||||||
@ -708,46 +651,49 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// discount
|
// discount
|
||||||
if ($newItem['discount'] || $newItem['discountPercent']|| $newItem['discountTotal']) {
|
if ((isset($newItem['discount']) && $newItem['discount'])
|
||||||
|
|| (isset($newItem['discountPercent']) && $newItem['discountPercent'])
|
||||||
|
|| (isset($newItem['discountTotal']) && $newItem['discountTotal'])
|
||||||
|
) {
|
||||||
$productPrice = $productPrice - $newItem['discount'];
|
$productPrice = $productPrice - $newItem['discount'];
|
||||||
$productPrice = $productPrice - $newItem['discountTotal'];
|
$productPrice = $productPrice - $newItem['discountTotal'];
|
||||||
$productPrice = $productPrice - ($prodPrice / 100 * $newItem['discountPercent']);
|
$productPrice = $productPrice - ($prodPrice / 100 * $newItem['discountPercent']);
|
||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query .= '('
|
$orderDetail = new OrderDetail();
|
||||||
.(int) $orderToUpdate->id.',
|
$orderDetail->id_order = $orderToUpdate->id;
|
||||||
0,
|
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
||||||
'. Context::getContext()->shop->id.',
|
$orderDetail->id_shop = Context::getContext()->shop->id;
|
||||||
'.(int) $product_id.',
|
$orderDetail->product_id = (int) $product_id;
|
||||||
'.(int) $product_attribute_id.',
|
$orderDetail->product_attribute_id = (int) $product_attribute_id;
|
||||||
'.implode('', array('\'', $productName, '\'')).',
|
$orderDetail->product_name = implode('', array('\'', $productName, '\''));
|
||||||
'.(int) $newItem['quantity'].',
|
$orderDetail->product_quantity = (int) $newItem['quantity'];
|
||||||
'.(int) $newItem['quantity'].',
|
$orderDetail->product_quantity_in_stock = (int) $newItem['quantity'];
|
||||||
'.$productPrice.',
|
$orderDetail->product_price = $productPrice;
|
||||||
'.implode('', array('\'', $product->reference, '\'')).',
|
$orderDetail->product_reference = implode('', array('\'', $product->reference, '\''));
|
||||||
'.$productPrice * $newItem['quantity'].',
|
$orderDetail->total_price_tax_excl = $productPrice * $newItem['quantity'];
|
||||||
'.($productPrice + $productPrice / 100 * $tax->rate) * $newItem['quantity'].',
|
$orderDetail->total_price_tax_incl = ($productPrice + $productPrice / 100 * $tax->rate) * $newItem['quantity'];
|
||||||
'.$productPrice.',
|
$orderDetail->unit_price_tax_excl = $productPrice;
|
||||||
'.($productPrice + $productPrice / 100 * $tax->rate).',
|
$orderDetail->unit_price_tax_incl = ($productPrice + $productPrice / 100 * $tax->rate);
|
||||||
'.$productPrice.'
|
$orderDetail->original_product_price = $productPrice;
|
||||||
),';
|
$orderDetail->save();
|
||||||
|
|
||||||
|
unset($orderDetail);
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::getInstance()->execute(rtrim($query, ','));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fix prices & discounts
|
* Fix prices & discounts
|
||||||
* Discounts only for whole order
|
* Discounts only for whole order
|
||||||
*/
|
*/
|
||||||
if (isset($order['discount']) ||
|
if (isset($order['discount'])
|
||||||
isset($order['discountPercent']) ||
|
|| isset($order['discountPercent'])
|
||||||
isset($order['delivery']['cost']) ||
|
|| isset($order['delivery']['cost'])
|
||||||
isset($order['discountTotal']) ||
|
|| isset($order['discountTotal'])
|
||||||
$ItemDiscount) {
|
|| $ItemDiscount
|
||||||
|
) {
|
||||||
$infoOrd = self::$api->ordersGet($order['externalId']);
|
$infoOrd = self::$api->ordersGet($order['externalId']);
|
||||||
$infoOrder = $infoOrd->order;
|
$infoOrder = $infoOrd->order;
|
||||||
$orderTotalProducts = $infoOrder['summ'];
|
$orderTotalProducts = $infoOrder['summ'];
|
||||||
@ -760,21 +706,18 @@ class RetailcrmHistory
|
|||||||
$order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']);
|
$order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']);
|
||||||
$order_cart_rule->delete();
|
$order_cart_rule->delete();
|
||||||
}
|
}
|
||||||
$orderToUpdate->update();
|
|
||||||
|
|
||||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'orders`
|
$orderToUpdate->total_discounts = $totalDiscount;
|
||||||
SET
|
$orderToUpdate->total_discounts_tax_incl = $totalDiscount;
|
||||||
`total_discounts` = '.$totalDiscount.',
|
$orderToUpdate->total_discounts_tax_excl = $totalDiscount;
|
||||||
`total_discounts_tax_incl` = '.$totalDiscount.',
|
$orderToUpdate->total_shipping = $deliveryCost;
|
||||||
`total_discounts_tax_excl` = '.$totalDiscount.',
|
$orderToUpdate->total_shipping_tax_incl = $deliveryCost;
|
||||||
`total_shipping` = '.$deliveryCost.',
|
$orderToUpdate->total_shipping_tax_excl = $deliveryCost;
|
||||||
`total_shipping_tax_incl` = '.$deliveryCost.',
|
$orderToUpdate->total_paid = $totalPaid;
|
||||||
`total_shipping_tax_excl` = '.$deliveryCost.',
|
$orderToUpdate->total_paid_tax_incl = $totalPaid;
|
||||||
`total_paid` = '.$totalPaid.',
|
$orderToUpdate->total_paid_tax_excl = $totalPaid;
|
||||||
`total_paid_tax_incl` = '.$totalPaid.',
|
$orderToUpdate->total_products_wt = $orderTotalProducts;
|
||||||
`total_paid_tax_excl` = '.$totalPaid.',
|
$orderToUpdate->update();
|
||||||
`total_products_wt` = '.$orderTotalProducts.'
|
|
||||||
WHERE `id_order` = '.(int) $order['externalId']);
|
|
||||||
|
|
||||||
unset($ItemDiscount);
|
unset($ItemDiscount);
|
||||||
}
|
}
|
||||||
@ -787,29 +730,48 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if ($statuses[$stype] != null) {
|
if ($statuses[$stype] != null) {
|
||||||
if ($statuses[$stype] != $orderToUpdate->current_state) {
|
if ($statuses[$stype] != $orderToUpdate->current_state) {
|
||||||
Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'order_history`
|
$orderHistory = new OrderHistory();
|
||||||
(`id_employee`, `id_order`, `id_order_state`, `date_add`)
|
$orderHistory->id_employee = 0;
|
||||||
VALUES
|
$orderHistory->id_order = $orderToUpdate->id;
|
||||||
(0, ' . $orderToUpdate->id . ',
|
$orderHistory->id_order_state = $statuses[$stype];
|
||||||
' . $statuses[$stype] . ',
|
$orderHistory->date_add = date('Y-m-d H:i:s');
|
||||||
"' . date('Y-m-d H:i:s') . '")');
|
$orderHistory->save();
|
||||||
|
|
||||||
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'orders`
|
$orderToUpdate->current_state = $statuses[$stype];
|
||||||
SET
|
$orderToUpdate->update();
|
||||||
`current_state` = \'' . $statuses[$stype] . '\'
|
|
||||||
WHERE
|
|
||||||
`id_order` = ' . (int)$order['externalId']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update last sync timestamp
|
* Update last sync timestamp
|
||||||
*/
|
*/
|
||||||
Configuration::updateValue('RETAILCRM_LAST_ORDERS_SYNC', $sinceId);
|
Configuration::updateValue('RETAILCRM_LAST_ORDERS_SYNC', $sinceId);
|
||||||
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 'Nothing to sync';
|
return 'Nothing to sync';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Delete order product from order by product
|
||||||
|
*
|
||||||
|
* @param $order_id
|
||||||
|
* @param $product_id
|
||||||
|
* @param $product_attribute_id
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function deleteOrderDetailByProduct($order_id, $product_id, $product_attribute_id)
|
||||||
|
{
|
||||||
|
Db::getInstance()->execute('
|
||||||
|
DELETE FROM ' . _DB_PREFIX_ . 'order_detail
|
||||||
|
WHERE id_order = ' . $order_id . '
|
||||||
|
AND product_id = ' . $product_id . '
|
||||||
|
AND product_attribute_id = ' . $product_attribute_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -33,10 +33,10 @@ class RetailcrmHistoryHelper {
|
|||||||
} else {
|
} else {
|
||||||
$orders[$change['order']['id']] = $change['order'];
|
$orders[$change['order']['id']] = $change['order'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($change['payment'])) {
|
if (isset($change['payment'])) {
|
||||||
if (isset($orders[$change['order']['id']]['payments'][$change['payment']['id']])) {
|
if (isset($orders[$change['order']['id']]['payments'][$change['payment']['id']])) {
|
||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = array_merge($orders[$change['order']['id']]['payments'][$change['payment']['id']], $change['payment']);
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = array_merge($orders[$change['order']['id']]['payments'][$change['payment']['id']], $change['payment']);
|
||||||
} else {
|
} else {
|
||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = $change['payment'];
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = $change['payment'];
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ class RetailcrmHistoryHelper {
|
|||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']][$fields['payment'][$change['field']]] = $change['newValue'];
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']][$fields['payment'][$change['field']]] = $change['newValue'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($change['item'])) {
|
if (isset($change['item'])) {
|
||||||
if (isset($orders[$change['order']['id']]['items'][$change['item']['id']])) {
|
if (isset($orders[$change['order']['id']]['items'][$change['item']['id']])) {
|
||||||
$orders[$change['order']['id']]['items'][$change['item']['id']] = array_merge($orders[$change['order']['id']]['items'][$change['item']['id']], $change['item']);
|
$orders[$change['order']['id']]['items'][$change['item']['id']] = array_merge($orders[$change['order']['id']]['items'][$change['item']['id']], $change['item']);
|
||||||
@ -64,7 +64,9 @@ class RetailcrmHistoryHelper {
|
|||||||
if (empty($change['newValue']) && $change['field'] == 'order_product') {
|
if (empty($change['newValue']) && $change['field'] == 'order_product') {
|
||||||
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = true;
|
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = true;
|
||||||
}
|
}
|
||||||
if (!$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] && $fields['item'][$change['field']]) {
|
if (!isset($orders[$change['order']['id']]['items'][$change['item']['id']]['create'])
|
||||||
|
&& isset($fields['item'][$change['field']]) && $fields['item'][$change['field']]
|
||||||
|
) {
|
||||||
$orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue'];
|
$orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user