mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-04-17 15:30:54 +00:00
добавлен учет tax_rate для формирования стоимости товара в заказе и icml, добавлена возможность выгружать в CRM пользователя по факту его регистрации в CRM, изменена структура передаваемых в CRM данных по заказу
This commit is contained in:
parent
b891ed607f
commit
a25409571c
4 changed files with 82 additions and 18 deletions
|
@ -11,7 +11,7 @@ if (file_exists(dirname(__FILE__) . '/../lib/custom/Catalog.php')) {
|
|||
}
|
||||
|
||||
$job = new Catalog();
|
||||
$data = $job->exportCatalog();
|
||||
$data = $job->getData();
|
||||
|
||||
$icml = new Icml(
|
||||
Configuration::get('PS_SHOP_NAME'),
|
||||
|
|
|
@ -9,7 +9,7 @@ class Catalog
|
|||
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
}
|
||||
|
||||
public function exportCatalog()
|
||||
public function getData()
|
||||
{
|
||||
|
||||
$id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||
|
@ -39,6 +39,7 @@ class Catalog
|
|||
|
||||
// Get products
|
||||
$products = Product::getProducts($id_lang, 0, 0, 'name', 'asc');
|
||||
|
||||
foreach ($products AS $product)
|
||||
{
|
||||
// Check for home category
|
||||
|
@ -77,19 +78,57 @@ class Catalog
|
|||
$available_for_order = $product['active'] && $product['available_for_order'] && $prod->checkQty(1);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
$item = array(
|
||||
'id' => $product['id_product'],
|
||||
'productId' => $product['id_product'],
|
||||
'productActivity' => ($available_for_order) ? 'Y' : 'N',
|
||||
'initialPrice' => round($product['price'],2),
|
||||
'purchasePrice' => round($product['wholesale_price'], 2),
|
||||
'name' => htmlspecialchars(strip_tags($product['name'])),
|
||||
'productName' => htmlspecialchars(strip_tags($product['name'])),
|
||||
'categoryId' => array($category),
|
||||
'picture' => $picture,
|
||||
'url' => $url,
|
||||
'article' => htmlspecialchars($product['reference'])
|
||||
'url' => $url
|
||||
);
|
||||
|
||||
if (!empty($product['wholesale_price'])) {
|
||||
$item['purchasePrice'] = round($product['wholesale_price'], 2);
|
||||
}
|
||||
|
||||
$item['initialPrice'] = !empty($product['rate'])
|
||||
? round($product['price'], 2) + (round($product['price'], 2) * $product['rate'] / 100)
|
||||
: round($product['price'], 2)
|
||||
;
|
||||
|
||||
|
||||
if (!empty($product['manufacturer_name'])) {
|
||||
$item['vendor'] = $product['manufacturer_name'];
|
||||
}
|
||||
|
||||
if (!empty($product['reference'])) {
|
||||
$item['article'] = htmlspecialchars($product['reference']);
|
||||
}
|
||||
|
||||
$weight = round($product['weight'], 2);
|
||||
|
||||
if (!empty($weight)) {
|
||||
$item['weight'] = $weight;
|
||||
}
|
||||
|
||||
$width = round($product['width'], 2);
|
||||
$height = round($product['height'], 2);
|
||||
$depth = round($product['depth'], 2);
|
||||
|
||||
if (!empty($width)) {
|
||||
if (!empty($height)) {
|
||||
if (!empty($depth)) {
|
||||
$item['size'] = implode('x', array($width, $height, $depth));
|
||||
} else {
|
||||
$item['size'] = implode('x', array($width, $height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$items[] = $item;
|
||||
|
||||
}
|
||||
|
||||
return array($categories, $items);
|
||||
|
|
1
retailcrm/lib/vendor/Icml.php
vendored
1
retailcrm/lib/vendor/Icml.php
vendored
|
@ -32,6 +32,7 @@ class Icml
|
|||
'color' => 'Цвет',
|
||||
'weight' => 'Вес',
|
||||
'size' => 'Размер',
|
||||
'tax' => 'Наценка'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ class RetailCRM extends Module
|
|||
parent::install() &&
|
||||
$this->registerHook('newOrder') &&
|
||||
$this->registerHook('actionOrderStatusPostUpdate') &&
|
||||
$this->registerHook('actionPaymentConfirmation')
|
||||
|
||||
$this->registerHook('actionPaymentConfirmation') &&
|
||||
$this->registerHook('actionCustomerAccountAdd')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -387,6 +387,27 @@ class RetailCRM extends Module
|
|||
return $addressFields;
|
||||
}
|
||||
|
||||
public function hookActionCustomerAccountAdd($params)
|
||||
{
|
||||
try {
|
||||
$this->api->customersCreate(
|
||||
array(
|
||||
'externalId' => $params['newCustomer']->id,
|
||||
'firstName' => $params['newCustomer']->firstname,
|
||||
'lastName' => $params['newCustomer']->lastname,
|
||||
'email' => $params['newCustomer']->email,
|
||||
'createdAt' => $params['newCustomer']->date_add
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (CurlException $e) {
|
||||
error_log('customerCreate: connection error', 3, _PS_ROOT_DIR_ . "log/retailcrm.log");
|
||||
}
|
||||
catch (InvalidJsonException $e) {
|
||||
error_log('customerCreate: ' . $e->getMessage(), 3, _PS_ROOT_DIR_ . "log/retailcrm.log");
|
||||
}
|
||||
}
|
||||
|
||||
public function hookNewOrder($params)
|
||||
{
|
||||
return $this->hookActionOrderStatusPostUpdate($params);
|
||||
|
@ -448,7 +469,7 @@ class RetailCRM extends Module
|
|||
$items = array();
|
||||
foreach ($inCart as $item) {
|
||||
$items[] = array(
|
||||
'initialPrice' => $item['price'],
|
||||
'initialPrice' => (!empty($item['rate'])) ? $item['price'] + ($item['price'] * $item['rate'] / 100) : $item['price'],
|
||||
'quantity' => $item['quantity'],
|
||||
'productId' => $item['id_product'],
|
||||
'productName' => $item['name'],
|
||||
|
@ -457,30 +478,33 @@ class RetailCRM extends Module
|
|||
}
|
||||
|
||||
$dTypeKey = $params['cart']->id_carrier;
|
||||
|
||||
if (Module::getInstanceByName('advancedcheckout') === false) {
|
||||
$pTypeKey = $params['order']->module;
|
||||
} else {
|
||||
$pTypeKey = $params['order']->payment;
|
||||
}
|
||||
|
||||
$this->api->ordersCreate(
|
||||
array(
|
||||
'externalId' => $params['order']->id,
|
||||
'orderType' => 'eshop-individual',
|
||||
'orderMethod' => 'shopping-cart',
|
||||
'status' => 'new',
|
||||
'customerId' => $params['cart']->id_customer,
|
||||
'firstName' => $params['customer']->firstname,
|
||||
'lastName' => $params['customer']->lastname,
|
||||
'phone' => $address['phone'],
|
||||
'email' => $params['customer']->email,
|
||||
'paymentStatus' => 'not-paid',
|
||||
'paymentType' => $payment->$pTypeKey,
|
||||
'deliveryType' => $delivery->$dTypeKey,
|
||||
'deliveryCost' => $params['order']->total_shipping,
|
||||
'status' => 'new',
|
||||
'deliveryAddress' => array(
|
||||
'city' => $address['city'],
|
||||
'index' => $address['postcode'],
|
||||
'text' => $address['address1'],
|
||||
'delivery' => array(
|
||||
'code' => $delivery->$dTypeKey,
|
||||
'cost' => $params['order']->total_shipping,
|
||||
'address' => array(
|
||||
'city' => $address['city'],
|
||||
'index' => $address['postcode'],
|
||||
'text' => $address['address1'],
|
||||
)
|
||||
),
|
||||
'discount' => $params['order']->total_discounts,
|
||||
'items' => $items,
|
||||
|
|
Loading…
Add table
Reference in a new issue