mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 19:53:19 +03:00
Merge pull request #50 from Evgeniy-Goroh/master
Поддержка передачи одинаковых товаров в заказе как разных товарных по…
This commit is contained in:
commit
1d3a2e34d9
@ -1,3 +1,6 @@
|
|||||||
|
## v2.3.4
|
||||||
|
* Добавлена поддержка передачи одинаковых товаров в заказе как разных товарных позиций
|
||||||
|
|
||||||
## v2.3.2
|
## v2.3.2
|
||||||
* Добавлен учет настройки включения НДС в стоимость товара
|
* Добавлен учет настройки включения НДС в стоимость товара
|
||||||
|
|
||||||
|
149
retailcrm/lib/RetailcrmHistory.php
Normal file → Executable file
149
retailcrm/lib/RetailcrmHistory.php
Normal file → Executable file
@ -612,6 +612,7 @@ class RetailcrmHistory
|
|||||||
/*
|
/*
|
||||||
* Clean deleted items
|
* Clean deleted items
|
||||||
*/
|
*/
|
||||||
|
$id_order_detail = null;
|
||||||
foreach ($order['items'] as $key => $item) {
|
foreach ($order['items'] as $key => $item) {
|
||||||
if (isset($item['delete']) && $item['delete'] == true) {
|
if (isset($item['delete']) && $item['delete'] == true) {
|
||||||
if (strpos($item['offer']['externalId'], '#') !== false) {
|
if (strpos($item['offer']['externalId'], '#') !== false) {
|
||||||
@ -623,7 +624,21 @@ class RetailcrmHistory
|
|||||||
$product_attribute_id = 0;
|
$product_attribute_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::deleteOrderDetailByProduct($orderToUpdate->id, $product_id, $product_attribute_id);
|
if (isset($item['externalIds'])) {
|
||||||
|
foreach ($item['externalIds'] as $externalId) {
|
||||||
|
if ($externalId['code'] == 'prestashop') {
|
||||||
|
$id_order_detail = explode('_', $externalId['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
$id_order_detail = explode('#', $item['offer']['externalId']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($id_order_detail[1])){
|
||||||
|
$id_order_detail = $id_order_detail[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::deleteOrderDetailByProduct($orderToUpdate->id, $product_id, $product_attribute_id, $id_order_detail);
|
||||||
|
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
@ -656,7 +671,7 @@ class RetailcrmHistory
|
|||||||
$prodPrice = $prodPrice + $prodPrice / 100 * $tax->rate;
|
$prodPrice = $prodPrice + $prodPrice / 100 * $tax->rate;
|
||||||
// discount
|
// discount
|
||||||
if (self::$apiVersion == 5) {
|
if (self::$apiVersion == 5) {
|
||||||
$productPrice = $prodPrice - $item['discountTotal'];
|
$productPrice = $prodPrice - (isset($item['discountTotal']) ? $item['discountTotal'] : 0);
|
||||||
} else {
|
} else {
|
||||||
$productPrice = $prodPrice - $item['discount'];
|
$productPrice = $prodPrice - $item['discount'];
|
||||||
if ($item['discountPercent'] > 0) {
|
if ($item['discountPercent'] > 0) {
|
||||||
@ -664,13 +679,83 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$productPrice = round($productPrice, 2);
|
$productPrice = round($productPrice, 2);
|
||||||
$orderDetail = new OrderDetail($orderItem['id_order_detail']);
|
|
||||||
|
if (isset($item['externalIds'])) {
|
||||||
|
foreach ($item['externalIds'] as $externalId) {
|
||||||
|
if ($externalId['code'] == 'prestashop') {
|
||||||
|
$id_order_detail = explode('_', $externalId['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$id_order_detail = explode('#', $item['offer']['externalId']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderDetail = new OrderDetail($id_order_detail[1]);
|
||||||
$orderDetail->unit_price_tax_incl = $productPrice;
|
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||||
|
$orderDetail->id_warehouse = 0;
|
||||||
|
|
||||||
// quantity
|
// quantity
|
||||||
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
||||||
$orderDetail->product_quantity = $item['quantity'];
|
$orderDetail->product_quantity = $item['quantity'];
|
||||||
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
||||||
|
$orderDetail->id_order_detail = $id_order_detail[1];
|
||||||
|
$orderDetail->id_warehouse = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($orderDetail->id_order) && !isset($orderDetail->id_shop)) {
|
||||||
|
$orderDetail->id_order = $orderToUpdate->id;
|
||||||
|
$orderDetail->id_shop = Context::getContext()->shop->id;
|
||||||
|
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||||
|
|
||||||
|
$productName = htmlspecialchars(strip_tags($item['offer']['displayName']));
|
||||||
|
|
||||||
|
$orderDetail->product_name = implode('', array('\'', $productName, '\''));
|
||||||
|
$orderDetail->product_price = $item['initialPrice'] ? $item['initialPrice'] : $product->price;
|
||||||
|
|
||||||
|
if (strpos($item['offer']['externalId'], '#') !== false) {
|
||||||
|
$product_id = explode('#', $item['offer']['externalId']);
|
||||||
|
$product_attribute_id = $product_id[1];
|
||||||
|
$product_id = $product_id[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderDetail->product_id = (int) $product_id;
|
||||||
|
$orderDetail->product_attribute_id = (int) $product_attribute_id;
|
||||||
|
$orderDetail->product_quantity = (int) $item['quantity'];
|
||||||
|
|
||||||
|
if ($orderDetail->save()) {
|
||||||
|
$upOrderItems = array(
|
||||||
|
'externalId' => $orderDetail->id_order,
|
||||||
|
);
|
||||||
|
|
||||||
|
$orderdb = new Order($orderDetail->id_order);
|
||||||
|
|
||||||
|
foreach ($orderdb->getProducts() as $item) {
|
||||||
|
if (isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) {
|
||||||
|
$productId = $item['product_id'] . '#' . $item['product_attribute_id'];
|
||||||
|
} else {
|
||||||
|
$productId = $item['product_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$upOrderItems['items'][] = array(
|
||||||
|
"id" => $key,
|
||||||
|
"externalIds" => array(
|
||||||
|
array(
|
||||||
|
'code' =>'prestashop',
|
||||||
|
'value' => $productId."_".$item['id_order_detail'],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'initialPrice' => $item['unit_price_tax_incl'],
|
||||||
|
'quantity' => $item['product_quantity'],
|
||||||
|
'offer' => array('externalId' => $productId),
|
||||||
|
'productName' => $item['product_name'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($orderdb);
|
||||||
|
self::$api->ordersEdit($upOrderItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$orderDetail->update();
|
$orderDetail->update();
|
||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
@ -714,7 +799,17 @@ class RetailcrmHistory
|
|||||||
$ItemDiscount = true;
|
$ItemDiscount = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orderDetail = new OrderDetail();
|
if(isset($newItem['externalIds'])) {
|
||||||
|
foreach ($newItem['externalIds'] as $externalId) {
|
||||||
|
if ($externalId['code'] == 'prestashop') {
|
||||||
|
$id_order_detail = explode('_', $externalId['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$id_order_detail = explode('#', $item['offer']['externalId']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderDetail = new OrderDetail($id_order_detail[1]);
|
||||||
$orderDetail->id_order = $orderToUpdate->id;
|
$orderDetail->id_order = $orderToUpdate->id;
|
||||||
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
||||||
$orderDetail->id_shop = Context::getContext()->shop->id;
|
$orderDetail->id_shop = Context::getContext()->shop->id;
|
||||||
@ -731,7 +826,39 @@ class RetailcrmHistory
|
|||||||
$orderDetail->unit_price_tax_incl = ($productPrice + $productPrice / 100 * $tax->rate);
|
$orderDetail->unit_price_tax_incl = ($productPrice + $productPrice / 100 * $tax->rate);
|
||||||
$orderDetail->original_product_price = $productPrice;
|
$orderDetail->original_product_price = $productPrice;
|
||||||
$orderDetail->id_warehouse = !empty($orderToUpdate->id_warehouse) ? $orderToUpdate->id_warehouse : 0;
|
$orderDetail->id_warehouse = !empty($orderToUpdate->id_warehouse) ? $orderToUpdate->id_warehouse : 0;
|
||||||
$orderDetail->save();
|
$orderDetail->id_order_detail = $id_order_detail[1];
|
||||||
|
|
||||||
|
if ($orderDetail->save()) {
|
||||||
|
$upOrderItems = array(
|
||||||
|
'externalId' => $orderDetail->id_order,
|
||||||
|
);
|
||||||
|
|
||||||
|
$orderdb = new Order($orderDetail->id_order);
|
||||||
|
foreach ($orderdb->getProducts() as $item) {
|
||||||
|
if (isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) {
|
||||||
|
$productId = $item['product_id'] . '#' . $item['product_attribute_id'];
|
||||||
|
} else {
|
||||||
|
$productId = $item['product_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$upOrderItems['items'][] = array(
|
||||||
|
"externalIds" => array(
|
||||||
|
array(
|
||||||
|
'code' =>'prestashop',
|
||||||
|
'value' => $productId."_".$item['id_order_detail'],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'initialPrice' => $item['unit_price_tax_incl'],
|
||||||
|
'quantity' => $item['product_quantity'],
|
||||||
|
'offer' => array('externalId' => $productId),
|
||||||
|
'productName' => $item['product_name'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($orderdb);
|
||||||
|
self::$api->ordersEdit($upOrderItems);
|
||||||
|
}
|
||||||
|
|
||||||
unset($orderDetail);
|
unset($orderDetail);
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
}
|
}
|
||||||
@ -787,13 +914,21 @@ class RetailcrmHistory
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function deleteOrderDetailByProduct($order_id, $product_id, $product_attribute_id)
|
private static function deleteOrderDetailByProduct($order_id, $product_id, $product_attribute_id, $id_order_detail)
|
||||||
{
|
{
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
DELETE FROM ' . _DB_PREFIX_ . 'order_detail
|
DELETE FROM ' . _DB_PREFIX_ . 'order_detail
|
||||||
WHERE id_order = ' . $order_id . '
|
WHERE id_order = ' . $order_id . '
|
||||||
AND product_id = ' . $product_id . '
|
AND product_id = ' . $product_id . '
|
||||||
AND product_attribute_id = ' . $product_attribute_id
|
AND product_attribute_id = ' . $product_attribute_id . '
|
||||||
|
AND id_order_detail = ' . $id_order_detail
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getNewOrderDetailId()
|
||||||
|
{
|
||||||
|
return Db::getInstance()->getRow('
|
||||||
|
SELECT MAX(id_order_detail) FROM ' . _DB_PREFIX_ . 'order_detail'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,6 @@ class RetailcrmHistoryHelper {
|
|||||||
if (isset($change['order']['items']) && $change['order']['items']) {
|
if (isset($change['order']['items']) && $change['order']['items']) {
|
||||||
$items = array();
|
$items = array();
|
||||||
foreach($change['order']['items'] as $item) {
|
foreach($change['order']['items'] as $item) {
|
||||||
if (isset($change['created'])) {
|
|
||||||
$item['create'] = 1;
|
|
||||||
}
|
|
||||||
$items[$item['id']] = $item;
|
$items[$item['id']] = $item;
|
||||||
}
|
}
|
||||||
$change['order']['items'] = $items;
|
$change['order']['items'] = $items;
|
||||||
|
14
retailcrm/retailcrm.php
Normal file → Executable file
14
retailcrm/retailcrm.php
Normal file → Executable file
@ -38,7 +38,7 @@ class RetailCRM extends Module
|
|||||||
{
|
{
|
||||||
$this->name = 'retailcrm';
|
$this->name = 'retailcrm';
|
||||||
$this->tab = 'export';
|
$this->tab = 'export';
|
||||||
$this->version = '2.3.1';
|
$this->version = '2.3.4';
|
||||||
$this->author = 'Retail Driver LCC';
|
$this->author = 'Retail Driver LCC';
|
||||||
$this->displayName = $this->l('RetailCRM');
|
$this->displayName = $this->l('RetailCRM');
|
||||||
$this->description = $this->l('Integration module for RetailCRM');
|
$this->description = $this->l('Integration module for RetailCRM');
|
||||||
@ -431,6 +431,12 @@ class RetailCRM extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$item = array(
|
$item = array(
|
||||||
|
"externalIds" => array(
|
||||||
|
array(
|
||||||
|
'code' =>'prestashop',
|
||||||
|
'value' => $productId."_".$product['id_order_detail'],
|
||||||
|
),
|
||||||
|
),
|
||||||
'offer' => array('externalId' => $productId),
|
'offer' => array('externalId' => $productId),
|
||||||
'productName' => $product['product_name'],
|
'productName' => $product['product_name'],
|
||||||
'quantity' => $product['product_quantity'],
|
'quantity' => $product['product_quantity'],
|
||||||
@ -925,6 +931,12 @@ class RetailCRM extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$order['items'][] = array(
|
$order['items'][] = array(
|
||||||
|
"externalIds" => array(
|
||||||
|
array(
|
||||||
|
'code' =>'prestashop',
|
||||||
|
'value' => $productId."_".$item['id_order_detail'],
|
||||||
|
)
|
||||||
|
),
|
||||||
'initialPrice' => $item['unit_price_tax_incl'],
|
'initialPrice' => $item['unit_price_tax_incl'],
|
||||||
'quantity' => $item['product_quantity'],
|
'quantity' => $item['product_quantity'],
|
||||||
'offer' => array('externalId' => $productId),
|
'offer' => array('externalId' => $productId),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user