1
0
mirror of synced 2024-11-25 22:46:07 +03:00

Multisite, validation of settings before saving, ICML catalog generation changed

This commit is contained in:
Akolzin Dmitry 2018-05-10 14:46:20 +03:00
parent ecd0dc03c0
commit ee90b20a65
12 changed files with 469 additions and 115 deletions

View File

@ -0,0 +1,37 @@
<?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Backend_Api_Key extends Mage_Core_Model_Config_Data
{
protected function _beforeSave()
{
if ($this->isValueChanged()) {
$api_url = $this->getFieldsetDataValue('api_url');
$api_key = $this->getValue();
if (!$api_key) {
Mage::throwException(Mage::helper('retailcrm')->__('Field API KEY could not be empty'));
}
$api_client = new Retailcrm_Retailcrm_Model_ApiClient(
$api_url,
$api_key
);
try {
$response = $api_client->sitesList();
} catch (Retailcrm_Retailcrm_Model_Exception_CurlException $curlException) {
Mage::throwException(Mage::helper('retailcrm')->__($curlException->getMessage()));
} catch (Retailcrm_Retailcrm_Model_Exception_InvalidJsonException $invalidJsonException) {
Mage::throwException(Mage::helper('retailcrm')->__($invalidJsonException->getMessage()));
} catch (\InvalidArgumentException $invalidArgumentException) {
Mage::throwException(Mage::helper('retailcrm')->__($invalidArgumentException->getMessage()));
}
if (isset($response['errorMsg'])) {
Mage::throwException(Mage::helper('retailcrm')->__($response['errorMsg']));
}
}
return $this;
}
}

View File

@ -0,0 +1,42 @@
<?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Backend_Api_Url extends Mage_Core_Model_Config_Data
{
protected function _beforeSave()
{
if ($this->isValueChanged()) {
$api_url = $this->getValue();
$api_key = $this->getFieldsetDataValue('api_key');
if (!$api_url) {
Mage::throwException(Mage::helper('retailcrm')->__('Field API URL could not be empty'));
}
if (false === stripos($api_url, 'https://')) {
$api_url = str_replace("http://", "https://", $api_url);
$this->setValue($api_url);
}
$api_client = new Retailcrm_Retailcrm_Model_ApiClient(
$api_url,
$api_key
);
try {
$response = $api_client->sitesList();
} catch (Retailcrm_Retailcrm_Model_Exception_CurlException $curlException) {
Mage::throwException(Mage::helper('retailcrm')->__($curlException->getMessage()));
} catch (Retailcrm_Retailcrm_Model_Exception_InvalidJsonException $invalidJsonException) {
Mage::throwException(Mage::helper('retailcrm')->__($invalidJsonException->getMessage()));
} catch (\InvalidArgumentException $invalidArgumentException) {
Mage::throwException(Mage::helper('retailcrm')->__($invalidArgumentException->getMessage()));
}
if (isset($response['errorMsg'])) {
Mage::throwException(Mage::helper('retailcrm')->__($response['errorMsg']));
}
}
return $this;
}
}

View File

@ -14,30 +14,9 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base exten
$this->_apiUrl = Mage::getStoreConfig('retailcrm/general/api_url'); $this->_apiUrl = Mage::getStoreConfig('retailcrm/general/api_url');
$this->_apiKey = Mage::getStoreConfig('retailcrm/general/api_key'); $this->_apiKey = Mage::getStoreConfig('retailcrm/general/api_key');
$this->_isCredentialCorrect = false; $this->_isCredentialCorrect = false;
if (!empty($this->_apiUrl) && !empty($this->_apiKey)) { if (!empty($this->_apiUrl) && !empty($this->_apiKey)) {
if (false === stripos($this->_apiUrl, 'https://')) {
$this->_apiUrl = str_replace("http://", "https://", $this->_apiUrl);
Mage::getModel('core/config')->saveConfig('retailcrm/general/api_url', $this->_apiUrl);
}
$client = new Retailcrm_Retailcrm_Model_ApiClient(
$this->_apiUrl,
$this->_apiKey
);
try {
$response = $client->sitesList();
} catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
Mage::log($e->getMessage());
}
if ($response->isSuccessful()) {
$this->_isCredentialCorrect = true; $this->_isCredentialCorrect = true;
if($response['success'] != 1) {
Mage::getModel('core/config')->saveConfig('retailcrm/general/api_url', '');
}
}
} }
} }
} }

View File

@ -0,0 +1,85 @@
<?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Site extends Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base
{
public function render(Varien_Data_Form_Element_Abstract $element)
{
$html = $this->_getHeaderHtml($element);
if (!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
$html .= $this->_getFieldHtml($element);
} else {
$html .= '<div style="margin-left: 15px;"><b><i>Please check your API Url & API Key</i></b></div>';
}
$html .= $this->_getFooterHtml($element);
return $html;
}
protected function _getFieldRenderer()
{
if (empty($this->_fieldRenderer)) {
$this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
}
return $this->_fieldRenderer;
}
/**
* @return array
*/
protected function _getValues()
{
if (!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
$client = new Retailcrm_Retailcrm_Model_ApiClient(
$this->_apiUrl,
$this->_apiKey
);
try {
$sites = $client->sitesList();
} catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
Mage::log($e->getMessage());
}
if ($sites->isSuccessful()) {
if (empty($this->_values)) {
foreach ($sites['sites'] as $site) {
$this->_values[] = array('label'=>Mage::helper('adminhtml')->__($site['name']), 'value'=>$site['code']);
}
}
}
}
return $this->_values;
}
protected function _getFieldHtml($fieldset)
{
$configData = $this->getConfigData();
$path = 'retailcrm/site/default';
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
} else {
$data = (int)(string)$this->getForm()->getConfigRoot()->descend($path);
$inherit = true;
}
$field = $fieldset->addField(
'site_default', 'select',
array(
'name' => 'groups[site][fields][default][value]',
'label' => 'Default',
'value' => $data,
'values' => $this->_getValues(),
'inherit' => $inherit,
'can_use_default_value' => 1,
'can_use_website_value' => 1
)
)->setRenderer($this->_getFieldRenderer());
return $field->toHtml();
}
}

View File

@ -0,0 +1,89 @@
<?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Sites extends Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base
{
public function render(Varien_Data_Form_Element_Abstract $element)
{
$html = $this->_getHeaderHtml($element);
if (!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
$websiteCode = Mage::app()->getRequest()->getParam('website');
$website = Mage::app()->getWebsite()->load($websiteCode);
foreach ($website->getStoreCollection() as $store) {
$html .= $this->_getFieldHtml($element, $store);
}
} else {
$html .= '<div style="margin-left: 15px;"><b><i>Please check your API Url & API Key</i></b></div>';
}
$html .= $this->_getFooterHtml($element);
return $html;
}
protected function _getFieldRenderer()
{
if (empty($this->_fieldRenderer)) {
$this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
}
return $this->_fieldRenderer;
}
/**
* @return array
*/
protected function _getValues()
{
if (!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
$client = new Retailcrm_Retailcrm_Model_ApiClient(
$this->_apiUrl,
$this->_apiKey
);
try {
$sites = $client->sitesList();
} catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
Mage::log($e->getMessage());
}
if ($sites->isSuccessful()) {
if (empty($this->_values)) {
foreach ($sites['sites'] as $site) {
$this->_values[] = array('label'=>Mage::helper('adminhtml')->__($site['name']), 'value'=>$site['code']);
}
}
}
}
return $this->_values;
}
protected function _getFieldHtml($fieldset, $group)
{
$configData = $this->getConfigData();
$path = 'retailcrm/sites/' . $group->getCode();
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
} else {
$data = (int)(string)$this->getForm()->getConfigRoot()->descend($path);
$inherit = true;
}
$field = $fieldset->addField(
'sites_' . $group->getCode(), 'select',
array(
'name' => 'groups[sites][fields][' . $group->getCode() . '][value]',
'label' => $group->getName(),
'value' => $data,
'values' => $this->_getValues(),
'inherit' => $inherit,
'can_use_default_value' => 1,
'can_use_website_value' => 1
)
)->setRenderer($this->_getFieldRenderer());
return $field->toHtml();
}
}

View File

@ -37,6 +37,74 @@ class Retailcrm_Retailcrm_Helper_Data extends Mage_Core_Helper_Abstract
*/ */
const XML_API_KEY = 'retailcrm/general/api_key'; const XML_API_KEY = 'retailcrm/general/api_key';
/**
* @var string
*/
const XML_SITES = 'retailcrm/sites/';
/**
* @var string
*/
const XML_SITE = 'retailcrm/site/default';
/**
* Get site code
*
* @param Mage_Core_Model_Store $store
*
* @return mixed|null
*/
public function getSite($store)
{
if (!$store instanceof Mage_Core_Model_Store
&& is_int($store)
) {
$store = Mage::app()->getStore($store);
}
$website = $store->getWebsite();
$site = $website->getConfig(self::XML_SITES . $store->getCode());
if ($site) {
return $site;
} else {
$site = Mage::getStoreConfig(self::XML_SITE);
if ($site) {
return $site;
}
}
return null;
}
/**
* @return array
*/
public function getMappingSites() {
$sites = array();
$webSites = Mage::app()->getWebsites();
foreach ($webSites as $webSite) {
$storesFromSite = $webSite->getStores();
foreach ($storesFromSite as $store) {
$config = $webSite->getConfig(self::XML_SITES . $store->getCode());
if ($config) {
$sites[$config] = $store->getCode();
}
}
unset($storesFromSite);
}
unset($webSites);
return $sites;
}
/** /**
* Get api url * Get api url
* *

View File

@ -31,6 +31,7 @@ class Retailcrm_Retailcrm_Model_Customer extends Retailcrm_Retailcrm_Model_Excha
'lastName' => $data->getLastname(), 'lastName' => $data->getLastname(),
'createdAt' => Mage::getSingleton('core/date')->date() 'createdAt' => Mage::getSingleton('core/date')->date()
); );
$this->_api->setSite(Mage::helper('retailcrm')->getSite($data->getStore()));
$this->_api->customersEdit($customer); $this->_api->customersEdit($customer);
} }
@ -44,7 +45,7 @@ class Retailcrm_Retailcrm_Model_Customer extends Retailcrm_Retailcrm_Model_Excha
*/ */
public function customersExport() public function customersExport()
{ {
$customers = array(); $customersSites = array();
$customerCollection = Mage::getModel('customer/customer') $customerCollection = Mage::getModel('customer/customer')
->getCollection() ->getCollection()
->addAttributeToSelect('email') ->addAttributeToSelect('email')
@ -57,18 +58,22 @@ class Retailcrm_Retailcrm_Model_Customer extends Retailcrm_Retailcrm_Model_Excha
'firstName' => $customerData->getData('firstname'), 'firstName' => $customerData->getData('firstname'),
'lastName' => $customerData->getData('lastname') 'lastName' => $customerData->getData('lastname')
); );
$customers[] = $customer;
$customersSites[$customerData->getStore()->getId()][] = $customer;
} }
unset($customerCollection); unset($customerCollection);
foreach ($customersSites as $storeId => $customers) {
$chunked = array_chunk($customers, 50); $chunked = array_chunk($customers, 50);
unset($customers); unset($customers);
foreach ($chunked as $chunk) { foreach ($chunked as $chunk) {
$this->_api->customersUpload($chunk); $this->_api->customersUpload($chunk, Mage::helper('retailcrm')->getSite($storeId));
time_nanosleep(0, 250000000); time_nanosleep(0, 250000000);
} }
unset($chunked); unset($chunked);
}
return true; return true;
} }

View File

@ -6,9 +6,11 @@ class Retailcrm_Retailcrm_Model_Exchange
protected $_apiUrl; protected $_apiUrl;
protected $_config; protected $_config;
protected $_api; protected $_api;
private $_helper;
public function __construct() public function __construct()
{ {
$this->_helper = Mage::helper('retailcrm');
$this->_apiUrl = Mage::getStoreConfig('retailcrm/general/api_url'); $this->_apiUrl = Mage::getStoreConfig('retailcrm/general/api_url');
$this->_apiKey = Mage::getStoreConfig('retailcrm/general/api_key'); $this->_apiKey = Mage::getStoreConfig('retailcrm/general/api_key');
@ -134,7 +136,17 @@ class Retailcrm_Retailcrm_Model_Exchange
// get store // get store
$_sendConfirmation = '0'; $_sendConfirmation = '0';
$storeId = Mage::app()->getStore()->getId(); $sitesConfig = $this->_helper->getMappingSites();
if (!$sitesConfig) {
$storeId = Mage::app()
->getWebsite(true)
->getDefaultGroup()
->getDefaultStoreId();
} else {
$storeId = Mage::app()->getStore()->load($sitesConfig[$order['site']])->getId();
}
$siteid = Mage::getModel('core/store')->load($storeId)->getWebsiteId(); $siteid = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
// search or create customer // search or create customer
@ -356,7 +368,17 @@ class Retailcrm_Retailcrm_Model_Exchange
// get store // get store
$_sendConfirmation = '0'; $_sendConfirmation = '0';
$storeId = Mage::app()->getStore()->getId(); $sitesConfig = $this->_helper->getMappingSites();
if (!$sitesConfig) {
$storeId = Mage::app()
->getWebsite(true)
->getDefaultGroup()
->getDefaultStoreId();
} else {
$storeId = Mage::app()->getStore()->load($sitesConfig[$order['site']])->getId();
}
$siteid = Mage::getModel('core/store')->load($storeId)->getWebsiteId(); $siteid = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
// search or create customer // search or create customer

View File

@ -14,7 +14,7 @@ class Retailcrm_Retailcrm_Model_Icml
$string = '<?xml version="1.0" encoding="UTF-8"?> $string = '<?xml version="1.0" encoding="UTF-8"?>
<yml_catalog date="'.date('Y-m-d H:i:s').'"> <yml_catalog date="'.date('Y-m-d H:i:s').'">
<shop> <shop>
<name>'.Mage::app()->getStore($shop)->getName().'</name> <name>'.$shop->getName().'</name>
<categories/> <categories/>
<offers/> <offers/>
</shop> </shop>
@ -41,9 +41,8 @@ class Retailcrm_Retailcrm_Model_Icml
$this->_dd->saveXML(); $this->_dd->saveXML();
$baseDir = Mage::getBaseDir(); $baseDir = Mage::getBaseDir();
$shopCode = Mage::app()->getStore($shop)->getCode(); $shopCode = $shop->getCode();
$this->_dd->save($baseDir . DS . 'retailcrm_' . $shopCode . '.xml'); $this->_dd->save($baseDir . DS . 'retailcrm_' . $shopCode . '.xml');
} }
private function addCategories() private function addCategories()
@ -102,7 +101,6 @@ class Retailcrm_Retailcrm_Model_Icml
$collection->addFieldToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); $collection->addFieldToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); $collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$collection->addAttributeToFilter('type_id', array('eq' => 'simple'));
foreach ($collection as $product) { foreach ($collection as $product) {
/** @var Mage_Catalog_Model_Product $product */ /** @var Mage_Catalog_Model_Product $product */
@ -174,6 +172,7 @@ class Retailcrm_Retailcrm_Model_Icml
$offers[] = $offer; $offers[] = $offer;
if($product->getTypeId() == 'configurable') { if($product->getTypeId() == 'configurable') {
/** @var Mage_Catalog_Model_Product_Type_Configurable $product */ /** @var Mage_Catalog_Model_Product_Type_Configurable $product */
$associatedProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product); $associatedProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);

View File

@ -59,8 +59,8 @@ class Retailcrm_Retailcrm_Model_Observer
public function exportCatalog() public function exportCatalog()
{ {
foreach (Mage::app()->getWebsites() as $website) { foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) { foreach ($website->getStores() as $store) {
Mage::getModel('retailcrm/icml')->generate((int)$group->getId()); Mage::getModel('retailcrm/icml')->generate($store);
} }
} }
} }

View File

@ -31,7 +31,10 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
'externalId' => $order->getRealOrderId(),//getId(), 'externalId' => $order->getRealOrderId(),//getId(),
'paymentStatus' => 'paid', 'paymentStatus' => 'paid',
); );
$preparedOrder = Mage::helper('retailcrm')->filterRecursive($preparedOrder);
$helper = Mage::helper('retailcrm');
$preparedOrder = $helper->filterRecursive($preparedOrder);
$this->_api->setSite($helper->getSite($order->getStore()));
$this->_api->ordersEdit($preparedOrder); $this->_api->ordersEdit($preparedOrder);
} }
} }
@ -55,12 +58,12 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
$preparedOrder['managerComment'] = $comment[0]['comment']; $preparedOrder['managerComment'] = $comment[0]['comment'];
} }
$preparedOrder = Mage::helper('retailcrm')->filterRecursive($preparedOrder); $helper = Mage::helper('retailcrm');
$preparedOrder = $helper->filterRecursive($preparedOrder);
$this->_api->setSite($helper->getSite($order->getStore()));
$this->_api->ordersEdit($preparedOrder); $this->_api->ordersEdit($preparedOrder);
} }
public function orderUpdate($order) public function orderUpdate($order)
{ {
$config = Mage::getModel( $config = Mage::getModel(
@ -75,14 +78,16 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
); );
if ((float)$order->getBaseGrandTotal() == (float)$order->getTotalPaid()) { if ((float)$order->getBaseGrandTotal() == (float)$order->getTotalPaid()) {
$preparedOrder['paymentStatus'] = 'paid'; $preparedOrder['paymentStatus'] = 'paid';
$preparedOrder = Mage::helper('retailcrm')->filterRecursive($preparedOrder); $helper = Mage::helper('retailcrm');
$preparedOrder = $helper->filterRecursive($preparedOrder);
$this->_api->setSite($helper->getSite($order->getStore()));
$this->_api->ordersEdit($preparedOrder); $this->_api->ordersEdit($preparedOrder);
} }
} }
public function orderCreate($order) public function orderCreate($order)
{ {
$helper = Mage::helper('retailcrm');
$config = Mage::getModel('retailcrm/settings', ['storeId' => $order->getStoreId()]); $config = Mage::getModel('retailcrm/settings', ['storeId' => $order->getStoreId()]);
$address = $order->getShippingAddress()->getData(); $address = $order->getShippingAddress()->getData();
$orderItems = $order->getItemsCollection() $orderItems = $order->getItemsCollection()
@ -127,7 +132,6 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
$shipping = $this->getShippingCode($order->getShippingMethod()); $shipping = $this->getShippingCode($order->getShippingMethod());
$preparedOrder = array( $preparedOrder = array(
'site' => $order->getStore()->getCode(),
'externalId' => $order->getRealOrderId(), 'externalId' => $order->getRealOrderId(),
'number' => $order->getRealOrderId(), 'number' => $order->getRealOrderId(),
'createdAt' => Mage::getModel('core/date')->date(), 'createdAt' => Mage::getModel('core/date')->date(),
@ -165,7 +169,6 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
) )
); );
if (trim($preparedOrder['delivery']['code']) == ''){ if (trim($preparedOrder['delivery']['code']) == ''){
unset($preparedOrder['delivery']['code']); unset($preparedOrder['delivery']['code']);
} }
@ -188,12 +191,12 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
} }
} }
$preparedOrder = Mage::helper('retailcrm')->filterRecursive($preparedOrder); $preparedOrder = $helper->filterRecursive($preparedOrder);
Mage::log($preparedOrder, null, 'retailcrmCreatePreparedOrder.log', true); Mage::log($preparedOrder, null, 'retailcrmCreatePreparedOrder.log', true);
try { try {
$response = $this->_api->ordersCreate($preparedOrder); $response = $this->_api->ordersCreate($preparedOrder, $helper->getSite($order->getStore()));
if ($response->isSuccessful() && 201 === $response->getStatusCode()) { if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
Mage::log($response->id); Mage::log($response->id);
} else { } else {
@ -218,7 +221,7 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
{ {
$config = Mage::getStoreConfig('retailcrm'); $config = Mage::getStoreConfig('retailcrm');
$ordersId = explode(",", $config['load_order']['numberOrder']); $ordersId = explode(",", $config['load_order']['numberOrder']);
$orders = array(); $ordersSites = array();
$ordersList = Mage::getResourceModel('sales/order_collection') $ordersList = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*') ->addAttributeToSelect('*')
@ -249,17 +252,19 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
->load(); ->load();
foreach ($ordersList as $order) { foreach ($ordersList as $order) {
$orders[] = $this->prepareOrder($order); $ordersSites[$order->getStore()->getId()][] = $this->prepareOrder($order);
} }
foreach ($ordersSites as $storeId => $orders) {
$chunked = array_chunk($orders, 50); $chunked = array_chunk($orders, 50);
unset($orders); unset($orders);
foreach ($chunked as $chunk) { foreach ($chunked as $chunk) {
$this->_api->ordersUpload($chunk); $this->_api->ordersUpload($chunk, Mage::helper('retailcrm')->getSite($storeId));
time_nanosleep(0, 250000000); time_nanosleep(0, 250000000);
} }
unset($chunked); unset($chunked);
}
return true; return true;
@ -275,7 +280,7 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
*/ */
public function ordersExport() public function ordersExport()
{ {
$orders = array(); $ordersSites = array();
$ordersList = Mage::getResourceModel('sales/order_collection') $ordersList = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*') ->addAttributeToSelect('*')
->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left') ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
@ -304,17 +309,19 @@ class Retailcrm_Retailcrm_Model_Order extends Retailcrm_Retailcrm_Model_Exchange
->load(); ->load();
foreach ($ordersList as $order) { foreach ($ordersList as $order) {
$orders[] = $this->prepareOrder($order); $ordersSites[$order->getStore()->getId()][] = $this->prepareOrder($order);
} }
foreach ($ordersSites as $storeId => $orders) {
$chunked = array_chunk($orders, 50); $chunked = array_chunk($orders, 50);
unset($orders); unset($orders);
foreach ($chunked as $chunk) { foreach ($chunked as $chunk) {
$this->_api->ordersUpload($chunk); $this->_api->ordersUpload($chunk, Mage::helper('retailcrm')->getSite($storeId));
time_nanosleep(0, 250000000); time_nanosleep(0, 250000000);
} }
unset($chunked); unset($chunked);
}
return true; return true;
} }

View File

@ -57,6 +57,7 @@ SOFTWARE.
<show_in_website>1</show_in_website> <show_in_website>1</show_in_website>
<show_in_store>1</show_in_store> <show_in_store>1</show_in_store>
<tooltip><![CDATA[https://<i><b>YourCrmName</b></i>.retailcrm.ru]]></tooltip> <tooltip><![CDATA[https://<i><b>YourCrmName</b></i>.retailcrm.ru]]></tooltip>
<backend_model>retailcrm_retailcrm_block_adminhtml_system_config_backend_api_url</backend_model>
</api_url> </api_url>
<api_key translate="label comment"> <api_key translate="label comment">
<label>API Key</label> <label>API Key</label>
@ -66,6 +67,7 @@ SOFTWARE.
<show_in_website>1</show_in_website> <show_in_website>1</show_in_website>
<show_in_store>1</show_in_store> <show_in_store>1</show_in_store>
<tooltip><![CDATA[To generate an API Key, log in to RetailCRM then select Admin > Integration > API Keys]]></tooltip> <tooltip><![CDATA[To generate an API Key, log in to RetailCRM then select Admin > Integration > API Keys]]></tooltip>
<backend_model>retailcrm_retailcrm_block_adminhtml_system_config_backend_api_key</backend_model>
</api_key> </api_key>
</fields> </fields>
</general> </general>
@ -153,7 +155,26 @@ SOFTWARE.
</fields> </fields>
</load_order> </load_order>
<site translate="label comment" module="retailcrm">
<expanded>1</expanded>
<label>Site</label>
<frontend_type>text</frontend_type>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>16</sort_order>
<frontend_model>retailcrm/adminhtml_system_config_form_fieldset_site</frontend_model>
</site>
<sites translate="label comment" module="retailcrm">
<expanded>1</expanded>
<label>Sites</label>
<frontend_type>text</frontend_type>
<show_in_default>0</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<sort_order>17</sort_order>
<frontend_model>retailcrm/adminhtml_system_config_form_fieldset_sites</frontend_model>
</sites>
</groups> </groups>
</retailcrm> </retailcrm>
</sections> </sections>