diff --git a/README.md b/README.md index ab46981..5b2d87b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -# Magento RetailCRM module -Модуль Magento интеграции с RetailCRM +Magento module +============== + +Magento module for interaction with [RetailCRM](http://www.retailcrm.ru) through [REST API](http://retailcrm.ru/docs/Разработчики). + +Module allows: + +* Exchange the orders with retailCRM +* Configure relations between dictionaries of RetailCRM and Magento (statuses, payments, delivery types and etc) +* Generate [ICML](http://docs.retailcrm.ru/index.php?n=Разработчики.ФорматICML) (Intaro Markup Language) for catalog loading by RetailCRM + diff --git a/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php b/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php index 9b7eb44..f6b4e78 100644 --- a/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php +++ b/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php @@ -27,12 +27,17 @@ class Retailcrm_Retailcrm_Model_Exchange */ public function ordersCreate($order) { + $this->_config = Mage::getStoreConfig('retailcrm', $order->getStoreId()); $statuses = array_flip(array_filter($this->_config['status'])); $payments = array_filter($this->_config['payment']); $shippings = array_filter($this->_config['shipping']); + $shipment = $order->getShippingMethod(); + $shipment = explode('_', $shipment); + $shipment = $shipment[0]; + $address = $order->getShippingAddress()->getData(); $orderItems = $order->getAllItems(); @@ -48,7 +53,7 @@ class Retailcrm_Retailcrm_Model_Exchange } $items = array(); - + foreach ($simpleItems as $item) { $product = array( @@ -56,29 +61,29 @@ class Retailcrm_Retailcrm_Model_Exchange 'productName' => $item->getName(), 'quantity' => (int) $item->getData('qty_ordered') ); - + if ($item->getData('parent_item_id')) { $product['initialPrice'] = $confItems[$item->getData('parent_item_id')]->getPrice(); - + /*if ($confItems[$item->getData('parent_item_id')]->getDiscountAmount() > 0) { $product['discount'] = $confItems[$item->getData('parent_item_id')]->getDiscountAmount(); } - + if ($confItems[$item->getData('parent_item_id')]->getDiscountPercent() > 0) { $product['discountPercent'] = $confItems[$item->getData('parent_item_id')]->getDiscountPercent(); }*/ } else { $product['initialPrice'] = $item->getPrice(); - + /*if ($item->getDiscountAmount() > 0) { $product['discount'] = $item->getDiscountAmount(); } - + if ($item->getDiscountPercent() > 0) { $product['discountPercent'] = $item->getDiscountPercent(); }*/ } - + $items[] = $product; } @@ -95,6 +100,7 @@ class Retailcrm_Retailcrm_Model_Exchange $customerId = $this->setCustomerId($customer); unset($customer); + $comment = $order->getStatusHistoryCollection()->getFirstItem(); $preparedOrder = array( 'site' => $order->getStore()->getCode(), 'externalId' => $order->getId(), @@ -110,8 +116,9 @@ class Retailcrm_Retailcrm_Model_Exchange 'status' => $statuses[$order->getStatus()], 'discount' => abs($order->getDiscountAmount()), 'items' => $items, + 'customerComment' => $comment->getComment(), 'delivery' => array( - 'code' => $shippings[$order->getShippingMethod()], + 'code' => $shippings[$shipment], 'cost' => $order->getShippingAmount(), 'address' => array( 'index' => $address['postcode'],