diff --git a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Payment.php b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Payment.php
index cc082a5..f487356 100644
--- a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Payment.php
+++ b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Payment.php
@@ -61,7 +61,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Payment ex
{
$configData = $this->getConfigData();
- $path = 'retailcrm/payment/'.$group->getId();
+ $path = 'retailcrm/payment/' . $group->getId();
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
@@ -71,7 +71,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Payment ex
}
- $field = $fieldset->addField($group->getId(), 'select',
+ $field = $fieldset->addField('payment_' . $group->getId(), 'select',
array(
'name' => 'groups[payment][fields]['.$group->getId().'][value]',
'label' => Mage::getStoreConfig('payment/'.$group->getId().'/title'),
diff --git a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Paymentstatus.php b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Paymentstatus.php
deleted file mode 100644
index 8f0d4b9..0000000
--- a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Paymentstatus.php
+++ /dev/null
@@ -1,87 +0,0 @@
-_getHeaderHtml($element);
-
- if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
-
- $client = Mage::getModel(
- 'retailcrm/ApiClient',
- array('url' => $this->_apiUrl, 'key' => $this->_apiKey, 'site' => null)
- );
-
- try {
- $paymentStatuses = $client->paymentStatusesList();
- } catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
- Mage::log($e->getMessage());
- }
-
- if ($paymentStatuses->isSuccessful() && !empty($paymentStatuses)) {
- foreach ($paymentStatuses['paymentStatuses'] as $group) {
- $html.= $this->_getFieldHtml($element, $group);
- }
- }
- } else {
- $html .= '
Please check your API Url & API Key
';
- }
-
- $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()
- {
- $values = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
- if (empty($this->_values)) {
- $this->_values[] = array('label'=>Mage::helper('adminhtml')->__('===Select status==='), 'value'=>'');
- foreach ($values as $value) {
- $this->_values[] = array('label'=>Mage::helper('adminhtml')->__($value['label']), 'value'=>$value['status']);
- }
- }
-
- return $this->_values;
- }
-
- protected function _getFieldHtml($fieldset, $group)
- {
- $configData = $this->getConfigData();
-
- $path = 'retailcrm/paymentstatus/'.$group['code'];
-
- if (isset($configData[$path])) {
- $data = $configData[$path];
- $inherit = false;
- } else {
- $data = (int)(string)$this->getForm()->getConfigRoot()->descend($path);
- $inherit = true;
- }
-
- $field = $fieldset->addField($group['code'], 'select',
- array(
- 'name' => 'groups[paymentstatus][fields]['.$group['code'].'][value]',
- 'label' => $group['name'],
- 'value' => $data,
- 'values' => $this->_getValues(),
- 'inherit' => $inherit,
- 'can_use_default_value' => 1,
- 'can_use_website_value' => 1
- ))->setRenderer($this->_getFieldRenderer());
-
- return $field->toHtml();
- }
-}
diff --git a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Shipping.php b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Shipping.php
index d6c7858..20eea5a 100644
--- a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Shipping.php
+++ b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Shipping.php
@@ -3,7 +3,6 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Shipping e
{
public function render(Varien_Data_Form_Element_Abstract $element)
{
- Mage::getModel( "retailcrm/exchange" )->ordersHistory();
$html = $this->_getHeaderHtml($element);
if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
@@ -63,7 +62,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Shipping e
{
$configData = $this->getConfigData();
- $path = 'retailcrm/shipping/'.$group->getId();
+ $path = 'retailcrm/shipping/' . $group->getId();
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
@@ -73,7 +72,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Shipping e
}
- $field = $fieldset->addField($group->getId(), 'select',
+ $field = $fieldset->addField('shipping_' . $group->getId(), 'select',
array(
'name' => 'groups[shipping][fields]['.$group->getId().'][value]',
'label' => Mage::getStoreConfig('carriers/'.$group->getId().'/title'),
diff --git a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Status.php b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Status.php
index f14e104..50e8187 100644
--- a/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Status.php
+++ b/app/code/community/Retailcrm/Retailcrm/Block/Adminhtml/System/Config/Form/Fieldset/Status.php
@@ -1,46 +1,20 @@
_getHeaderHtml($element);
- $warn = '
-
- Please check your API Url & API Key
-
- ';
if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
- $orderEntity = Mage::getModel('sales/order');
- $reflection = new ReflectionClass($orderEntity);
- $constants = $reflection->getConstants();
- $values = array();
- foreach ($constants as $key => $value)
- {
- if (preg_match("/state_/i", $key)) {
- $label = implode(
- ' ',
- $arr = array_map(
- function($word) {
- return ucfirst($word);
- },
- explode('_', $value)
- )
- );
-
- $values[] = array('code' => $value, 'name' => $label);
- }
+ $statuses = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
+
+ foreach ($statuses as $status) {
+ $html .= $this->_getFieldHtml($element, $status);
}
-
- if (!empty($values)) {
- foreach ($values as $group) {
- $html.= $this->_getFieldHtml($element, $group);
- }
- }
-
} else {
- $html .= $warn;
+ $html .= 'Please check your API Url & API Key
';
}
$html .= $this->_getFooterHtml($element);
@@ -51,9 +25,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
protected function _getFieldRenderer()
{
if (empty($this->_fieldRenderer)) {
- $this->_fieldRenderer = Mage::getBlockSingleton(
- 'adminhtml/system_config_form_field'
- );
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
}
return $this->_fieldRenderer;
}
@@ -63,36 +35,26 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
*/
protected function _getValues()
{
- $client = Mage::getModel(
- 'retailcrm/ApiClient',
- array(
- 'url' => $this->_apiUrl,
- 'key' => $this->_apiKey,
- 'site' => null
- )
- );
-
- try {
- $statuses = $client->statusesList();
- } catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
- Mage::log($e->getMessage());
- }
-
- if (empty($this->_values)) {
- $this->_values[] = array(
- 'label' => Mage::helper('adminhtml')
- ->__('===Select status==='),
- 'value' => ''
+ if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
+ $client = Mage::getModel(
+ 'retailcrm/ApiClient',
+ array('url' => $this->_apiUrl, 'key' => $this->_apiKey, 'site' => null)
);
- if ($statuses->isSuccessful() && !empty($statuses)) {
- foreach ($statuses['statuses'] as $status) {
- $this->_values[] = array(
- 'label' => Mage::helper('adminhtml')
- ->__($status['name']),
- 'value' => $status['code']
- );
+
+ try {
+ $statuses = $client->statusesList();
+ } catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
+ Mage::log($e->getMessage());
+ }
+
+ if ($statuses->isSuccessful()) {
+ if (empty($this->_values)) {
+ foreach ($statuses['statuses'] as $status) {
+ $this->_values[] = array('label'=>Mage::helper('adminhtml')->__($status['name']), 'value'=>$status['code']);
+ }
}
}
+
}
return $this->_values;
@@ -102,24 +64,22 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
{
$configData = $this->getConfigData();
- $path = 'retailcrm/status/'.$group['code'];
-
+ $path = 'retailcrm/status/' . $group['status'];
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
} else {
- $data = (int) (string) $this->getForm()
- ->getConfigRoot()->descend($path);
+ $data = (int)(string)$this->getForm()->getConfigRoot()->descend($path);
$inherit = true;
}
- $field = $fieldset->addField($group['code'], 'select',
+ $field = $fieldset->addField('status_' . $group['status'], 'select',
array(
- 'name' => 'groups[status][fields]['.$group['code'].'][value]',
- 'label' => $group['name'],
- 'value' => $data,
- 'values' => $this->_getValues(),
- 'inherit' => $inherit,
+ 'name' => 'groups[status][fields]['.$group['status'].'][value]',
+ 'label' => $group['label'],
+ 'value' => $data,
+ 'values' => $this->_getValues(),
+ 'inherit' => $inherit,
'can_use_default_value' => 1,
'can_use_website_value' => 1
))->setRenderer($this->_getFieldRenderer());
diff --git a/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php b/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php
index e7963e0..9b7eb44 100644
--- a/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php
+++ b/app/code/community/Retailcrm/Retailcrm/Model/Exchange.php
@@ -30,23 +30,56 @@ class Retailcrm_Retailcrm_Model_Exchange
$this->_config = Mage::getStoreConfig('retailcrm', $order->getStoreId());
$statuses = array_flip(array_filter($this->_config['status']));
- $paymentsStatuses = array_flip(array_filter($this->_config['paymentstatus']));
$payments = array_filter($this->_config['payment']);
$shippings = array_filter($this->_config['shipping']);
$address = $order->getShippingAddress()->getData();
- $orderItems = $order->getItemsCollection();
- $items = array();
+ $orderItems = $order->getAllItems();
+ $simpleItems = array();
+ $confItems = array();
- foreach ($orderItems as $item){
- $items[] = array(
+ foreach ($orderItems as $item) {
+ if ($item->getProductType() == 'simple') {
+ $simpleItems[] = $item;
+ } else {
+ $confItems[$item->getData('item_id')] = $item;
+ }
+ }
+
+ $items = array();
+
+ foreach ($simpleItems as $item) {
+
+ $product = array(
'productId' => $item->product_id,
- 'initialPrice' => $item->getPrice(),
- 'taxPrice' => $item->getPriceInclTax(),
'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;
}
$customer = array(
@@ -74,8 +107,7 @@ class Retailcrm_Retailcrm_Model_Exchange
'email' => $order->getCustomerEmail(),
'phone' => $address['telephone'],
'paymentType' => $payments[$order->getPayment()->getMethodInstance()->getCode()],
- //'paymentStatus' => $paymentsStatuses[$order->getStatus()],
- //'status' => $statuses[$order->getStatus()],
+ 'status' => $statuses[$order->getStatus()],
'discount' => abs($order->getDiscountAmount()),
'items' => $items,
'delivery' => array(
diff --git a/app/code/community/Retailcrm/Retailcrm/etc/system.xml b/app/code/community/Retailcrm/Retailcrm/etc/system.xml
index 9e89574..3b34d6a 100644
--- a/app/code/community/Retailcrm/Retailcrm/etc/system.xml
+++ b/app/code/community/Retailcrm/Retailcrm/etc/system.xml
@@ -89,21 +89,11 @@ SOFTWARE.
1
retailcrm/adminhtml_system_config_form_fieldset_payment
-
- 0
-
- text
- 13
- 1
- 1
- 1
- retailcrm/adminhtml_system_config_form_fieldset_paymentstatus
-
0
text
- 14
+ 13
1
1
1