mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-04-10 04:10:54 +00:00
Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
|
3cf7638fc2 | ||
|
c20b285b11 | ||
|
11248f5309 | ||
|
cc2f33eb7b | ||
|
37c4ca835e | ||
|
2192a84379 | ||
|
41509493e4 | ||
|
d0782028ee | ||
|
d6862bad58 |
17 changed files with 246 additions and 165 deletions
4
.github/workflows/presta.yml
vendored
4
.github/workflows/presta.yml
vendored
|
@ -26,10 +26,10 @@ jobs:
|
|||
# - php-version: '7.1' - Error install PrestaShop
|
||||
# branch: '1.7.8.10'
|
||||
- php-version: '7.2'
|
||||
branch: '1.7.8.10'
|
||||
branch: '1.7.8.11'
|
||||
coverage: 1
|
||||
- php-version: '7.3'
|
||||
branch: '1.7.8.10'
|
||||
branch: '1.7.8.11'
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
|
|
27
CHANGELOG.md
27
CHANGELOG.md
|
@ -1,3 +1,30 @@
|
|||
## v3.6.13
|
||||
* Внесены правки в тесты
|
||||
|
||||
## v3.6.12
|
||||
* Добавлена передача дополнительных параметров в GET запросах
|
||||
|
||||
## v3.6.11
|
||||
* Добавлены подсказки в настройках модуля
|
||||
|
||||
## v3.6.10
|
||||
* Изменена валидация ключа коллектора
|
||||
|
||||
## v3.6.9
|
||||
* Добавлена проверка корректности введеного ключа при подключении Daemon Collector
|
||||
|
||||
## v3.6.8
|
||||
* Исправлен перевод для поля "ИНН"
|
||||
|
||||
## v3.6.7
|
||||
* Добавлена передача полей "Компания" и "ИНН" из заказа CMS в пользовательские поля заказа CRM
|
||||
|
||||
## v3.6.6
|
||||
* Добавлена передача поля link при выгрузке брошенных корзин
|
||||
|
||||
## v3.6.5
|
||||
* Исправлено дублирование товаров при обратной синхронизации
|
||||
|
||||
## v3.6.4
|
||||
* Добавлена передача услуг через ICML каталог
|
||||
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
3.6.4
|
||||
3.6.13
|
||||
|
|
|
@ -263,6 +263,7 @@ class RetailcrmCartUploader
|
|||
'customer' => ['externalId' => $cart->id_customer],
|
||||
'clearAt' => null,
|
||||
'createdAt' => DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cart->date_add)->format(static::$crmCartDateFormat),
|
||||
'link' => self::generateCartLink(),
|
||||
];
|
||||
|
||||
if (!$isExistExternalId) {
|
||||
|
@ -447,4 +448,13 @@ class RetailcrmCartUploader
|
|||
{
|
||||
self::$context->employee = $employee;
|
||||
}
|
||||
|
||||
public static function generateCartLink()
|
||||
{
|
||||
return sprintf(
|
||||
'%s://%s/index.php?controller=cart&action=show',
|
||||
!empty($_SERVER['HTTPS']) ? 'https' : 'http',
|
||||
$_SERVER['HTTP_HOST']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,11 +393,11 @@ class RetailcrmHistory
|
|||
|
||||
self::saveCarrier($prestashopOrder->id, $deliveryType, $crmOrder['delivery']['cost']);
|
||||
|
||||
$quantities = self::createOrderDetails($crmOrder, $prestashopOrder);
|
||||
$isStockEnough = self::createOrderDetails($crmOrder, $prestashopOrder, true);
|
||||
|
||||
self::setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $quantities);
|
||||
self::setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $isStockEnough);
|
||||
|
||||
self::setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $quantities);
|
||||
self::setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $isStockEnough);
|
||||
|
||||
// collect order ids for single fix request
|
||||
self::$orderFix[] = ['id' => $crmOrder['id'], 'externalId' => $prestashopOrder->id];
|
||||
|
@ -438,13 +438,13 @@ class RetailcrmHistory
|
|||
|
||||
$crmOrder = self::cleanDeletedItems($crmOrder, $prestashopOrder);
|
||||
|
||||
$quantities = self::createOrderDetails($crmOrder, $prestashopOrder);
|
||||
$isStockEnoughForNewItems = self::createOrderDetails($crmOrder, $prestashopOrder);
|
||||
$isStockEnoughForExistingItems = self::checkItemsQuantityAndDiscount($crmOrder, $prestashopOrder);
|
||||
$isStockEnough = $isStockEnoughForNewItems && $isStockEnoughForExistingItems;
|
||||
|
||||
self::setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $quantities);
|
||||
|
||||
self::setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $quantities);
|
||||
|
||||
self::switchPrestashopOrderStatusByCrmStatus($crmOrder, $prestashopOrder, $quantities);
|
||||
self::setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $isStockEnough);
|
||||
self::setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $isStockEnough);
|
||||
self::switchPrestashopOrderStatusByCrmStatus($crmOrder, $prestashopOrder, $isStockEnough);
|
||||
|
||||
// update order number in PS if receiveOrderNumber option (CRM->PS) enabled
|
||||
if (isset($crmOrder['number']) && self::$receiveOrderNumber) {
|
||||
|
@ -1137,50 +1137,45 @@ class RetailcrmHistory
|
|||
}
|
||||
|
||||
/**
|
||||
* @return bool Returns if stock of all items is enough
|
||||
*
|
||||
* @throws PrestaShopDatabaseException
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
private static function createOrderDetails($crmOrder, $prestashopOrder)
|
||||
private static function createOrderDetails($crmOrder, $prestashopOrder, $isCreating = false)
|
||||
{
|
||||
$newItemsIds = [];
|
||||
$quantities = [];
|
||||
$isNewItemsExist = false;
|
||||
$isStockEnough = true;
|
||||
|
||||
if (empty($crmOrder['items'])) {
|
||||
RetailcrmLogger::writeDebug(__METHOD__, 'Empty order items');
|
||||
|
||||
return $quantities;
|
||||
return $isStockEnough;
|
||||
}
|
||||
|
||||
foreach ($crmOrder['items'] as $item) {
|
||||
if (!isset($item['offer']['externalId'])) {
|
||||
continue;
|
||||
}
|
||||
$externalId = $item['offer']['externalId'];
|
||||
|
||||
$product = new Product((int) $externalId, false, self::$default_lang);
|
||||
$product_id = $externalId;
|
||||
|
||||
foreach ($crmOrder['items'] as $key => $item) {
|
||||
if (RetailcrmOrderBuilder::isGiftItem($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_attribute_id = 0;
|
||||
if (false !== strpos($externalId, '#')) {
|
||||
$externalIds = explode('#', $externalId);
|
||||
$product_id = $externalIds[0];
|
||||
$product_attribute_id = $externalIds[1];
|
||||
$isNewItem = isset($item['create']);
|
||||
if (!$isNewItem && !$isCreating) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderDetail = self::createOrderDetail($item, $product, $product_attribute_id, $prestashopOrder);
|
||||
$availableInStockOld = StockAvailable::getQuantityAvailableByProduct($product_id);
|
||||
$parsedExtId = static::parseItemExternalId($item);
|
||||
$product_id = $parsedExtId['product_id'];
|
||||
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
||||
|
||||
$quantities[$product_id]['old'] = $availableInStockOld;
|
||||
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||
|
||||
if (isset($item['initialPrice'])) {
|
||||
$deltaQuantity = -1 * $orderDetail->product_quantity;
|
||||
} else {
|
||||
$deltaQuantity = -1 * ($item['quantity'] - $orderDetail->product_quantity);
|
||||
}
|
||||
$orderDetail = self::createOrderDetail($item, $product, $parsedExtId, $prestashopOrder);
|
||||
|
||||
$isStockEnough = $product->checkQty($orderDetail->product_quantity);
|
||||
|
||||
// переменная используется для передачи разницы количества товара в метод StockAvailable::updateQuantity
|
||||
$deltaQuantity = -1 * $orderDetail->product_quantity;
|
||||
|
||||
StockAvailable::updateQuantity(
|
||||
$product_id,
|
||||
|
@ -1189,37 +1184,32 @@ class RetailcrmHistory
|
|||
Context::getContext()->shop->id
|
||||
);
|
||||
|
||||
$availableInStockNew = StockAvailable::getQuantityAvailableByProduct($product_id);
|
||||
$quantities[$product_id]['new'] = $availableInStockNew;
|
||||
|
||||
if (!isset($item['initialPrice'])) {
|
||||
$orderDetail->product_quantity = $orderDetail->product_quantity - $deltaQuantity;
|
||||
$orderDetail->total_price_tax_incl = $orderDetail->product_price * $orderDetail->product_quantity;
|
||||
}
|
||||
|
||||
try {
|
||||
self::loadInPrestashop($orderDetail, 'save');
|
||||
$newItemsIds[Db::getInstance()->Insert_ID()] = $item['id'];
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
$isNewItemsExist = true;
|
||||
unset($crmOrder['items'][$key]);
|
||||
}
|
||||
|
||||
// update order items ids in crm
|
||||
self::$newItemsIdsByOrderId[$prestashopOrder->id] = $newItemsIds;
|
||||
if ($isNewItemsExist) {
|
||||
self::$newItemsIdsByOrderId[$prestashopOrder->id] = $newItemsIds;
|
||||
}
|
||||
|
||||
return $quantities;
|
||||
return $isStockEnough;
|
||||
}
|
||||
|
||||
private static function switchPrestashopOrderStatusByCrmStatus($crmOrder, $prestashopOrder, $quantities)
|
||||
private static function switchPrestashopOrderStatusByCrmStatus($crmOrder, $prestashopOrder, $isStockEnough)
|
||||
{
|
||||
if (!isset($crmOrder['status'])) {
|
||||
return;
|
||||
}
|
||||
$orderStatus = $crmOrder['status'];
|
||||
|
||||
$outOfStockItems = self::getOutOfStockItems($quantities);
|
||||
|
||||
if (0 < count($outOfStockItems)) {
|
||||
if (!$isStockEnough) {
|
||||
$orderStatus = self::getOutOfStockStatus($crmOrder, $prestashopOrder);
|
||||
}
|
||||
|
||||
|
@ -1245,10 +1235,10 @@ class RetailcrmHistory
|
|||
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
||||
$address = $addressBuilder
|
||||
->setIdCustomer($customer->id)
|
||||
->setDataCrm(isset($order['delivery']['address']) ? $order['delivery']['address'] : [])
|
||||
->setFirstName(isset($order['firstName']) ? $order['firstName'] : null)
|
||||
->setLastName(isset($order['lastName']) ? $order['lastName'] : null)
|
||||
->setPhone(isset($order['phone']) ? $order['phone'] : null)
|
||||
->setDataCrm($order['delivery']['address'] ?? [])
|
||||
->setFirstName($order['firstName'] ?? null)
|
||||
->setLastName($order['lastName'] ?? null)
|
||||
->setPhone($order['phone'] ?? null)
|
||||
->build()
|
||||
->getData()
|
||||
;
|
||||
|
@ -1414,19 +1404,19 @@ class RetailcrmHistory
|
|||
continue;
|
||||
}
|
||||
|
||||
$orderPayment = new OrderPayment();
|
||||
|
||||
$paymentType = self::getPaymentType($payment);
|
||||
|
||||
if ($paymentType) {
|
||||
$orderToUpdate->payment = $paymentType;
|
||||
$orderPayment->payment_method = $paymentType;
|
||||
if (!$paymentType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderToUpdate->payment = $paymentType;
|
||||
|
||||
$orderPayment = new OrderPayment();
|
||||
$orderPayment->payment_method = $paymentType;
|
||||
$orderPayment->order_reference = $orderToUpdate->reference;
|
||||
$orderPayment->id_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
|
||||
$orderPayment->amount = isset($payment['amount']) ? $payment['amount'] : $orderToUpdate->total_paid;
|
||||
$orderPayment->date_add = isset($payment['paidAt']) ? $payment['paidAt'] : date('Y-m-d H:i:s');
|
||||
$orderPayment->amount = $payment['amount'] ?? $orderToUpdate->total_paid;
|
||||
$orderPayment->date_add = $payment['paidAt'] ?? date('Y-m-d H:i:s');
|
||||
|
||||
RetailcrmLogger::writeDebug(
|
||||
__METHOD__,
|
||||
|
@ -1535,10 +1525,13 @@ class RetailcrmHistory
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (RetailcrmTools::validateEntity($addressInvoice, null, true)) {
|
||||
$addressInvoice->id_customer = $customer->id;
|
||||
RetailcrmTools::assignAddressIdsByFields($customer, $addressInvoice);
|
||||
|
||||
self::setCompanyAndVatNumberForInvoiceAddress($order, $addressInvoice);
|
||||
|
||||
if (empty($addressInvoice->id)) {
|
||||
self::loadInPrestashop($addressInvoice, 'save');
|
||||
|
||||
|
@ -1577,7 +1570,7 @@ class RetailcrmHistory
|
|||
return $crmOrder;
|
||||
}
|
||||
|
||||
foreach ($crmOrder['items'] as $item) {
|
||||
foreach ($crmOrder['items'] as $key => $item) {
|
||||
if (!isset($item['delete']) || true != $item['delete']) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1606,6 +1599,8 @@ class RetailcrmHistory
|
|||
$product_attribute_id,
|
||||
$id_order_detail
|
||||
);
|
||||
|
||||
unset($crmOrder['items'][$key]);
|
||||
}
|
||||
|
||||
return $crmOrder;
|
||||
|
@ -1613,9 +1608,16 @@ class RetailcrmHistory
|
|||
|
||||
private static function checkItemsQuantityAndDiscount($crmOrder, $prestashopOrder)
|
||||
{
|
||||
$itemQuantities = [];
|
||||
$isStockEnough = true;
|
||||
|
||||
if (empty($crmOrder['items'])) {
|
||||
RetailcrmLogger::writeDebug(__METHOD__, 'Empty order items');
|
||||
|
||||
return $isStockEnough;
|
||||
}
|
||||
|
||||
foreach ($prestashopOrder->getProductsDetail() as $orderItem) {
|
||||
foreach ($crmOrder['items'] as $crmItem) {
|
||||
foreach ($crmOrder['items'] as $key => $crmItem) {
|
||||
if (RetailcrmOrderBuilder::isGiftItem($crmItem)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1625,10 +1627,16 @@ class RetailcrmHistory
|
|||
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
||||
$isExistingItem = !isset($crmItem['create']);
|
||||
|
||||
if (!$isExistingItem || $product_id != $orderItem['product_id'] || $product_attribute_id != $orderItem['product_attribute_id']) {
|
||||
if (
|
||||
!$isExistingItem
|
||||
|| $product_id != $orderItem['product_id']
|
||||
|| $product_attribute_id != $orderItem['product_attribute_id']
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||
|
||||
$orderDetailId = !empty($parsedExtId['id_order_detail'])
|
||||
? $parsedExtId['id_order_detail'] : $orderItem['id_order_detail'];
|
||||
$orderDetail = new OrderDetail($orderDetailId);
|
||||
|
@ -1645,7 +1653,7 @@ class RetailcrmHistory
|
|||
$orderDetail->product_quantity = $crmItem['quantity'];
|
||||
$orderDetail->product_quantity_in_stock = $crmItem['quantity'];
|
||||
|
||||
$itemQuantities[$product_id] = StockAvailable::getQuantityAvailableByProduct($product_id);
|
||||
$isStockEnough = 0 > $deltaQuantity || $product->checkQty(-1 * $deltaQuantity);
|
||||
|
||||
StockAvailable::updateQuantity(
|
||||
$product_id,
|
||||
|
@ -1659,10 +1667,11 @@ class RetailcrmHistory
|
|||
? $prestashopOrder->id_warehouse : 0;
|
||||
|
||||
self::loadInPrestashop($orderDetail, 'update');
|
||||
unset($crmOrder['items'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $itemQuantities;
|
||||
return $isStockEnough;
|
||||
}
|
||||
|
||||
private static function getInternalOrderStatus($state)
|
||||
|
@ -1761,16 +1770,15 @@ class RetailcrmHistory
|
|||
return $orderToUpdate;
|
||||
}
|
||||
|
||||
private static function setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $quantities)
|
||||
private static function setOutOfStockStatusInPrestashop($crmOrder, $prestashopOrder, $isStockEnough)
|
||||
{
|
||||
if (!isset($crmOrder['items'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$outOfStockItems = self::getOutOfStockItems($quantities);
|
||||
$newStatus = self::getOutOfStockStatus($crmOrder, $prestashopOrder);
|
||||
|
||||
if (0 < count($outOfStockItems) && $newStatus) {
|
||||
if (!$isStockEnough && $newStatus) {
|
||||
self::createOrderHistory($prestashopOrder, $newStatus);
|
||||
$prestashopOrder->current_state = self::$statuses[$newStatus];
|
||||
self::loadInPrestashop($prestashopOrder, 'save');
|
||||
|
@ -1865,19 +1873,13 @@ class RetailcrmHistory
|
|||
return $cart;
|
||||
}
|
||||
|
||||
private static function setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $quantities = null)
|
||||
private static function setOutOfStockStatusInCrm($crmOrder, $prestashopOrder, $isStockEnough)
|
||||
{
|
||||
if (!isset($crmOrder['items']) || !is_array($crmOrder['items'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === $quantities) {
|
||||
$quantities = self::checkItemsQuantityAndDiscount($crmOrder, $prestashopOrder);
|
||||
}
|
||||
|
||||
$outOfStockItems = self::getOutOfStockItems($quantities);
|
||||
|
||||
if (0 < count($outOfStockItems)) {
|
||||
if (!$isStockEnough) {
|
||||
$crmOrder['status'] = self::getOutOfStockStatus($crmOrder, $prestashopOrder);
|
||||
|
||||
self::$api->ordersEdit($crmOrder, 'id');
|
||||
|
@ -1912,20 +1914,10 @@ class RetailcrmHistory
|
|||
$orderHistory->changeIdOrderState(self::$statuses[$orderStatus], $prestashopOrder->id, true);
|
||||
}
|
||||
|
||||
private static function getOutOfStockItems($quantities)
|
||||
private static function createOrderDetail($item, $product, $parsedExtId, $prestashopOrder)
|
||||
{
|
||||
return array_filter($quantities, function ($value) {
|
||||
if (0 > $value['new'] || $value['new'] == $value['old']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private static function createOrderDetail($item, $product, $product_attribute_id, $prestashopOrder)
|
||||
{
|
||||
$product_id = $item['offer']['externalId'];
|
||||
$product_id = $parsedExtId['product_id'];
|
||||
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
||||
|
||||
if (0 != $product_attribute_id) {
|
||||
$productName = htmlspecialchars(
|
||||
|
@ -1935,16 +1927,11 @@ class RetailcrmHistory
|
|||
$productName = htmlspecialchars(strip_tags($product->name));
|
||||
}
|
||||
|
||||
if (isset($item['initialPrice'])) {
|
||||
$productPrice = round($item['initialPrice'], 2);
|
||||
$orderDetail = new OrderDetail();
|
||||
$orderDetail->product_quantity = (int) $item['quantity'];
|
||||
$orderDetail->product_quantity_in_stock = (int) $item['quantity'];
|
||||
} else {
|
||||
$parsedExtId = static::parseItemExternalId($item);
|
||||
$orderDetail = new OrderDetail($parsedExtId['id_order_detail']);
|
||||
$productPrice = $orderDetail->product_price;
|
||||
}
|
||||
$parsedExtId = static::parseItemExternalId($item);
|
||||
$orderDetail = new OrderDetail($parsedExtId['id_order_detail'] ?? null);
|
||||
|
||||
$orderDetail->product_quantity = (int) $item['quantity'];
|
||||
$orderDetail->product_quantity_in_stock = (int) $item['quantity'];
|
||||
|
||||
static::setOrderDetailProductName($orderDetail, $productName);
|
||||
|
||||
|
@ -1956,17 +1943,38 @@ class RetailcrmHistory
|
|||
$orderDetail->product_attribute_id = (int) $product_attribute_id;
|
||||
$orderDetail->product_reference = implode('', ['\'', $product->reference, '\'']);
|
||||
|
||||
$productPrice = $item['initialPrice'];
|
||||
|
||||
$orderDetail->product_price = $productPrice;
|
||||
$orderDetail->original_product_price = $productPrice;
|
||||
|
||||
$orderDetail->total_price_tax_incl = $productPrice * $orderDetail->product_quantity;
|
||||
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||
|
||||
$orderDetail->id_warehouse = !empty($prestashopOrder->id_warehouse) ? $prestashopOrder->id_warehouse : 0;
|
||||
$orderDetail->id_warehouse = $prestashopOrder->id_warehouse ?? 0;
|
||||
$orderDetail->id_order_detail = $parsedExtId['id_order_detail'] ?? null;
|
||||
|
||||
return $orderDetail;
|
||||
}
|
||||
|
||||
private static function setCompanyAndVatNumberForInvoiceAddress($crmOrder, $addressInvoice)
|
||||
{
|
||||
if (!RetailcrmTools::isCorporateEnabled()
|
||||
&& RetailcrmTools::isCampanyAndVatNumberSendEnabled()
|
||||
) {
|
||||
$company = $crmOrder['customFields']['ps_company'] ?? '';
|
||||
$vatNumber = $crmOrder['customFields']['ps_vat_number'] ?? '';
|
||||
|
||||
if ('' !== $company) {
|
||||
$addressInvoice->company = $company;
|
||||
}
|
||||
|
||||
if ('' !== $vatNumber) {
|
||||
$addressInvoice->vat_number = $vatNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleError($order, $e)
|
||||
{
|
||||
RetailcrmLogger::writeCaller(
|
||||
|
|
|
@ -979,15 +979,25 @@ class RetailcrmOrderBuilder
|
|||
;
|
||||
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());
|
||||
|
||||
if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
|
||||
$crmOrder['contragent']['legalName'] = $addressInvoice->company;
|
||||
$isCorporateEnabled = RetailcrmTools::isCorporateEnabled();
|
||||
|
||||
if (!empty($addressInvoice->vat_number)) {
|
||||
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number;
|
||||
if ($isCorporateEnabled && RetailcrmTools::isOrderCorporate($order)) {
|
||||
$crmOrder['contragent']['contragentType'] = 'legal-entity';
|
||||
$crmOrder['contragent']['legalName'] = $addressInvoice->company ?? '';
|
||||
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number ?? '';
|
||||
} else {
|
||||
$crmOrder['contragent']['contragentType'] = 'individual';
|
||||
|
||||
if (
|
||||
RetailcrmTools::isCampanyAndVatNumberSendEnabled()
|
||||
&& Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||
) {
|
||||
$crmOrder['customFields']['ps_company'] = $addressInvoice->company ?? '';
|
||||
$crmOrder['customFields']['ps_vat_number'] = $addressInvoice->vat_number ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
||||
if (!empty($payment[$paymentType])) {
|
||||
$order_payment = [
|
||||
'externalId' => $order->id . '#' . $order->reference,
|
||||
'type' => $payment[$paymentType],
|
||||
|
@ -1124,9 +1134,6 @@ class RetailcrmOrderBuilder
|
|||
'productName' => $product['product_name'],
|
||||
'quantity' => $product['product_quantity'],
|
||||
'initialPrice' => round($product['product_price'], 2),
|
||||
/*'initialPrice' => !empty($item['rate'])
|
||||
? $item['price'] + ($item['price'] * $item['rate'] / 100)
|
||||
: $item['price'],*/
|
||||
'purchasePrice' => round($product['purchase_supplier_price'], 2),
|
||||
];
|
||||
|
||||
|
@ -1161,12 +1168,6 @@ class RetailcrmOrderBuilder
|
|||
if (!empty($site)) {
|
||||
$crmOrder['customer']['site'] = $site;
|
||||
}
|
||||
|
||||
if (RetailcrmTools::isCorporateEnabled() && RetailcrmTools::isOrderCorporate($order)) {
|
||||
$crmOrder['contragent']['contragentType'] = 'legal-entity';
|
||||
} else {
|
||||
$crmOrder['contragent']['contragentType'] = 'individual';
|
||||
}
|
||||
}
|
||||
|
||||
return RetailcrmTools::filter(
|
||||
|
|
|
@ -58,6 +58,28 @@ class RetailcrmTools
|
|||
return self::$default_lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ISO code of current employee language or default language.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCurrentLanguageISO()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!empty($context) && !empty($context->employee)) {
|
||||
$langId = (int) $context->employee->id_lang;
|
||||
} elseif ($cookie instanceof Cookie) {
|
||||
$langId = (int) $cookie->id_lang;
|
||||
} else {
|
||||
$langId = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
return (string) Language::getIsoById($langId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if corporate customers are enabled in settings
|
||||
*
|
||||
|
@ -78,6 +100,16 @@ class RetailcrmTools
|
|||
return (bool) Configuration::get(RetailCRM::ENABLE_ICML_SERVICES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the transfer of company and VAT number is enabled in the settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCampanyAndVatNumberSendEnabled()
|
||||
{
|
||||
return (bool) Configuration::get(RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if customer is corporate
|
||||
*
|
||||
|
@ -969,22 +1001,6 @@ class RetailcrmTools
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return DateTime|false
|
||||
*/
|
||||
public static function getConfigurationCreatedAtByName($name)
|
||||
{
|
||||
$config = self::getConfigurationByName($name);
|
||||
|
||||
if (empty($config)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $config['date_add']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -362,7 +362,7 @@ class RetailcrmApiClientV5
|
|||
);
|
||||
}
|
||||
|
||||
if (empty($entity) || 'customer' != $entity || 'order' != $entity) {
|
||||
if (empty($entity)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `entity` must contain a data & value must be `order` or `customer`'
|
||||
);
|
||||
|
|
|
@ -106,7 +106,14 @@ class RetailcrmHttpClient
|
|||
);
|
||||
}
|
||||
|
||||
$parameters = array_merge($this->defaultParameters, $parameters);
|
||||
$parameters = self::METHOD_GET === $method
|
||||
? array_merge($this->defaultParameters, $parameters, [
|
||||
'cms_source' => 'PrestaShop',
|
||||
'cms_version' => _PS_VERSION_,
|
||||
'php_version' => function_exists('phpversion') ? phpversion() : '',
|
||||
'module_version' => RetailCRM::VERSION,
|
||||
])
|
||||
: $parameters = array_merge($this->defaultParameters, $parameters);
|
||||
|
||||
$url = $this->url . $path;
|
||||
|
||||
|
|
|
@ -87,6 +87,13 @@ class RetailcrmSettings
|
|||
$changed['consultantScript'] = $this->consultantScript->getValueStored();
|
||||
}
|
||||
|
||||
if (
|
||||
!empty($changed['enableCompanyAndVatNumberSend'])
|
||||
&& !Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||
) {
|
||||
$this->createCompanyAndVatNumberFields();
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $this->validator->getSuccess(),
|
||||
'errors' => $this->validator->getErrors(),
|
||||
|
@ -127,4 +134,30 @@ class RetailcrmSettings
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createCompanyAndVatNumberFields()
|
||||
{
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
$locale = RetailcrmTools::getCurrentLanguageISO();
|
||||
$translate = [
|
||||
'ru' => ['company' => 'Компания', 'vat_number' => 'ИНН'],
|
||||
'en' => ['company' => 'Company', 'vat_number' => 'VAT number'],
|
||||
];
|
||||
|
||||
$company = $translate[$locale]['company'] ?? 'Empresa';
|
||||
$vatNumber = $translate[$locale]['vat_number'] ?? 'Número de IVA';
|
||||
|
||||
$customFields = [
|
||||
['code' => 'ps_company', 'name' => $company, 'type' => 'string', 'displayArea' => 'customer'],
|
||||
['code' => 'ps_vat_number', 'name' => $vatNumber, 'type' => 'string', 'displayArea' => 'customer'],
|
||||
];
|
||||
|
||||
if (null !== $api) {
|
||||
foreach ($customFields as $field) {
|
||||
$api->customFieldsCreate('order', $field);
|
||||
}
|
||||
|
||||
Configuration::updateValue(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ class RetailcrmSettingsItems
|
|||
'enableCorporate' => new RetailcrmSettingsItemBool('enableCorporate', RetailCRM::ENABLE_CORPORATE_CLIENTS),
|
||||
'enableOrderNumberSending' => new RetailcrmSettingsItemBool('enableOrderNumberSending', RetailCRM::ENABLE_ORDER_NUMBER_SENDING),
|
||||
'enableOrderNumberReceiving' => new RetailcrmSettingsItemBool('enableOrderNumberReceiving', RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING),
|
||||
'enableCompanyAndVatNumberSend' => new RetailcrmSettingsItemBool('enableCompanyAndVatNumberSend', RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND),
|
||||
'webJobs' => new RetailcrmSettingsItemBool('webJobs', RetailCRM::ENABLE_WEB_JOBS, '1'),
|
||||
'debugMode' => new RetailcrmSettingsItemBool('debugMode', RetailCRM::ENABLE_DEBUG_MODE),
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ class RetailcrmSettingsValidator
|
|||
|
||||
private function validateCollector($collectorActive, $collectorKey)
|
||||
{
|
||||
return !$collectorActive || '' !== $collectorKey;
|
||||
return !$collectorActive || preg_match('/^RC-[0-9]{11}-[0-9]{1,2}$/', $collectorKey);
|
||||
}
|
||||
|
||||
private function addError($field, $message)
|
||||
|
|
|
@ -65,28 +65,6 @@ abstract class RetailcrmAbstractTemplate
|
|||
$this->assets = $assets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ISO code of current employee language or default language.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCurrentLanguageISO()
|
||||
{
|
||||
$langId = 0;
|
||||
|
||||
global $cookie;
|
||||
|
||||
if (!empty($this->context) && !empty($this->context->employee)) {
|
||||
$langId = (int) $this->context->employee->id_lang;
|
||||
} elseif ($cookie instanceof Cookie) {
|
||||
$langId = (int) $cookie->id_lang;
|
||||
} else {
|
||||
$langId = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
return (string) Language::getIsoById($langId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
*
|
||||
|
|
|
@ -47,7 +47,7 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||
'chunk-vendors' => filemtime(_PS_MODULE_DIR_ . '/retailcrm/views/js/chunk-vendors.js'),
|
||||
],
|
||||
'appData' => [
|
||||
'locale' => $this->getCurrentLanguageISO(),
|
||||
'locale' => RetailcrmTools::getCurrentLanguageISO(),
|
||||
'debug' => RetailcrmTools::isDebug(),
|
||||
'routes' => [
|
||||
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
|
||||
|
|
|
@ -48,8 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
|
|||
|
||||
class RetailCRM extends Module
|
||||
{
|
||||
const VERSION = '3.6.4';
|
||||
|
||||
const VERSION = '3.6.13';
|
||||
const API_URL = 'RETAILCRM_ADDRESS';
|
||||
const API_KEY = 'RETAILCRM_API_TOKEN';
|
||||
const DELIVERY = 'RETAILCRM_API_DELIVERY';
|
||||
|
@ -72,12 +71,12 @@ class RetailCRM extends Module
|
|||
const ENABLE_BALANCES_RECEIVING = 'RETAILCRM_ENABLE_BALANCES_RECEIVING';
|
||||
const ENABLE_ORDER_NUMBER_SENDING = 'RETAILCRM_ENABLE_ORDER_NUMBER_SENDING';
|
||||
const ENABLE_ORDER_NUMBER_RECEIVING = 'RETAILCRM_ENABLE_ORDER_NUMBER_RECEIVING';
|
||||
const ENABLE_COMPANY_AND_VAT_NUMBER_SEND = 'RETAILCRM_ENABLE_COMPANY_AND_VAT_NUMBER_SEND';
|
||||
const COMPANY_AND_VAT_NUMBER_CREATED = 'RETAILCRM_COMPANY_AND_VAT_NUMBER_CREATED';
|
||||
const ENABLE_DEBUG_MODE = 'RETAILCRM_ENABLE_DEBUG_MODE';
|
||||
|
||||
const CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
|
||||
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
|
||||
const ENABLE_WEB_JOBS = 'RETAILCRM_ENABLE_WEB_JOBS';
|
||||
|
||||
const REQUIRED_CRM_SITE_ACCESS = 'access_selective';
|
||||
const REQUIRED_CRM_SITE_COUNT = 1;
|
||||
const REQUIRED_CRM_SCOPES = [
|
||||
|
@ -343,6 +342,7 @@ class RetailCRM extends Module
|
|||
&& Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING)
|
||||
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING)
|
||||
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING)
|
||||
&& Configuration::deleteByName(static::ENABLE_COMPANY_AND_VAT_NUMBER_SEND)
|
||||
&& Configuration::deleteByName(static::ENABLE_DEBUG_MODE)
|
||||
&& Configuration::deleteByName(static::ENABLE_WEB_JOBS)
|
||||
&& Configuration::deleteByName('RETAILCRM_LAST_SYNC')
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 100 KiB |
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue