1
0
mirror of synced 2024-11-22 13:06:07 +03:00

order status, order items

This commit is contained in:
Alex Lushpai 2015-09-24 15:58:17 +03:00
parent a0305e202e
commit f370e6d085
6 changed files with 78 additions and 184 deletions

View File

@ -61,7 +61,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Payment ex
{ {
$configData = $this->getConfigData(); $configData = $this->getConfigData();
$path = 'retailcrm/payment/'.$group->getId(); $path = 'retailcrm/payment/' . $group->getId();
if (isset($configData[$path])) { if (isset($configData[$path])) {
$data = $configData[$path]; $data = $configData[$path];
$inherit = false; $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( array(
'name' => 'groups[payment][fields]['.$group->getId().'][value]', 'name' => 'groups[payment][fields]['.$group->getId().'][value]',
'label' => Mage::getStoreConfig('payment/'.$group->getId().'/title'), 'label' => Mage::getStoreConfig('payment/'.$group->getId().'/title'),

View File

@ -1,87 +0,0 @@
<?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Paymentstatus 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) {
$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 .= '<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()
{
$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();
}
}

View File

@ -3,7 +3,6 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Shipping e
{ {
public function render(Varien_Data_Form_Element_Abstract $element) public function render(Varien_Data_Form_Element_Abstract $element)
{ {
Mage::getModel( "retailcrm/exchange" )->ordersHistory();
$html = $this->_getHeaderHtml($element); $html = $this->_getHeaderHtml($element);
if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) { 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(); $configData = $this->getConfigData();
$path = 'retailcrm/shipping/'.$group->getId(); $path = 'retailcrm/shipping/' . $group->getId();
if (isset($configData[$path])) { if (isset($configData[$path])) {
$data = $configData[$path]; $data = $configData[$path];
$inherit = false; $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( array(
'name' => 'groups[shipping][fields]['.$group->getId().'][value]', 'name' => 'groups[shipping][fields]['.$group->getId().'][value]',
'label' => Mage::getStoreConfig('carriers/'.$group->getId().'/title'), 'label' => Mage::getStoreConfig('carriers/'.$group->getId().'/title'),

View File

@ -1,46 +1,20 @@
<?php <?php
class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status extends Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status extends Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base
{ {
public function render(Varien_Data_Form_Element_Abstract $element) public function render(Varien_Data_Form_Element_Abstract $element)
{ {
$html = $this->_getHeaderHtml($element); $html = $this->_getHeaderHtml($element);
$warn = '
<div style="margin-left: 15px;">
<b><i>Please check your API Url & API Key</i></b>
</div>
';
if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) { 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) $statuses = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
{
if (preg_match("/state_/i", $key)) {
$label = implode(
' ',
$arr = array_map(
function($word) {
return ucfirst($word);
},
explode('_', $value)
)
);
$values[] = array('code' => $value, 'name' => $label); foreach ($statuses as $status) {
} $html .= $this->_getFieldHtml($element, $status);
} }
if (!empty($values)) {
foreach ($values as $group) {
$html.= $this->_getFieldHtml($element, $group);
}
}
} else { } else {
$html .= $warn; $html .= '<div style="margin-left: 15px;"><b><i>Please check your API Url & API Key</i></b></div>';
} }
$html .= $this->_getFooterHtml($element); $html .= $this->_getFooterHtml($element);
@ -51,9 +25,7 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
protected function _getFieldRenderer() protected function _getFieldRenderer()
{ {
if (empty($this->_fieldRenderer)) { if (empty($this->_fieldRenderer)) {
$this->_fieldRenderer = Mage::getBlockSingleton( $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
'adminhtml/system_config_form_field'
);
} }
return $this->_fieldRenderer; return $this->_fieldRenderer;
} }
@ -63,36 +35,26 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
*/ */
protected function _getValues() protected function _getValues()
{ {
$client = Mage::getModel( if(!empty($this->_apiUrl) && !empty($this->_apiKey) && $this->_isCredentialCorrect) {
'retailcrm/ApiClient', $client = Mage::getModel(
array( 'retailcrm/ApiClient',
'url' => $this->_apiUrl, array('url' => $this->_apiUrl, 'key' => $this->_apiKey, 'site' => null)
'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 ($statuses->isSuccessful() && !empty($statuses)) {
foreach ($statuses['statuses'] as $status) { try {
$this->_values[] = array( $statuses = $client->statusesList();
'label' => Mage::helper('adminhtml') } catch (Retailcrm_Retailcrm_Model_Exception_CurlException $e) {
->__($status['name']), Mage::log($e->getMessage());
'value' => $status['code'] }
);
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; return $this->_values;
@ -102,24 +64,22 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Status ext
{ {
$configData = $this->getConfigData(); $configData = $this->getConfigData();
$path = 'retailcrm/status/'.$group['code']; $path = 'retailcrm/status/' . $group['status'];
if (isset($configData[$path])) { if (isset($configData[$path])) {
$data = $configData[$path]; $data = $configData[$path];
$inherit = false; $inherit = false;
} else { } else {
$data = (int) (string) $this->getForm() $data = (int)(string)$this->getForm()->getConfigRoot()->descend($path);
->getConfigRoot()->descend($path);
$inherit = true; $inherit = true;
} }
$field = $fieldset->addField($group['code'], 'select', $field = $fieldset->addField('status_' . $group['status'], 'select',
array( array(
'name' => 'groups[status][fields]['.$group['code'].'][value]', 'name' => 'groups[status][fields]['.$group['status'].'][value]',
'label' => $group['name'], 'label' => $group['label'],
'value' => $data, 'value' => $data,
'values' => $this->_getValues(), 'values' => $this->_getValues(),
'inherit' => $inherit, 'inherit' => $inherit,
'can_use_default_value' => 1, 'can_use_default_value' => 1,
'can_use_website_value' => 1 'can_use_website_value' => 1
))->setRenderer($this->_getFieldRenderer()); ))->setRenderer($this->_getFieldRenderer());

View File

@ -30,23 +30,56 @@ class Retailcrm_Retailcrm_Model_Exchange
$this->_config = Mage::getStoreConfig('retailcrm', $order->getStoreId()); $this->_config = Mage::getStoreConfig('retailcrm', $order->getStoreId());
$statuses = array_flip(array_filter($this->_config['status'])); $statuses = array_flip(array_filter($this->_config['status']));
$paymentsStatuses = array_flip(array_filter($this->_config['paymentstatus']));
$payments = array_filter($this->_config['payment']); $payments = array_filter($this->_config['payment']);
$shippings = array_filter($this->_config['shipping']); $shippings = array_filter($this->_config['shipping']);
$address = $order->getShippingAddress()->getData(); $address = $order->getShippingAddress()->getData();
$orderItems = $order->getItemsCollection(); $orderItems = $order->getAllItems();
$simpleItems = array();
$confItems = array();
foreach ($orderItems as $item) {
if ($item->getProductType() == 'simple') {
$simpleItems[] = $item;
} else {
$confItems[$item->getData('item_id')] = $item;
}
}
$items = array(); $items = array();
foreach ($orderItems as $item){ foreach ($simpleItems as $item) {
$items[] = array(
$product = array(
'productId' => $item->product_id, 'productId' => $item->product_id,
'initialPrice' => $item->getPrice(),
'taxPrice' => $item->getPriceInclTax(),
'productName' => $item->getName(), 'productName' => $item->getName(),
'quantity' => (int) $item->getData('qty_ordered') '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( $customer = array(
@ -74,8 +107,7 @@ class Retailcrm_Retailcrm_Model_Exchange
'email' => $order->getCustomerEmail(), 'email' => $order->getCustomerEmail(),
'phone' => $address['telephone'], 'phone' => $address['telephone'],
'paymentType' => $payments[$order->getPayment()->getMethodInstance()->getCode()], 'paymentType' => $payments[$order->getPayment()->getMethodInstance()->getCode()],
//'paymentStatus' => $paymentsStatuses[$order->getStatus()], 'status' => $statuses[$order->getStatus()],
//'status' => $statuses[$order->getStatus()],
'discount' => abs($order->getDiscountAmount()), 'discount' => abs($order->getDiscountAmount()),
'items' => $items, 'items' => $items,
'delivery' => array( 'delivery' => array(

View File

@ -89,21 +89,11 @@ SOFTWARE.
<show_in_store>1</show_in_store> <show_in_store>1</show_in_store>
<frontend_model>retailcrm/adminhtml_system_config_form_fieldset_payment</frontend_model> <frontend_model>retailcrm/adminhtml_system_config_form_fieldset_payment</frontend_model>
</payment> </payment>
<payment_status translate="label comment" module="retailcrm">
<expanded>0</expanded>
<label>Payment Information</label>
<frontend_type>text</frontend_type>
<sort_order>13</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_model>retailcrm/adminhtml_system_config_form_fieldset_paymentstatus</frontend_model>
</payment_status>
<status translate="label comment" module="retailcrm"> <status translate="label comment" module="retailcrm">
<expanded>0</expanded> <expanded>0</expanded>
<label>Order Statuses</label> <label>Order Statuses</label>
<frontend_type>text</frontend_type> <frontend_type>text</frontend_type>
<sort_order>14</sort_order> <sort_order>13</sort_order>
<show_in_default>1</show_in_default> <show_in_default>1</show_in_default>
<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>