diff --git a/src/Block/Adminhtml/System/Config/Form/Fieldset/PaymentList.php b/src/Block/Adminhtml/System/Config/Form/Fieldset/PaymentList.php
new file mode 100644
index 0000000..fb77324
--- /dev/null
+++ b/src/Block/Adminhtml/System/Config/Form/Fieldset/PaymentList.php
@@ -0,0 +1,95 @@
+_paymentCms) {
+ $this->_paymentCms = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\PaymentCms',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_paymentCms;
+ }
+
+ /**
+ * @return \Magento\Framework\View\Element\BlockInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _getPaymentCrmRenderer()
+ {
+ if (!$this->_paymentCrm) {
+ $this->_paymentCrm = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\PaymentCrm',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_paymentCrm;
+ }
+
+ /**
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _prepareToRender()
+ {
+ $this->addColumn(
+ 'payment_cms',
+ [
+ 'label' => __('CMS'),
+ 'renderer' => $this->_getPaymentCmsRenderer()
+ ]
+ );
+
+ $this->addColumn(
+ 'payment_crm',
+ [
+ 'label' => __('CRM'),
+ 'renderer' => $this->_getPaymentCrmRenderer()
+ ]
+ );
+
+ $this->_addAfter = false;
+ $this->_addButtonLabel = __('Add');
+ }
+
+ /**
+ *
+ * @param \Magento\Framework\DataObject $row
+ * @throws \Magento\Framework\Exception\LocalizedException
+ * @return void
+ */
+ protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
+ {
+ $options = [];
+ $customAttribute = $row->getData('payment_cms');
+ $key = 'option_' . $this->_getPaymentCmsRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $customAttribute = $row->getData('payment_crm');
+ $key = 'option_' . $this->_getPaymentCrmRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $row->setData('option_extra_attrs', $options);
+ }
+}
diff --git a/src/Block/Adminhtml/System/Config/Form/Fieldset/ShippingList.php b/src/Block/Adminhtml/System/Config/Form/Fieldset/ShippingList.php
new file mode 100644
index 0000000..d4475b4
--- /dev/null
+++ b/src/Block/Adminhtml/System/Config/Form/Fieldset/ShippingList.php
@@ -0,0 +1,95 @@
+_shippingCms) {
+ $this->_shippingCms = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\ShippingCms',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_shippingCms;
+ }
+
+ /**
+ * @return \Magento\Framework\View\Element\BlockInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _getShippingCrmRenderer()
+ {
+ if (!$this->_shippingCrm) {
+ $this->_shippingCrm = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\ShippingCrm',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_shippingCrm;
+ }
+
+ /**
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _prepareToRender()
+ {
+ $this->addColumn(
+ 'shipping_cms',
+ [
+ 'label' => __('CMS'),
+ 'renderer' => $this->_getShippingCmsRenderer()
+ ]
+ );
+
+ $this->addColumn(
+ 'shipping_crm',
+ [
+ 'label' => __('CRM'),
+ 'renderer' => $this->_getShippingCrmRenderer()
+ ]
+ );
+
+ $this->_addAfter = false;
+ $this->_addButtonLabel = __('Add');
+ }
+
+ /**
+ *
+ * @param \Magento\Framework\DataObject $row
+ * @throws \Magento\Framework\Exception\LocalizedException
+ * @return void
+ */
+ protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
+ {
+ $options = [];
+ $customAttribute = $row->getData('shipping_cms');
+ $key = 'option_' . $this->_getShippingCmsRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $customAttribute = $row->getData('shipping_crm');
+ $key = 'option_' . $this->_getShippingCrmRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $row->setData('option_extra_attrs', $options);
+ }
+}
diff --git a/src/Block/Adminhtml/System/Config/Form/Fieldset/StatusList.php b/src/Block/Adminhtml/System/Config/Form/Fieldset/StatusList.php
new file mode 100644
index 0000000..53ea867
--- /dev/null
+++ b/src/Block/Adminhtml/System/Config/Form/Fieldset/StatusList.php
@@ -0,0 +1,95 @@
+_statusCms) {
+ $this->_statusCms = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\StatusCms',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_statusCms;
+ }
+
+ /**
+ * @return \Magento\Framework\View\Element\BlockInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _getStatusCrmRenderer()
+ {
+ if (!$this->_statusCrm) {
+ $this->_statusCrm = $this->getLayout()->createBlock(
+ '\Retailcrm\Retailcrm\Model\Config\Backend\StatusCrm',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ }
+
+ return $this->_statusCrm;
+ }
+
+ /**
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function _prepareToRender()
+ {
+ $this->addColumn(
+ 'status_cms',
+ [
+ 'label' => __('CMS'),
+ 'renderer' => $this->_getStatusCmsRenderer()
+ ]
+ );
+
+ $this->addColumn(
+ 'status_crm',
+ [
+ 'label' => __('CRM'),
+ 'renderer' => $this->_getStatusCrmRenderer()
+ ]
+ );
+
+ $this->_addAfter = false;
+ $this->_addButtonLabel = __('Add');
+ }
+
+ /**
+ *
+ * @param \Magento\Framework\DataObject $row
+ * @throws \Magento\Framework\Exception\LocalizedException
+ * @return void
+ */
+ protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
+ {
+ $options = [];
+ $customAttribute = $row->getData('status_cms');
+ $key = 'option_' . $this->_getStatusCmsRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $customAttribute = $row->getData('status_crm');
+ $key = 'option_' . $this->_getStatusCrmRenderer()->calcOptionHash($customAttribute);
+ $options[$key] = 'selected="selected"';
+
+ $row->setData('option_extra_attrs', $options);
+ }
+}
diff --git a/src/Helper/Data.php b/src/Helper/Data.php
index dc805fc..5e207cd 100644
--- a/src/Helper/Data.php
+++ b/src/Helper/Data.php
@@ -11,6 +11,7 @@ use Magento\Store\Model\ScopeInterface;
class Data extends AbstractHelper
{
private $storeManager;
+ private $json;
const XML_PATH_RETAILCRM = 'retailcrm/';
const XML_PATH_DEFAULT_SITE = 'retailcrm_site/default';
@@ -19,9 +20,11 @@ class Data extends AbstractHelper
const XML_PATH_INVENTORIES = 'inventories_upload/';
public function __construct(
+ \Magento\Framework\Serialize\Serializer\Json $json,
Context $context,
StoreManagerInterface $storeManager
) {
+ $this->json = $json;
$this->storeManager = $storeManager;
parent::__construct($context);
}
@@ -206,4 +209,46 @@ class Data extends AbstractHelper
return $haystack;
}
+
+ /**
+ * @return mixed
+ */
+ public function getConfigPayments()
+ {
+ $json = $this->scopeConfig->getValue('retailcrm/paymentList/paymentList');
+ $List = $this->json->unserialize($json);
+ foreach ($List as $code => $el) {
+ $payments[$el['payment_cms']] = $el['payment_crm'];
+ }
+
+ return $payments;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCongigShipping()
+ {
+ $json = $this->scopeConfig->getValue('retailcrm/shippingList/shippingList');
+ $shippingList = $this->json->unserialize($json);
+ foreach ($shippingList as $code => $el) {
+ $shippings[$el['shipping_cms']] = $el['shipping_crm'];
+ }
+
+ return $shippings;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCongigStatus()
+ {
+ $json = $this->scopeConfig->getValue('retailcrm/statusList/statusList');
+ $List = $this->json->unserialize($json);
+ foreach ($List as $code => $el) {
+ $statusList[$el['status_cms']] = $el['status_crm'];
+ }
+
+ return $statusList;
+ }
}
diff --git a/src/Model/Config/Backend/PaymentCms.php b/src/Model/Config/Backend/PaymentCms.php
new file mode 100644
index 0000000..3b6c17e
--- /dev/null
+++ b/src/Model/Config/Backend/PaymentCms.php
@@ -0,0 +1,56 @@
+paymentConfig = $paymentConfig;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+
+ $paymentMethods = $this->paymentConfig->getActiveMethods();
+
+ foreach ($paymentMethods as $code => $payment) {
+ $this->addOption($payment->getCode(), $payment->getTitle());
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/Config/Backend/PaymentCrm.php b/src/Model/Config/Backend/PaymentCrm.php
new file mode 100644
index 0000000..2d5fd61
--- /dev/null
+++ b/src/Model/Config/Backend/PaymentCrm.php
@@ -0,0 +1,59 @@
+client = $client;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+
+ $response = $this->client->paymentTypesList();
+
+ if ($response->isSuccessful()) {
+ $paymentsTypes = $response['paymentTypes'];
+ }
+
+ $this->addOption( 'null', " ");
+ foreach ($paymentsTypes as $paymentsType) {
+ $this->addOption($paymentsType['code'], $paymentsType['name']);
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/Config/Backend/ShippingCms.php b/src/Model/Config/Backend/ShippingCms.php
new file mode 100644
index 0000000..7a808f6
--- /dev/null
+++ b/src/Model/Config/Backend/ShippingCms.php
@@ -0,0 +1,55 @@
+shippingConfig = $shippingConfig;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+ $deliveryMethods = $this->shippingConfig->getActiveCarriers();
+
+ foreach ($deliveryMethods as $code => $delivery) {
+ $this->addOption($delivery->getCarrierCode(), $delivery->getConfigData('title'));
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/Config/Backend/ShippingCrm.php b/src/Model/Config/Backend/ShippingCrm.php
new file mode 100644
index 0000000..086e97e
--- /dev/null
+++ b/src/Model/Config/Backend/ShippingCrm.php
@@ -0,0 +1,59 @@
+client = $client;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+
+ $response = $this->client->deliveryTypesList();
+
+ if ($response->isSuccessful()) {
+ $deliveryTypes = $response['deliveryTypes'];
+ }
+
+ $this->addOption( 'null', " ");
+ foreach ($deliveryTypes as $deliveryType) {
+ $this->addOption($deliveryType['code'], $deliveryType['name']);
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/Config/Backend/StatusCms.php b/src/Model/Config/Backend/StatusCms.php
new file mode 100644
index 0000000..734704e
--- /dev/null
+++ b/src/Model/Config/Backend/StatusCms.php
@@ -0,0 +1,55 @@
+statusCollection = $statusCollection;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+ $statuses = $this->statusCollection->toOptionArray();
+
+ foreach ($statuses as $code => $status) {
+ $this->addOption( $status['value'], $status['label']);
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/Config/Backend/StatusCrm.php b/src/Model/Config/Backend/StatusCrm.php
new file mode 100644
index 0000000..d40e2b3
--- /dev/null
+++ b/src/Model/Config/Backend/StatusCrm.php
@@ -0,0 +1,59 @@
+client = $client;
+ }
+
+ /**
+ * @param string $value
+ * @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
+ */
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Parse to html.
+ *
+ * @return mixed
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+
+ $response = $this->client->statusesList();
+
+ if ($response->isSuccessful()) {
+ $statuses = $response['statuses'];
+ }
+
+ $this->addOption( 'null', " ");
+ foreach ($statuses as $status) {
+ $this->addOption($status['code'], $status['name']);
+ }
+ }
+
+ return parent::_toHtml();
+ }
+}
diff --git a/src/Model/History/Exchange.php b/src/Model/History/Exchange.php
index b6f821d..326a360 100644
--- a/src/Model/History/Exchange.php
+++ b/src/Model/History/Exchange.php
@@ -161,8 +161,8 @@ class Exchange
{
$this->logger->writeDump($order, 'doCreate');
- $payments = $this->config->getValue('retailcrm/retailcrm_payment');
- $shippings = $this->config->getValue('retailcrm/retailcrm_shipping');
+ $payments = $this->helper->getConfigPayments();
+ $shippings = $this->helper->getCongigShipping();
$sites = $this->helper->getMappingSites();
if ($sites && in_array($order['site'], $sites)) {
@@ -242,7 +242,7 @@ class Exchange
//add items in quote
foreach ($ditems as $id =>$item) {
$product = $productRepository->getById($id,false, $store->getId(), false);
- $product->setPrice($item['price_item']);
+ $product->setPrice($item['initialPrice']);
$quote->addProduct(
$product,
(int)$item['quantity']
@@ -349,8 +349,8 @@ class Exchange
$order = $response['order'];
}
- $payments = $this->config->getValue('retailcrm/retailcrm_payment');
- $shippings = $this->config->getValue('retailcrm/retailcrm_shipping');
+ $payments = $this->helper->getConfigPayments();
+ $shippings = $this->helper->getCongigShipping();
$region = $this->regionFactory->create();
$sites = $this->helper->getMappingSites();
@@ -411,7 +411,7 @@ class Exchange
//add items in quote
foreach ($ditems as $id => $item) {
$product = $productRepository->getById($id,false, $store->getId(), false);
- $product->setPrice($item['price_item']);
+ $product->setPrice($item['initialPrice']);
$quote->addProduct(
$product,
(int)$item['quantity']
@@ -520,7 +520,7 @@ class Exchange
{
$this->logger->writeDump($order, 'doUpdate');
- $Status = $this->config->getValue('retailcrm/retailcrm_status');
+ $Status = $this->helper->getCongigStatus();
$Status = array_flip(array_filter($Status));
$magentoOrder = $this->order->load($order['externalId']);
diff --git a/src/Model/Observer/OrderUpdate.php b/src/Model/Observer/OrderUpdate.php
index 0f65184..ed5768e 100644
--- a/src/Model/Observer/OrderUpdate.php
+++ b/src/Model/Observer/OrderUpdate.php
@@ -53,9 +53,11 @@ class OrderUpdate implements \Magento\Framework\Event\ObserverInterface
$order = $observer->getEvent()->getOrder();
if ($order) {
+ $statusList = $this->helper->getCongigStatus();
+
$this->order = [
'externalId' => $order->getId(),
- 'status' => $this->config->getValue('retailcrm/retailcrm_status/' . $order->getStatus())
+ 'status' => $statusList[$order->getStatus()]
];
if ($order->getBaseTotalDue() == 0) {
diff --git a/src/Model/Service/Order.php b/src/Model/Service/Order.php
index 5ed2bb9..f8940b7 100644
--- a/src/Model/Service/Order.php
+++ b/src/Model/Service/Order.php
@@ -37,6 +37,10 @@ class Order implements \Retailcrm\Retailcrm\Api\OrderManagerInterface
$shippingAddress = $order->getShippingAddress();
$shipping = $this->getShippingCode($order->getShippingMethod());
+ $shipList = $this->helper->getCongigShipping();
+ $statusList = $this->helper->getCongigStatus();
+ $paymentList = $this->helper->getConfigPayments();
+
$preparedOrder = [
'externalId' => $order->getId(),
'number' => $order->getRealOrderId(),
@@ -46,10 +50,10 @@ class Order implements \Retailcrm\Retailcrm\Api\OrderManagerInterface
'patronymic' => $shippingAddress->getMiddlename(),
'email' => $shippingAddress->getEmail(),
'phone' => $shippingAddress->getTelephone(),
- 'status' => $this->config->getValue('retailcrm/retailcrm_status/' . $order->getStatus()),
+ 'status' => $statusList[$order->getStatus()],
'items' => $products,
'delivery' => [
- 'code' => $this->config->getValue('retailcrm/retailcrm_shipping/' . $shipping),
+ 'code' => $shipList[$shipping],
'cost' => $order->getShippingAmount(),
'address' => [
'index' => $shippingAddress->getData('postcode'),
@@ -80,15 +84,11 @@ class Order implements \Retailcrm\Retailcrm\Api\OrderManagerInterface
if ($this->helper->getGeneralSettings('api_version') == 'v4') {
$preparedOrder['discount'] = abs($order->getDiscountAmount());
- $preparedOrder['paymentType'] = $this->config->getValue(
- 'retailcrm/retailcrm_payment/' . $order->getPayment()->getMethodInstance()->getCode()
- );
+ $preparedOrder['paymentType'] = $paymentList[$order->getPayment()->getMethodInstance()->getCode()];
} elseif ($this->helper->getGeneralSettings('api_version') == 'v5') {
$preparedOrder['discountManualAmount'] = abs($order->getDiscountAmount());
$payment = [
- 'type' => $this->config->getValue(
- 'retailcrm/retailcrm_payment/' . $order->getPayment()->getMethodInstance()->getCode()
- ),
+ 'type'=> $paymentList[$order->getPayment()->getMethodInstance()->getCode()],
'externalId' => $codeShop.$order->getId(),
'order' => [
'externalId' => $order->getId(),
diff --git a/src/etc/adminhtml/system.xml b/src/etc/adminhtml/system.xml
index 3130bb6..56617e1 100644
--- a/src/etc/adminhtml/system.xml
+++ b/src/etc/adminhtml/system.xml
@@ -34,17 +34,29 @@
Retailcrm\Retailcrm\Model\Setting\Attribute
-
+
- Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Shipping
+
+
+ Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\ShippingList
+ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
+
-
+
- Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Payment
+
+
+ Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\PaymentList
+ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
+
-
-
- Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Status
+
+
+
+
+ Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\StatusList
+ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
+