mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-21 20:56:07 +03:00
Add info about discount on order (#211)
This commit is contained in:
parent
6391f49d2b
commit
4359f084bd
@ -328,7 +328,11 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'text_lenght_label',
|
'text_lenght_label',
|
||||||
'corporate_enabled_label',
|
'corporate_enabled_label',
|
||||||
'entry_code',
|
'entry_code',
|
||||||
'entry_status'
|
'entry_status',
|
||||||
|
'text_retailcrm_discount',
|
||||||
|
'text_label_retailcrm_discount',
|
||||||
|
'label_retailcrm_discount',
|
||||||
|
'default_label_retailcrm_discount'
|
||||||
);
|
);
|
||||||
|
|
||||||
$_data = &$data;
|
$_data = &$data;
|
||||||
|
@ -79,6 +79,11 @@ $_['text_status_changes'] = 'Record changes to the order history of Openc
|
|||||||
$_['column_total'] = 'Total';
|
$_['column_total'] = 'Total';
|
||||||
$_['product_summ'] = 'Sum';
|
$_['product_summ'] = 'Sum';
|
||||||
|
|
||||||
|
$_['text_retailcrm_discount'] = 'RetailCRM discount';
|
||||||
|
$_['text_retailcrm_label_discount'] = 'Label of RetailCRM discount in section total of order';
|
||||||
|
$_['default_retailcrm_label_discount'] = 'Discount in RetailCRM';
|
||||||
|
|
||||||
|
|
||||||
$_['article'] = 'Article';
|
$_['article'] = 'Article';
|
||||||
$_['color'] = 'Color';
|
$_['color'] = 'Color';
|
||||||
$_['weight'] = 'Weight';
|
$_['weight'] = 'Weight';
|
||||||
|
@ -79,6 +79,10 @@ $_['text_status_changes'] = 'Registrar los cambios en el historial de ped
|
|||||||
$_['column_total'] = 'Total';
|
$_['column_total'] = 'Total';
|
||||||
$_['product_summ'] = 'Importe';
|
$_['product_summ'] = 'Importe';
|
||||||
|
|
||||||
|
$_['text_retailcrm_discount'] = 'RetailCRM descuento';
|
||||||
|
$_['text_retailcrm_label_discount'] = 'Etiqueta de descuento de RetailCRM en la sección total del pedido';
|
||||||
|
$_['default_retailcrm_label_discount'] = 'Descuento en RetailCRM';
|
||||||
|
|
||||||
$_['article'] = 'Artículo';
|
$_['article'] = 'Artículo';
|
||||||
$_['color'] = 'Color';
|
$_['color'] = 'Color';
|
||||||
$_['weight'] = 'Peso';
|
$_['weight'] = 'Peso';
|
||||||
|
@ -79,6 +79,10 @@ $_['text_status_changes'] = 'Фиксировать изменения в
|
|||||||
$_['column_total'] = 'Итого';
|
$_['column_total'] = 'Итого';
|
||||||
$_['product_summ'] = 'Сумма';
|
$_['product_summ'] = 'Сумма';
|
||||||
|
|
||||||
|
$_['text_retailcrm_discount'] = 'Скидка RetailCRM';
|
||||||
|
$_['text_retailcrm_label_discount'] = 'Подпись для скидки, установленной в RetailCRM, в итоговой секции заказа';
|
||||||
|
$_['default_retailcrm_label_discount'] = 'Скидка в RetailCRM';
|
||||||
|
|
||||||
$_['article'] = 'Артикул';
|
$_['article'] = 'Артикул';
|
||||||
$_['color'] = 'Цвет';
|
$_['color'] = 'Цвет';
|
||||||
$_['weight'] = 'Вес';
|
$_['weight'] = 'Вес';
|
||||||
|
@ -213,6 +213,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend><?php echo $text_retailcrm_discount; ?></legend>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="label_discount"><?php echo $text_retailcrm_label_discount ?></label>
|
||||||
|
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||||
|
<input name="retailcrm_label_discount" id="label_discount" class="form-control" value="<?php if (isset($saved_settings['retailcrm_label_discount'])): echo $saved_settings['retailcrm_label_discount']; else: echo $default_retailcrm_label_discount; endif ;?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="tab-references">
|
<div class="tab-pane" id="tab-references">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -220,6 +220,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>{{ text_retailcrm_discount }}</legend>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="label_discount">{{ text_retailcrm_label_discount }}</label>
|
||||||
|
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||||
|
<input name="module_retailcrm_label_discount" id="label_discount" class="form-control" value="{% if saved_settings.module_retailcrm_label_discount is defined %}{{ saved_settings.module_retailcrm_label_discount }}{% else %}{{ default_retailcrm_label_discount }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="tab-references">
|
<div class="tab-pane" id="tab-references">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ModelExtensionTotalRetailcrmDiscount
|
||||||
|
*
|
||||||
|
* This class is unused in this module but used inside opencart as stub in file "catalog/model/checkout/order.php"
|
||||||
|
* in method addOrderHistory()
|
||||||
|
*/
|
||||||
|
class ModelExtensionTotalRetailcrmDiscount extends Model
|
||||||
|
{
|
||||||
|
}
|
@ -5,6 +5,7 @@ namespace retailcrm\history;
|
|||||||
use retailcrm\repository\DataRepository;
|
use retailcrm\repository\DataRepository;
|
||||||
use retailcrm\repository\OrderRepository;
|
use retailcrm\repository\OrderRepository;
|
||||||
use retailcrm\repository\ProductsRepository;
|
use retailcrm\repository\ProductsRepository;
|
||||||
|
use retailcrm\Retailcrm;
|
||||||
use retailcrm\service\SettingsManager;
|
use retailcrm\service\SettingsManager;
|
||||||
|
|
||||||
class Order {
|
class Order {
|
||||||
@ -285,6 +286,15 @@ class Order {
|
|||||||
$subtotal_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'sub_total');
|
$subtotal_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'sub_total');
|
||||||
$total_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'total');
|
$total_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'total');
|
||||||
$shipping_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'shipping');
|
$shipping_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'shipping');
|
||||||
|
$retailcrm_label_discount = $this->settings_manager->getSetting('label_discount')
|
||||||
|
?: $this->data_repository->getLanguage('default_retailcrm_label_discount');
|
||||||
|
|
||||||
|
$totalDiscount = 0;
|
||||||
|
foreach ($order['items'] as $item) {
|
||||||
|
if ($item['discountTotal'] !== 0) {
|
||||||
|
$totalDiscount += $item['discountTotal'] * $item['quantity'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$data['total'] = $order['totalSumm'];
|
$data['total'] = $order['totalSumm'];
|
||||||
$data['order_total'] = array(
|
$data['order_total'] = array(
|
||||||
@ -314,15 +324,41 @@ class Order {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//TODO подкорректировать логику добавления скидки из RetailCRM
|
||||||
|
//Если заказ создали со скидкой в RetailCRM, то добавить скидку
|
||||||
|
if (!empty($totalDiscount)) {
|
||||||
|
$data['order_total'][] = array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => Retailcrm::RETAILCRM_DISCOUNT,
|
||||||
|
'title' => $retailcrm_label_discount,
|
||||||
|
'value' => -$totalDiscount,
|
||||||
|
'sort_order' => Retailcrm::RETAILCRM_DISCOUNT_SORT_ORDER,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($order['externalId'])) {
|
if (!empty($order['externalId'])) {
|
||||||
$orderTotals = $this->order_repository->getOrderTotals($order['externalId']);
|
$orderTotals = $this->order_repository->getOrderTotals($order['externalId']);
|
||||||
|
|
||||||
foreach ($orderTotals as $orderTotal) {
|
foreach ($orderTotals as $orderTotal) {
|
||||||
if ($orderTotal['code'] == 'coupon'
|
if ($orderTotal['code'] == 'coupon'
|
||||||
|| $orderTotal['code'] == 'reward'
|
|| $orderTotal['code'] == 'reward'
|
||||||
|
|| $orderTotal['code'] == 'voucher'
|
||||||
) {
|
) {
|
||||||
$data['order_total'][] = $orderTotal;
|
$data['order_total'][] = $orderTotal;
|
||||||
|
$totalDiscount -= abs($orderTotal['value']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO подкорректировать логику добавления скидки из RetailCRM
|
||||||
|
$keyRetailCrmDiscount = array_search(Retailcrm::RETAILCRM_DISCOUNT, array_map(function ($item) {
|
||||||
|
return $item['code'];
|
||||||
|
}, $data['order_total']));
|
||||||
|
|
||||||
|
if ($totalDiscount > 0 && false !== $keyRetailCrmDiscount) {
|
||||||
|
$data['order_total'][$keyRetailCrmDiscount]['value'] = -$totalDiscount;
|
||||||
|
} elseif ($totalDiscount <= 0 && false !== $keyRetailCrmDiscount) {
|
||||||
|
unset($data['order_total'][$keyRetailCrmDiscount]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ class RetailcrmOrderConverter {
|
|||||||
$totalCoupon = $this->getTotal('coupon');
|
$totalCoupon = $this->getTotal('coupon');
|
||||||
$totalReward = $this->getTotal('reward');
|
$totalReward = $this->getTotal('reward');
|
||||||
$totalVoucher = $this->getTotal('voucher');
|
$totalVoucher = $this->getTotal('voucher');
|
||||||
|
$retailcrmDiscount = $this->getTotal(\retailcrm\Retailcrm::RETAILCRM_DISCOUNT);
|
||||||
|
|
||||||
if (!empty($totalCoupon)) {
|
if (!empty($totalCoupon)) {
|
||||||
$discount += abs($totalCoupon);
|
$discount += abs($totalCoupon);
|
||||||
@ -92,10 +93,12 @@ class RetailcrmOrderConverter {
|
|||||||
$discount += abs($totalVoucher);
|
$discount += abs($totalVoucher);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($discount > 0) {
|
if (!empty($retailcrmDiscount)) {
|
||||||
$this->data['discountManualAmount'] = $discount;
|
$discount += abs($retailcrmDiscount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->data['discountManualAmount'] = $discount;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,17 @@ use retailcrm\service\SettingsManager;
|
|||||||
require_once 'bootstrap.php';
|
require_once 'bootstrap.php';
|
||||||
|
|
||||||
class Retailcrm {
|
class Retailcrm {
|
||||||
|
|
||||||
|
const RETAILCRM_DISCOUNT = 'retailcrm_discount';
|
||||||
|
const RETAILCRM_DISCOUNT_SORT_ORDER = 8;
|
||||||
|
|
||||||
protected $registry;
|
protected $registry;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
public static $history_run = false;
|
public static $history_run = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(\Registry $registry) {
|
public function __construct(\Registry $registry) {
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user