mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-25 06:36:06 +03:00
Merge pull request #85 from iyzoer/master
Bonus points, fix customer group in history
This commit is contained in:
commit
65459af91b
@ -1,3 +1,7 @@
|
||||
## v.3.0.4
|
||||
* Добавлена проверка группы пользователя в заказе при редактировании
|
||||
* Добавлена передача скидки по бонусным баллам
|
||||
|
||||
## v.3.0.3
|
||||
* Исправлена ошибка с изменением пароля пользователя
|
||||
|
||||
|
@ -41,7 +41,6 @@ class ModelExtensionRetailcrmHistory extends Model
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
// Products
|
||||
if (isset($order['order_product']) && $order['order_product']) {
|
||||
|
@ -225,9 +225,13 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
$data['telephone'] = $phone;
|
||||
}
|
||||
|
||||
if (isset($order['customer']['externalId']) && $order['customer']['externalId']) {
|
||||
$customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']);
|
||||
}
|
||||
|
||||
$data['customer'] = $order['firstName'];
|
||||
$data['customer_id'] = (!empty($order['customer']['externalId'])) ? $order['customer']['externalId'] : 0;
|
||||
$data['customer_group_id'] = 1;
|
||||
$data['customer_id'] = (isset($customer)) ? $customer['customer_id'] : 0;
|
||||
$data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1;
|
||||
$data['firstname'] = $order['firstName'];
|
||||
$data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru';
|
||||
@ -279,8 +283,8 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : $ocOrder['payment_country'];
|
||||
$data['payment_zone_id'] = $payment_zone_id ? $payment_zone_id : $ocOrder['payment_zone_id'];
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : $ocOrder['payment_zone'];
|
||||
$data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id'];
|
||||
$data['shipping_country'] = $shippingCountry ? $shippingCountry['name'] : $ocOrder['shipping_country'];
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id'];
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : $ocOrder['shipping_country'];
|
||||
$data['shipping_zone_id'] = $shipping_zone_id ? $shipping_zone_id : $ocOrder['shipping_zone_id'];
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $ocOrder['shipping_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
@ -309,6 +313,10 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
}
|
||||
|
||||
$data['shipping_code'] = $data['shipping'];
|
||||
} elseif (!isset($this->settings[$this->moduleTitle . '_delivery'][$ocOrder['shipping_code']])
|
||||
) {
|
||||
$data['shipping_method'] = $ocOrder['shipping_method'];
|
||||
$data['shipping_code'] = $ocOrder['shipping_code'];
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->settings[$ocOrder['shipping_code']])
|
||||
@ -345,10 +353,16 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
|
||||
$data['order_product'] = array();
|
||||
|
||||
$discount = false;
|
||||
|
||||
foreach ($order['items'] as $item) {
|
||||
$productId = $item['offer']['externalId'];
|
||||
$options = array();
|
||||
|
||||
if (isset($item['discountTotal']) && $item['discountTotal'] > 0) {
|
||||
$discount = true;
|
||||
}
|
||||
|
||||
if (mb_strpos($item['offer']['externalId'], '#') > 1) {
|
||||
$offer = explode('#', $item['offer']['externalId']);
|
||||
$productId = $offer[0];
|
||||
@ -407,15 +421,6 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
|
||||
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||
|
||||
if(isset($order['discount']) && $order['discount'] > 0) {
|
||||
$orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']);
|
||||
foreach($orderTotals as $orderTotal) {
|
||||
if($orderTotal['code'] == 'coupon') {
|
||||
$data['order_total'][] = $orderTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['total'] = $order['totalSumm'];
|
||||
$data['order_total'] = array(
|
||||
array(
|
||||
@ -444,6 +449,20 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
)
|
||||
);
|
||||
|
||||
if ((isset($order['discount'])
|
||||
&& $order['discount'] > 0)
|
||||
|| $discount
|
||||
) {
|
||||
$orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']);
|
||||
foreach ($orderTotals as $orderTotal) {
|
||||
if ($orderTotal['code'] == 'coupon'
|
||||
|| $orderTotal['code'] == 'reward'
|
||||
) {
|
||||
$data['order_total'][] = $orderTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['fromApi'] = true;
|
||||
|
||||
if (array_key_exists($order['status'], $this->status)) {
|
||||
@ -592,8 +611,8 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['delivery']['address']['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['delivery']['address']['countryIso']);
|
||||
if (isset($order['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['countryIso'])) {
|
||||
@ -605,8 +624,8 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : '';
|
||||
$data['payment_zone_id'] = $payment_zone_id;
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : '';
|
||||
$data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0;
|
||||
$data['shipping_country'] = $shippingCountry ? $shippingCountry['name'] : '';
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0;
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : '';
|
||||
$data['shipping_zone_id'] = $shipping_zone_id;
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $data['payment_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
|
@ -158,6 +158,7 @@ class ModelExtensionRetailcrmOrder extends Model {
|
||||
}
|
||||
|
||||
$deliveryCost = 0;
|
||||
$couponTotal = 0;
|
||||
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
||||
|
||||
foreach ($orderTotals as $totals) {
|
||||
@ -166,7 +167,11 @@ class ModelExtensionRetailcrmOrder extends Model {
|
||||
}
|
||||
|
||||
if ($totals['code'] == 'coupon') {
|
||||
$couponTotal = abs($totals['value']);
|
||||
$couponTotal += abs($totals['value']);
|
||||
}
|
||||
|
||||
if ($totals['code'] == 'reward') {
|
||||
$couponTotal += abs($totals['value']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,11 +179,11 @@ class ModelExtensionRetailcrmOrder extends Model {
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') {
|
||||
$order['paymentType'] = $payment_code;
|
||||
if (isset($couponTotal)) {
|
||||
if ($couponTotal > 0) {
|
||||
$order['discount'] = $couponTotal;
|
||||
}
|
||||
} else {
|
||||
if (isset($couponTotal)) {
|
||||
if ($couponTotal > 0) {
|
||||
$order['discountManualAmount'] = $couponTotal;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user