mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
add update user and order, bug fixes (#10)
This commit is contained in:
parent
2c4f8524a6
commit
f6b26353a0
@ -364,10 +364,11 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
||||
$ptype = $order['paymentType'];
|
||||
|
||||
if ($payments[$ptype] != null) {
|
||||
$paymentType = Module::getModuleName($payments[$ptype]);
|
||||
if ($payments[$ptype] != $orderToUpdate->payment) {
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `' . _DB_PREFIX_ . 'orders`
|
||||
SET `payment` = \'' . $payments[$ptype] . '\'
|
||||
SET `payment` = \'' . ($paymentType != null ? $paymentType : $payments[$ptype]). '\'
|
||||
WHERE `id_order` = ' . (int)$order['externalId']
|
||||
);
|
||||
Db::getInstance()->execute('
|
||||
@ -411,7 +412,6 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
||||
*/
|
||||
foreach ($orderToUpdate->getProductsDetail() as $orderItem) {
|
||||
foreach ($order['items'] as $key => $item) {
|
||||
if (isset($item['discount']) || isset($item['discountPercent'])) $ItemDiscount = true;
|
||||
if(strpos($item['offer']['externalId'], '#') !== false) {
|
||||
$itemId = explode('#', $item['offer']['externalId']);
|
||||
$product_id = $itemId[0];
|
||||
@ -439,7 +439,6 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
||||
|
||||
$productPrice = $prodPrice - $item['discount'];
|
||||
$productPrice = $productPrice - ($prodPrice / 100 * $item['discountPercent']);
|
||||
$ItemDiscount = true;
|
||||
|
||||
$productPrice = round($productPrice , 2);
|
||||
|
||||
@ -460,6 +459,7 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
||||
);
|
||||
}
|
||||
|
||||
$ItemDiscount = true;
|
||||
unset($order['items'][$key]);
|
||||
}
|
||||
}
|
||||
@ -480,7 +480,6 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
||||
VALUES';
|
||||
|
||||
foreach ($order['items'] as $key => $newItem) {
|
||||
if ($newItem['discount'] || $newItem['discountPercent']) $ItemDiscount = true;
|
||||
$product_id = $newItem['offer']['externalId'];
|
||||
$product_attribute_id = 0;
|
||||
if(strpos($product_id, '#') !== false) {
|
||||
|
@ -36,6 +36,7 @@ class RetailCRM extends Module
|
||||
|
||||
if ($this->version == '1.6') {
|
||||
$this->bootstrap = true;
|
||||
$this->use_new_hooks = false;
|
||||
}
|
||||
|
||||
if ($this->validateCrmAddress($this->apiUrl) && !empty($this->apiKey)) {
|
||||
@ -53,7 +54,9 @@ class RetailCRM extends Module
|
||||
$this->registerHook('newOrder') &&
|
||||
$this->registerHook('actionOrderStatusPostUpdate') &&
|
||||
$this->registerHook('actionPaymentConfirmation') &&
|
||||
$this->registerHook('actionCustomerAccountAdd')
|
||||
$this->registerHook('actionCustomerAccountAdd') &&
|
||||
$this->registerHook('actionOrderEdited') &&
|
||||
($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true)
|
||||
);
|
||||
}
|
||||
|
||||
@ -298,6 +301,20 @@ class RetailCRM extends Module
|
||||
);
|
||||
}
|
||||
|
||||
// this hook added in 1.7
|
||||
public function hookActionCustomerAccountUpdate($params)
|
||||
{
|
||||
$this->api->customersEdit(
|
||||
array(
|
||||
'externalId' => $params['customer']->id,
|
||||
'firstName' => $params['customer']->firstname,
|
||||
'lastName' => $params['customer']->lastname,
|
||||
'email' => $params['customer']->email,
|
||||
'birthday' => $params['customer']->birthday
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function hookNewOrder($params)
|
||||
{
|
||||
return $this->hookActionOrderStatusPostUpdate($params);
|
||||
@ -315,6 +332,38 @@ class RetailCRM extends Module
|
||||
return $this->hookActionOrderStatusPostUpdate($params);
|
||||
}
|
||||
|
||||
public function hookActionOrderEdited($params)
|
||||
{
|
||||
$order = array(
|
||||
'externalId' => $params['order']->id,
|
||||
'firstName' => $params['customer']->firstname,
|
||||
'lastName' => $params['customer']->lastname,
|
||||
'email' => $params['customer']->email,
|
||||
'discount' => $params['order']->total_discounts,
|
||||
'createdAt' => $params['order']->date_add,
|
||||
'delivery' => array('cost' => $params['order']->total_shipping)
|
||||
);
|
||||
|
||||
$orderdb = new Order($params['order']->id);
|
||||
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'];
|
||||
}
|
||||
|
||||
$order['items'][] = array(
|
||||
'initialPrice' => $item['unit_price_tax_incl'],
|
||||
'quantity' => $item['product_quantity'],
|
||||
'offer' => array('externalId' => $productId),
|
||||
'productName' => $item['product_name'],
|
||||
);
|
||||
}
|
||||
|
||||
$order['customer']['externalId'] = $params['order']->id_customer;
|
||||
$this->api->ordersEdit($order);
|
||||
}
|
||||
|
||||
public function hookActionOrderStatusPostUpdate($params)
|
||||
{
|
||||
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user