CsuMarketSystem_OpteMais - Version 1.1.0

Version Notes

- Integração de todo Catálogo (Produtos, Categorias, Atributos e Imagens);
- Criação de Campanhas;
- Integração de Pedidos feitos no ambiente da Opte+;

Download this release

Release Info

Developer csumarketsystem
Extension CsuMarketSystem_OpteMais
Version 1.1.0
Comparing to
See all releases


Version 1.1.0

Files changed (48) hide show
  1. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign.php +26 -0
  2. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit.php +55 -0
  3. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Form.php +31 -0
  4. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tab/Form.php +105 -0
  5. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tab/Product/Grid.php +132 -0
  6. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tabs.php +44 -0
  7. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Grid.php +104 -0
  8. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Item.php +33 -0
  9. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Item/Edit/Form.php +172 -0
  10. app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Paymentmethod.php +140 -0
  11. app/code/community/CsuMarketSystem/OpteMais/Block/Payment/Info/Modelc.php +21 -0
  12. app/code/community/CsuMarketSystem/OpteMais/Helper/Data.php +101 -0
  13. app/code/community/CsuMarketSystem/OpteMais/Model/Abstract.php +26 -0
  14. app/code/community/CsuMarketSystem/OpteMais/Model/Auth/Adapter/Http.php +45 -0
  15. app/code/community/CsuMarketSystem/OpteMais/Model/Campaign.php +142 -0
  16. app/code/community/CsuMarketSystem/OpteMais/Model/Campaign/Item.php +48 -0
  17. app/code/community/CsuMarketSystem/OpteMais/Model/Estimate/Rate.php +269 -0
  18. app/code/community/CsuMarketSystem/OpteMais/Model/Observer.php +50 -0
  19. app/code/community/CsuMarketSystem/OpteMais/Model/Order.php +782 -0
  20. app/code/community/CsuMarketSystem/OpteMais/Model/Payment/Modelc.php +24 -0
  21. app/code/community/CsuMarketSystem/OpteMais/Model/Product.php +481 -0
  22. app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign.php +22 -0
  23. app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Collection.php +23 -0
  24. app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Item.php +35 -0
  25. app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Item/Collection.php +23 -0
  26. app/code/community/CsuMarketSystem/OpteMais/Model/Response.php +57 -0
  27. app/code/community/CsuMarketSystem/OpteMais/Model/Shipping.php +135 -0
  28. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Attributes.php +44 -0
  29. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Campaign/Actions.php +29 -0
  30. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Campaign/Statuses.php +28 -0
  31. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Customer/Attributes.php +43 -0
  32. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Select/Attributes.php +64 -0
  33. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Shipping/Pricetype.php +28 -0
  34. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Shippingmethods.php +36 -0
  35. app/code/community/CsuMarketSystem/OpteMais/Model/Source/Stores.php +30 -0
  36. app/code/community/CsuMarketSystem/OpteMais/controllers/Adminhtml/Optemais/CampaignController.php +276 -0
  37. app/code/community/CsuMarketSystem/OpteMais/controllers/Api/OrderController.php +145 -0
  38. app/code/community/CsuMarketSystem/OpteMais/controllers/Api/ProductController.php +80 -0
  39. app/code/community/CsuMarketSystem/OpteMais/controllers/Api/ShippingController.php +45 -0
  40. app/code/community/CsuMarketSystem/OpteMais/controllers/ApiController.php +69 -0
  41. app/code/community/CsuMarketSystem/OpteMais/etc/adminhtml.xml +59 -0
  42. app/code/community/CsuMarketSystem/OpteMais/etc/config.xml +183 -0
  43. app/code/community/CsuMarketSystem/OpteMais/etc/system.xml +473 -0
  44. app/code/community/CsuMarketSystem/OpteMais/sql/optemais_setup/mysql4-install-1.0.0.php +148 -0
  45. app/code/community/CsuMarketSystem/OpteMais/sql/optemais_setup/mysql4-upgrade-1.0.0-1.1.0.php +21 -0
  46. app/design/adminhtml/default/default/template/optemais/payment/info/modelc.phtml +8 -0
  47. app/etc/modules/CsuMarketSystem_OpteMais.xml +23 -0
  48. package.xml +22 -0
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign extends Mage_Adminhtml_Block_Widget_Grid_Container
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ $this->_controller = 'adminhtml_campaign';
20
+ $this->_blockGroup = 'optemais';
21
+ $this->_headerText = Mage::helper('optemais')->__('Gerenciar Campanhas OPTe+');
22
+ $this->_addButtonLabel = Mage::helper('optemais')->__('Adicionar Campanha');
23
+ parent::__construct();
24
+ }
25
+
26
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ $this->_objectId = 'entity_id';
22
+ $this->_blockGroup = 'optemais';
23
+ $this->_controller = 'adminhtml_campaign';
24
+
25
+ $this->_updateButton('save', 'label', Mage::helper('adminhtml')->__('Save'));
26
+ $this->_updateButton('delete', 'label', Mage::helper('adminhtml')->__('Delete'));
27
+
28
+ $this->_addButton(
29
+ 'saveandcontinue', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Save and Continue Edit'),
31
+ 'onclick' => 'saveAndContinueEdit()',
32
+ 'class' => 'save',
33
+ ), -100
34
+ );
35
+
36
+ $this->_formScripts[]
37
+ = "
38
+ function saveAndContinueEdit(){
39
+ editForm.submit($('edit_form').action+'back/edit/');
40
+ }
41
+ ";
42
+ }
43
+
44
+ public function getHeaderText()
45
+ {
46
+ /** @var $campaign */
47
+ $campaign = Mage::registry('optemais_campaign');
48
+ if ($campaign && $campaign->getId()) {
49
+ return Mage::helper('optemais')->__("Editar Campanha '%s'", self::escapeHtml($campaign->getName()));
50
+ } else {
51
+ return Mage::helper('optemais')->__('Adicionar Campanha');
52
+ }
53
+ }
54
+
55
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Form.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
15
+ {
16
+ protected function _prepareForm()
17
+ {
18
+ $form = new Varien_Data_Form(
19
+ array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
22
+ 'method' => 'post',
23
+ 'enctype' => 'multipart/form-data'
24
+ )
25
+ );
26
+ $form->setUseContainer(true);
27
+ $this->setForm($form);
28
+ return parent::_prepareForm();
29
+ }
30
+
31
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tab/Form.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
15
+ {
16
+
17
+ protected function _prepareForm()
18
+ {
19
+
20
+ $form = new Varien_Data_Form();
21
+
22
+ $fieldset = $form->addFieldset('campaign_form', array('legend' => Mage::helper('optemais')->__('Informação da Campanha')));
23
+
24
+ $fieldset->addField(
25
+ 'name', 'text', array(
26
+ 'name' => 'name',
27
+ 'label' => Mage::helper('optemais')->__('Nome'),
28
+ 'title' => Mage::helper('optemais')->__('Nome'),
29
+ 'required' => true,
30
+ )
31
+ );
32
+
33
+ $fieldset->addField(
34
+ 'description', 'textarea', array(
35
+ 'name' => 'description',
36
+ 'label' => Mage::helper('optemais')->__('Descrição'),
37
+ 'title' => Mage::helper('optemais')->__('Descrição'),
38
+ 'style' => 'height: 100px;',
39
+ )
40
+ );
41
+
42
+ $fieldset->addField(
43
+ 'freight_discount', 'text', array(
44
+ 'name' => 'freight_discount',
45
+ 'label' => Mage::helper('optemais')->__('Desconto no Frete'),
46
+ 'title' => Mage::helper('optemais')->__('Desconto no Frete'),
47
+ 'note' => Mage::helper('optemais')->__('<small>Percentual de desconto aplicado ao frete.</small>'),
48
+ )
49
+ );
50
+
51
+ $fieldset->addField(
52
+ 'is_active', 'select', array(
53
+ 'label' => Mage::helper('optemais')->__('Status'),
54
+ 'title' => Mage::helper('optemais')->__('Status'),
55
+ 'name' => 'is_active',
56
+ 'required' => true,
57
+ 'options' => Mage::getModel('optemais/source_campaign_statuses')->getOptions()
58
+ )
59
+ );
60
+
61
+ $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
62
+ $fieldset->addField(
63
+ 'from_date', 'date', array(
64
+ 'name' => 'from_date',
65
+ 'label' => Mage::helper('optemais')->__('Iniciar Em'),
66
+ 'title' => Mage::helper('optemais')->__('Iniciar Em'),
67
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
68
+ 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
69
+ 'format' => $dateFormatIso,
70
+ 'note' => Mage::helper('optemais')->__('<small>Data inicial de validade para a Campanha.</small>'),
71
+
72
+ )
73
+ );
74
+ $fieldset->addField(
75
+ 'to_date', 'date', array(
76
+ 'name' => 'to_date',
77
+ 'label' => Mage::helper('optemais')->__('Finalizar Em'),
78
+ 'title' => Mage::helper('optemais')->__('Finalizar Em'),
79
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
80
+ 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
81
+ 'format' => $dateFormatIso,
82
+ 'note' => Mage::helper('optemais')->__('<small>Data final de validade para a Campanha.</small>'),
83
+ )
84
+ );
85
+
86
+ $field = $fieldset->addField(
87
+ 'payment_methods', 'text', array(
88
+ 'name' => 'payment_methods',
89
+ 'label' => Mage::helper('optemais')->__('Métodos de Pagamento e Parcelamento'),
90
+ 'title' => Mage::helper('optemais')->__('Métodos de Pagamento e Parcelamento'),
91
+ 'required' => true,
92
+ )
93
+ );
94
+ $field->setRenderer($this->getLayout()->createBlock('optemais/adminhtml_paymentmethod'));
95
+
96
+ if (Mage::registry('optemais_campaign')) {
97
+
98
+ $form->setValues(Mage::registry('optemais_campaign')->getData());
99
+ }
100
+
101
+ $this->setForm($form);
102
+ return parent::_prepareForm();
103
+ }
104
+
105
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tab/Product/Grid.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Edit_Tab_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+ $this->setId('optemais_campaign_product_grid');
21
+ $this->setDefaultSort('entity_id');
22
+ $this->setDefaultDir('DESC');
23
+ $this->setSaveParametersInSession(true);
24
+ $this->setUseAjax(true);
25
+ }
26
+
27
+ protected function _prepareCollection()
28
+ {
29
+ $collection = Mage::getModel('optemais/campaign_item')->getCollection();
30
+ $productName = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'name');
31
+ $productSku = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'sku');
32
+ $collection->getSelect()
33
+ ->columns(
34
+ array(
35
+ 'product_name' => 'product_attribute_name.value',
36
+ 'product_sku' => 'product_attribute_sku.sku'
37
+ )
38
+ )
39
+ ->join(
40
+ array('product_attribute_name' => $productName->getBackendTable()),
41
+ 'main_table.product_id = product_attribute_name.entity_id',
42
+ array()
43
+ )
44
+ ->join(
45
+ array('product_attribute_sku' => $productSku->getBackendTable()),
46
+ 'main_table.product_id = product_attribute_sku.entity_id',
47
+ array()
48
+ )
49
+ ->where("product_attribute_name.attribute_id = ?", $productName->getId())
50
+ ->where("product_attribute_name.store_id = ?", Mage_Core_Model_App::ADMIN_STORE_ID)
51
+ ->where("main_table.campaign_id = ?", Mage::registry('optemais_campaign')->getId());
52
+ $this->setCollection($collection);
53
+ return parent::_prepareCollection();
54
+ }
55
+
56
+ protected function _getStore()
57
+ {
58
+ return Mage::app()->getStore();
59
+ }
60
+
61
+
62
+ protected function _prepareColumns()
63
+ {
64
+ $this->addColumn(
65
+ 'product_id', array(
66
+ 'header' => Mage::helper('optemais')->__('ID'),
67
+ 'align' => 'right',
68
+ 'index' => 'entity_id',
69
+ )
70
+ );
71
+
72
+ $this->addColumn(
73
+ 'product_sku', array(
74
+ 'header' => Mage::helper('optemais')->__('SKU'),
75
+ 'align' => 'left',
76
+ 'index' => 'product_sku',
77
+ 'filter_index' => 'product_attribute_sku.sku'
78
+ )
79
+ );
80
+
81
+ $this->addColumn(
82
+ 'product_name', array(
83
+ 'header' => Mage::helper('optemais')->__('Nome'),
84
+ 'align' => 'left',
85
+ 'index' => 'product_name',
86
+ 'filter_index' => 'product_attribute_name.value'
87
+ )
88
+ );
89
+
90
+ $store = $this->_getStore();
91
+ $this->addColumn(
92
+ 'price', array(
93
+ 'header' => Mage::helper('optemais')->__('Preço'),
94
+ 'type' => 'price',
95
+ 'index' => 'price',
96
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
97
+
98
+ )
99
+ );
100
+
101
+ $this->addColumn(
102
+ 'stock_qty', array(
103
+ 'header' => Mage::helper('optemais')->__('Estoque'),
104
+ 'type' => 'number',
105
+ 'index' => 'stock_qty'
106
+ )
107
+ );
108
+
109
+
110
+ return parent::_prepareColumns();
111
+ }
112
+
113
+ public function getGridUrl()
114
+ {
115
+ return $this->getUrl('*/*/productGrid', array('_current' => true));
116
+ }
117
+
118
+ protected function _prepareMassaction()
119
+ {
120
+ $this->setMassactionIdField('entity_id');
121
+ $this->getMassactionBlock()->setFormFieldName('product');
122
+ $this->getMassactionBlock()->addItem(
123
+ 'delete', array(
124
+ 'label' => Mage::helper('optemais')->__('Excluir'),
125
+ 'url' => $this->getUrl('*/*/massDeleteItem'),
126
+ 'confirm' => Mage::helper('optemais')->__('Você tem certeza?')
127
+ )
128
+ );
129
+ return $this;
130
+ }
131
+
132
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Edit/Tabs.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+ $this->setId('optemais_tabs');
21
+ $this->setDestElementId('edit_form');
22
+ $this->setTitle(Mage::helper('optemais')->__('Campanha'));
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->addTab(
28
+ 'form', array(
29
+ 'label' => Mage::helper('optemais')->__('Dados'),
30
+ 'alt' => Mage::helper('optemais')->__('Dados'),
31
+ 'content' => $this->getLayout()->createBlock('optemais/adminhtml_campaign_edit_tab_form')->toHtml(),
32
+ )
33
+ );
34
+ $this->addTab(
35
+ 'products', array(
36
+ 'label' => Mage::helper('optemais')->__('Produtos da Campanha'),
37
+ 'title' => Mage::helper('optemais')->__('Produtos da Campanha'),
38
+ 'content' => $this->getLayout()->createBlock('optemais/adminhtml_campaign_edit_tab_product_grid')->toHtml()
39
+ )
40
+ );
41
+ return parent::_beforeToHtml();
42
+ }
43
+
44
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Grid.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+ $this->setId('optemais_campaign_grid');
21
+ $this->setDefaultSort('entity_id');
22
+ $this->setDefaultDir('DESC');
23
+ $this->setSaveParametersInSession(true);
24
+ }
25
+
26
+ protected function _prepareCollection()
27
+ {
28
+ $collection = Mage::getModel('optemais/campaign')->getCollection();
29
+ $this->setCollection($collection);
30
+ return parent::_prepareCollection();
31
+ }
32
+
33
+ protected function _prepareColumns()
34
+ {
35
+ $this->addColumn(
36
+ 'entity_id', array(
37
+ 'header' => Mage::helper('optemais')->__('ID'),
38
+ 'align' => 'center',
39
+ 'width' => '30px',
40
+ 'index' => 'entity_id',
41
+ )
42
+ );
43
+
44
+ $this->addColumn(
45
+ 'nome', array(
46
+ 'header' => Mage::helper('optemais')->__('Nome'),
47
+ 'index' => 'name',
48
+ )
49
+ );
50
+
51
+ $this->addColumn(
52
+ 'is_active', array(
53
+ 'header' => Mage::helper('optemais')->__('Status'),
54
+ 'align' => 'left',
55
+ 'width' => '80px',
56
+ 'index' => 'is_active',
57
+ 'type' => 'options',
58
+ 'options' => Mage::getModel('optemais/source_campaign_statuses')->getOptions()
59
+ )
60
+ );
61
+ $this->addExportType('*/*/exportCsv', Mage::helper('optemais')->__('CSV'));
62
+ $this->addExportType('*/*/exportXml', Mage::helper('optemais')->__('XML'));
63
+ return parent::_prepareColumns();
64
+ }
65
+
66
+ protected function _prepareMassaction()
67
+ {
68
+ $this->setMassactionIdField('entity_id');
69
+ $this->getMassactionBlock()->setFormFieldName('campaign');
70
+
71
+ $this->getMassactionBlock()->addItem(
72
+ 'delete', array(
73
+ 'label' => Mage::helper('optemais')->__('Excluir'),
74
+ 'url' => $this->getUrl('*/*/massDelete'),
75
+ 'confirm' => Mage::helper('optemais')->__('Você tem certeza?')
76
+ )
77
+ );
78
+
79
+ $statuses = Mage::getModel('optemais/source_campaign_statuses')->getOptions();
80
+
81
+ $this->getMassactionBlock()->addItem(
82
+ 'status', array(
83
+ 'label' => Mage::helper('optemais')->__('Alterar Status'),
84
+ 'url' => $this->getUrl('*/*/massStatus', array('_current' => true)),
85
+ 'additional' => array(
86
+ 'visibility' => array(
87
+ 'name' => 'status',
88
+ 'type' => 'select',
89
+ 'class' => 'required-entry',
90
+ 'label' => Mage::helper('optemais')->__('Status'),
91
+ 'values' => $statuses
92
+ )
93
+ )
94
+ )
95
+ );
96
+ return $this;
97
+ }
98
+
99
+ public function getRowUrl($row)
100
+ {
101
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
102
+ }
103
+
104
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Item.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Item extends Mage_Adminhtml_Block_Widget_Form_Container
15
+ {
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+ $this->_objectId = 'entity_id';
21
+ $this->_blockGroup = 'optemais';
22
+ $this->_controller = 'adminhtml_campaign_item';
23
+ $this->_updateButton('save', 'label', Mage::helper('optemais')->__('Salvar'));
24
+ $this->_removeButton('delete');
25
+ $this->_removeButton('reset');
26
+ }
27
+
28
+ public function getHeaderText()
29
+ {
30
+ return Mage::helper('optemais')->__('Adicionar itens à Campanha');
31
+ }
32
+
33
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Campaign/Item/Edit/Form.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Campaign_Item_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
15
+ {
16
+
17
+ protected function _prepareForm()
18
+ {
19
+
20
+ $form = new Varien_Data_Form(
21
+ array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/*/confirmItems'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ )
27
+ );
28
+
29
+ $fieldsetAction = $form->addFieldset('campaign_item_form_action', array('legend' => Mage::helper('optemais')->__('Ação')));
30
+
31
+ $instructions = '<p><b>Para o ajuste dos valores, siga as recomendações abaixo:</b></p>';
32
+ $instructions .= '<li><b>Incremento</b>: Para aumentar o valor dos produtos em relação ao valor original (como está no cadastro), utilize o sinal de + antes do valor. <b>[Exemplo: +10.00]</b>.</li>';
33
+ $instructions .= '<li><b>Decremento</b>: Para reduzir o valor dos produtos em relação ao valor original, utilize o sinal de - antes do valor. <b>[Exemplo: -10.00]</b>.</li>';
34
+ $instructions .= '<li><b>Percentual</b>: Para operações com percentual, utilize o sinal % no final do valor. <b>[Exemplo: +10%]</b>.</li>';
35
+ $instructions .= '<li><b>Original</b>: Para manter os valores originais, ignorar os campos de ajustes (Preço e Estoque).</b></li>';
36
+
37
+ $fieldsetAction->addField(
38
+ 'action', 'select', array(
39
+ 'name' => 'action',
40
+ 'label' => Mage::helper('optemais')->__('Adicionar em'),
41
+ 'title' => Mage::helper('optemais')->__('Adicionar em'),
42
+ 'required' => true,
43
+ 'value' => '1',
44
+ 'onchange' => "changeAction(this)",
45
+ 'values' => Mage::getModel('optemais/source_campaign_actions')->getOptions(),
46
+ 'after_element_html' => '
47
+ <script type="text/javascript">
48
+ function changeAction(e) {
49
+ if (e.value == 2) {
50
+ $$(\'.new-campaign\').invoke(\'up\',\'tr\').invoke(\'hide\');
51
+ $(\'name\').removeClassName(\'required-entry\');
52
+ $(\'campaign\').addClassName(\'required-entry\');
53
+ $$(\'.existing-campaign\').invoke(\'up\',\'tr\').invoke(\'show\');
54
+ } else {
55
+ $$(\'.new-campaign\').invoke(\'up\',\'tr\').invoke(\'show\');
56
+ $$(\'.existing-campaign\').invoke(\'up\',\'tr\').invoke(\'hide\');
57
+ $(\'name\').addClassName(\'required-entry\');
58
+ $(\'campaign\').removeClassName(\'required-entry\');
59
+ }
60
+ }
61
+ document.observe("dom:loaded", function() {
62
+ $$(\'.existing-campaign\').invoke(\'up\',\'tr\').invoke(\'hide\');
63
+ $(\'campaign\').removeClassName(\'required-entry\');
64
+ $(\'campaign_item_form_values\').down().insert({before: \'' . $instructions . '\'});
65
+ });
66
+ </script>',
67
+ )
68
+ );
69
+
70
+ $fieldset = $form->addFieldset('campaign_item_form_new', array('legend' => Mage::helper('optemais')->__('Dados da Campanha')));
71
+
72
+ $fieldset->addField(
73
+ 'products', 'hidden', array(
74
+ 'name' => 'products',
75
+ 'value' => implode(',', $this->getRequest()->getParam('product'))
76
+ )
77
+ );
78
+
79
+ $fieldset->addField(
80
+ 'name', 'text', array(
81
+ 'name' => 'name',
82
+ 'label' => Mage::helper('optemais')->__('Nome'),
83
+ 'title' => Mage::helper('optemais')->__('Nome'),
84
+ 'required' => true,
85
+ 'class' => 'new-campaign'
86
+ )
87
+ );
88
+
89
+ $fieldset->addField(
90
+ 'description', 'textarea', array(
91
+ 'name' => 'description',
92
+ 'label' => Mage::helper('optemais')->__('Descrição'),
93
+ 'title' => Mage::helper('optemais')->__('Descrição'),
94
+ 'style' => 'height: 100px;',
95
+ 'class' => 'new-campaign'
96
+ )
97
+ );
98
+
99
+ $fieldset->addField(
100
+ 'is_active', 'select', array(
101
+ 'label' => Mage::helper('optemais')->__('Status'),
102
+ 'title' => Mage::helper('optemais')->__('Status'),
103
+ 'name' => 'is_active',
104
+ 'required' => true,
105
+ 'options' => Mage::getModel('optemais/source_campaign_statuses')->getOptions(),
106
+ 'class' => 'new-campaign',
107
+ 'value' => CsuMarketSystem_OpteMais_Model_Source_Campaign_Statuses::STATE_ACTIVE
108
+ )
109
+ );
110
+
111
+ $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
112
+ $fieldset->addField(
113
+ 'from_date', 'date', array(
114
+ 'name' => 'from_date',
115
+ 'label' => Mage::helper('optemais')->__('Iniciar Em'),
116
+ 'title' => Mage::helper('optemais')->__('Iniciar Em'),
117
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
118
+ 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
119
+ 'format' => $dateFormatIso,
120
+ 'class' => 'new-campaign',
121
+ )
122
+ );
123
+ $fieldset->addField(
124
+ 'to_date', 'date', array(
125
+ 'name' => 'to_date',
126
+ 'label' => Mage::helper('optemais')->__('Finalizar Em'),
127
+ 'title' => Mage::helper('optemais')->__('Finalizar Em'),
128
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
129
+ 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
130
+ 'format' => $dateFormatIso,
131
+ 'class' => 'new-campaign'
132
+ )
133
+ );
134
+
135
+ $fieldset->addField(
136
+ 'campaign', 'select', array(
137
+ 'label' => Mage::helper('optemais')->__('Campanha'),
138
+ 'title' => Mage::helper('optemais')->__('Campanha'),
139
+ 'name' => 'campaign',
140
+ 'required' => true,
141
+ 'options' => Mage::getModel('optemais/campaign')->getToOptions(true),
142
+ 'class' => 'existing-campaign',
143
+ 'note' => Mage::helper('optemais')->__('<small>Somente campanhas ativas</small>'),
144
+ )
145
+ );
146
+
147
+ $fieldsetValues = $form->addFieldset('campaign_item_form_values', array('legend' => Mage::helper('optemais')->__('Ajuste de Valores do Produto')));
148
+
149
+ $fieldsetValues->addField(
150
+ 'price', 'text', array(
151
+ 'name' => 'price',
152
+ 'label' => Mage::helper('optemais')->__('Preço'),
153
+ 'title' => Mage::helper('optemais')->__('Preço'),
154
+ 'style' => 'width: 90px;',
155
+ )
156
+ );
157
+
158
+ $fieldsetValues->addField(
159
+ 'stock_qty', 'text', array(
160
+ 'name' => 'stock_qty',
161
+ 'label' => Mage::helper('optemais')->__('Estoque'),
162
+ 'title' => Mage::helper('optemais')->__('Estoque'),
163
+ 'style' => 'width: 90px;',
164
+ )
165
+ );
166
+
167
+ $form->setUseContainer(true);
168
+ $this->setForm($form);
169
+ return parent::_prepareForm();
170
+ }
171
+
172
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Adminhtml/Paymentmethod.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Adminhtml_Paymentmethod extends Mage_Adminhtml_Block_System_Config_Form_Field {
15
+ protected $_addRowButtonHtml = array();
16
+ protected $_removeRowButtonHtml = array();
17
+
18
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
19
+ $this->setElement($element);
20
+ $html = '<div id="payment_method_template" style="display:none">';
21
+ $html .= $this->_getRowTemplateHtml();
22
+ $html .= '</div>';
23
+ $html .= '<ul id="payment_method_container">';
24
+ if ($this->_getValue('payment_method_code')) {
25
+ foreach ($this->_getValue('payment_method_code') as $i => $f) {
26
+ if ($i) {
27
+ $html .= $this->_getRowTemplateHtml($i);
28
+ }
29
+ }
30
+ }
31
+ $html .= '</ul>';
32
+ $html .= $this->_getAddRowButtonHtml('payment_method_container', 'payment_method_template', $this->__('Adicionar'));
33
+ return $html;
34
+ }
35
+
36
+ protected function _getRowTemplateHtml($i = 0) {
37
+ $html = '<li><fieldset>';
38
+ $html .= '<label>' . $this->__('Método de Pagamento') . '</label>';
39
+ $html .= '<select name="' . $this->getElement()->getName() . '[payment_method_code][]" ' . $this->_getDisabled() . '>';
40
+ $html .= '<option value="">' . Mage::helper('adminhtml')->__('-- Please Select --') . '</option>';
41
+ foreach ($this->_getPaymentMethods() as $id => $title) {
42
+ $html .= '<option value="' . $id . '" '
43
+ . $this->_getSelected('payment_method_code/' . $i, $id)
44
+ . ' style="background:white;">' . $title . '</option>';
45
+ }
46
+ $html .= '</select>';
47
+ $html .= '<p class="note">Método de Pagamento</p>';
48
+ $html .= '<label>' . $this->__('Quantidade de Parcelas') . '</label>';
49
+ $html .= '<select name="' . $this->getElement()->getName() . '[qty_installments][]" ' . $this->_getDisabled() . '>';
50
+ foreach ($this->_getInstallments() as $item) {
51
+ $html .= '<option value="' . $item['value'] . '" '
52
+ . $this->_getSelected('qty_installments/' . $i, $item['value'])
53
+ . ' style="background:white;">' . $item['label'] . '</option>';
54
+ }
55
+ $html .= '</select>';
56
+ $html .= '<p class="note">Número maximo de parcelas permitida para o Método de Pagamento (Selecione somente quando houver parcelamento).</p>';
57
+
58
+
59
+ $html .= '<label>' . $this->__('Júros aplicado às parcelas') . '</label>';
60
+ $html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[interest][]" value="' . $this->_getValue('interest/' . $i) . '" ' . $this->_getDisabled() . ' />';
61
+ $html .= '<p class="note">Júros que será aplicado ao parcelamento (Preencha somente quando houver parcelamento e júros). Exemplo: 1.9%</p>';
62
+
63
+ $html .= '<label>' . $this->__('Parâmetro esperado para receber informação de parcelamento') . '</label>';
64
+ $html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[param_installment][]" value="' . $this->_getValue('param_installment/' . $i) . '" ' . $this->_getDisabled() . ' />';
65
+ $html .= '<p class="note">Nome do parâmetro esperado no Método de Pagamento para informação do parcelamento (varia de acordo com cada extensão de Método de Pagamento no Magento). Exemplo: cc_installlments</p>';
66
+
67
+
68
+ $html .= $this->_getRemoveRowButtonHtml();
69
+ $html .= '</fieldset></li>';
70
+
71
+ return $html;
72
+ }
73
+
74
+ protected function _getDisabled() {
75
+ return $this->getElement()->getDisabled() ? ' disabled' : '';
76
+ }
77
+
78
+ protected function _getValue($key) {
79
+ return $this->getElement()->getData('value/' . $key);
80
+ }
81
+
82
+ protected function _getSelected($key, $value) {
83
+ return $this->getElement()->getData('value/' . $key) == $value ? 'selected="selected"' : '';
84
+ }
85
+
86
+ protected function _getAddRowButtonHtml($container, $template, $title = 'Adicionar') {
87
+ if (!isset($this->_addRowButtonHtml[$container])) {
88
+ $this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
89
+ ->setType('button')
90
+ ->setClass('add ' . $this->_getDisabled())
91
+ ->setLabel($this->__($title))
92
+ ->setOnClick("Element.insert($('" . $container . "'), {bottom: $('" . $template . "').innerHTML})")
93
+ ->setDisabled($this->_getDisabled())
94
+ ->toHtml();
95
+ }
96
+ return $this->_addRowButtonHtml[$container];
97
+ }
98
+
99
+ protected function _getRemoveRowButtonHtml($selector = 'li', $title = 'Remover') {
100
+ if (!$this->_removeRowButtonHtml) {
101
+ $this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
102
+ ->setType('button')
103
+ ->setClass('delete v-middle ' . $this->_getDisabled())
104
+ ->setLabel($this->__($title))
105
+ ->setOnClick("Element.remove($(this).up('" . $selector . "'))")
106
+ ->setDisabled($this->_getDisabled())
107
+ ->toHtml();
108
+ }
109
+ return $this->_removeRowButtonHtml;
110
+ }
111
+
112
+ /**
113
+ * Retrieves payment methods
114
+ *
115
+ * @return array
116
+ */
117
+ public function _getPaymentMethods() {
118
+ $payments = Mage::getSingleton('payment/config')->getAllMethods();
119
+ $methods = array();
120
+ foreach ($payments as $code => $model) {
121
+ $title = Mage::getStoreConfig('payment/' . $code . '/title');
122
+ $methods[$code] = $title . ' (' . $code . ')';
123
+ }
124
+ return $methods;
125
+ }
126
+
127
+ /**
128
+ * Retrieves Yes/NO
129
+ *
130
+ * @return array
131
+ */
132
+ public function _getInstallments() {
133
+ $installments = array();
134
+ $installments[] = array('label'=>Mage::helper('optemais')->__('Nenhuma'),'value'=>0);
135
+ for ($x = 1; $x <= 24; $x++) {
136
+ $installments[] = array('label'=>$x . 'x','value'=>$x);
137
+ }
138
+ return $installments;
139
+ }
140
+ }
app/code/community/CsuMarketSystem/OpteMais/Block/Payment/Info/Modelc.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Block_Payment_Info_Modelc extends Mage_Payment_Block_Info
15
+ {
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ $this->setTemplate('optemais/payment/info/modelc.phtml');
20
+ }
21
+ }
app/code/community/CsuMarketSystem/OpteMais/Helper/Data.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+
17
+ const AUTH_REALM = 'CSU MarketSystem OPTe+ Api';
18
+
19
+ const MESSAGE_SUCCESS = 'Requisição executada com sucesso';
20
+ const STATUS_CODE_SUCCESS = 200;
21
+
22
+ const MESSAGE_NOT_FOUND = 'Recurso não encontrado: %s';
23
+ const STATUS_CODE_NOT_FOUND = 404;
24
+
25
+ const MESSAGE_NOT_AUTHORIZED = 'Usuario inválid.';
26
+ const STATUS_CODE_NOT_AUTHORIZED = 401;
27
+
28
+ const MESSAGE_INVALID = 'Parâmetros inválidos: %s';
29
+ const STATUS_CODE_INVALID = 405;
30
+
31
+ const MESSAGE_ERROR = 'Erro: %s';
32
+ const STATUS_CODE_ERROR = 500;
33
+
34
+ public function isActive()
35
+ {
36
+ return Mage::getStoreConfigFlag('optemais/config/active');
37
+ }
38
+
39
+ /**
40
+ * @param $cpf
41
+ *
42
+ * @return mixed|string
43
+ */
44
+ public function formatCpf($cpf)
45
+ {
46
+ $cpf = str_replace(array(',', '-', '.', ' '), '', $cpf);
47
+ if (strlen($cpf) == 11) {
48
+ $cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
49
+ $cpf = substr($cpf, 0, 3) . '.' . substr($cpf, 3, 3) . '.' . substr($cpf, 6, 3) . '-' . substr($cpf, 9, 2);
50
+ }
51
+ return $cpf;
52
+ }
53
+
54
+ /**
55
+ * @param $cnpj
56
+ *
57
+ * @return mixed|string
58
+ */
59
+ public function formatCnpj($cnpj)
60
+ {
61
+ $cnpj = str_replace(array(',', '-', '.', ' '), '', $cnpj);
62
+ $cnpj = substr($cnpj, 0, 2) . '.' . substr($cnpj, 2, 3) .
63
+ '.' . substr($cnpj, 5, 3) . '/' .
64
+ substr($cnpj, 8, 4) . '-' . substr($cnpj, 12, 2);
65
+ return $cnpj;
66
+ }
67
+
68
+ /**
69
+ * @param $shippingMethod
70
+ *
71
+ * @return array
72
+ */
73
+ public function getShippingMethodData($shippingMethod)
74
+ {
75
+ $data = array();
76
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
77
+ /** @var Mage_Shipping_Model_Carrier_Abstract $carriersModel */
78
+ foreach ($carriers as $carCod => $carriersModel) {
79
+ if (strpos($shippingMethod, $carCod) === false) {
80
+ continue;
81
+ }
82
+ $data['carrier_title'] = $carriersModel->getConfigData('title');
83
+ $data['carrier'] = $carriersModel->getCarrierCode();
84
+ list($carrierCode, $methodCode) = explode($carriersModel->getCarrierCode() . '_', $shippingMethod);
85
+ $data['method'] = $methodCode;
86
+ foreach ($carriersModel->getAllowedMethods() as $metCod => $title) {
87
+ if ($metCod == $methodCode) {
88
+ $data['method_title'] = $title;
89
+ break;
90
+ }
91
+ }
92
+ }
93
+ return $data;
94
+ }
95
+
96
+ public function getPriceWithInterest($value,$interest,$qtyInstallments) {
97
+ $interest = $interest / 100;
98
+ return round($value * (($interest * pow((1 + $interest), $qtyInstallments)) / (pow((1 + $interest), $qtyInstallments) - 1)), 2);
99
+ }
100
+
101
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Abstract.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ abstract class CsuMarketSystem_OpteMais_Model_Abstract extends Mage_Core_Model_Abstract
15
+ {
16
+
17
+ protected function _beforeSave()
18
+ {
19
+ $this->setData('updated_at', Mage::getSingleton('core/date')->gmtDate());
20
+ if (!$this->getId()) {
21
+ $this->setData('created_at', Mage::getSingleton('core/date')->gmtDate());
22
+ }
23
+ return parent::_beforeSave();
24
+ }
25
+
26
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Auth/Adapter/Http.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Auth_Adapter_Http extends Zend_Auth_Adapter_Http
15
+ {
16
+
17
+ protected function _basicAuth($header)
18
+ {
19
+ if (empty($header)) {
20
+ throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
21
+ }
22
+ $auth = substr($header, strlen('Basic '));
23
+ $auth = base64_decode($auth);
24
+ if (!$auth) {
25
+ throw new Zend_Auth_Adapter_Exception('Unable to base64_decode Authorization header value');
26
+ }
27
+ if (!ctype_print($auth)) {
28
+ return $this->_challengeClient();
29
+ }
30
+ $creds = array_filter(explode(':', $auth));
31
+ if (count($creds) != 2) {
32
+ return $this->_challengeClient();
33
+ }
34
+ $username = Mage::getStoreConfig('optemais/config/username');
35
+ $password = Mage::getStoreConfig('optemais/config/password');
36
+ if (($creds[0] == $username) && ($creds[1] == $password)) {
37
+ $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, '', array(Mage::helper('optemais')->__('Autorizado.')));
38
+ } else {
39
+ $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, '', array(Mage::helper('optemais')->__('Falha na autenticacao.')));
40
+ $this->_challengeClient();
41
+ }
42
+ return $result;
43
+ }
44
+
45
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Campaign.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Campaign extends CsuMarketSystem_OpteMais_Model_Abstract
15
+ {
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('optemais/campaign');
20
+ }
21
+
22
+ protected function _beforeSave()
23
+ {
24
+ foreach ($this->getData() as $key => $value) {
25
+ if (in_array($key, array('from_date', 'to_date')) && $value) {
26
+ $value = Mage::app()->getLocale()->date(
27
+ $value,
28
+ Varien_Date::DATE_INTERNAL_FORMAT,
29
+ null,
30
+ false
31
+ );
32
+ $this->setData($key, $value);
33
+ } elseif($key == 'payment_methods') {
34
+ $serialized = serialize($value);
35
+ $this->setData($key,$serialized);
36
+ }
37
+ }
38
+ return parent::_beforeSave();
39
+ }
40
+
41
+ protected function _afterLoad() {
42
+ foreach ($this->getData() as $key => $value) {
43
+ if($key == 'payment_methods') {
44
+ $unserialized = unserialize($value);
45
+ $this->setData($key,$unserialized);
46
+ }
47
+ }
48
+ return parent::_afterLoad();
49
+ }
50
+
51
+ public function isValid()
52
+ {
53
+ if ($this->getId()) {
54
+ if (!$this->getIsActive()) {
55
+ return false;
56
+ }
57
+ if (!$this->getFromDate() && !$this->getToDate()) {
58
+ return true;
59
+ } elseif ($this->getFromDate() && !$this->getToDate()) {
60
+ return strtotime("today") >= strtotime($this->getFromDate());
61
+ } elseif ($this->getFromDate() && $this->getToDate()) {
62
+ return strtotime("today") >= strtotime($this->getFromDate()) && strtotime("today") <= strtotime($this->getToDate());
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+
68
+ public function getToOptions($onlyActive = false)
69
+ {
70
+ $items = array();
71
+ $items[null] = Mage::helper('optemais')->__('-- Escolha uma Campanha --');
72
+ foreach ($this->getCollection() as $item) {
73
+ if ($onlyActive && !$item->getIsActive()) {
74
+ continue;
75
+ }
76
+ $items[$item->getEntityId()] = $item->getName();
77
+ }
78
+ return $items;
79
+ }
80
+
81
+ public function addCampaign(Mage_Core_Controller_Request_Http $request)
82
+ {
83
+ $campaign = $this;
84
+ $campaign->setId(null);
85
+ $campaign->setName($request->getParam('name'));
86
+ $campaign->setDescription($request->getParam('description'));
87
+ $campaign->setIsActive($request->getParam('is_active'));
88
+ $campaign->setPaymentMethods($request->getParam('payment_methods'));
89
+ $campaign->setFromDate($request->getParam('from_date'));
90
+ $campaign->setToDate($request->getParam('to_date'));
91
+ $campaign->save();
92
+ if ($campaign->getId()) {
93
+ $this->addItemToCampaign($request, $campaign->getId());
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+
99
+ public function addItemToCampaign(Mage_Core_Controller_Request_Http $request, $campaignId)
100
+ {
101
+ $products = explode(',', $request->getParam('products'));
102
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
103
+ ->addAttributeToSelect('*')
104
+ ->addIdFilter($products)
105
+ ->joinField(
106
+ 'qty',
107
+ 'cataloginventory/stock_item',
108
+ 'qty',
109
+ 'product_id=entity_id',
110
+ '{{table}}.stock_id=1',
111
+ 'left'
112
+ );
113
+ foreach ($productCollection as $product) {
114
+ $campaignItem = Mage::getModel('optemais/campaign_item');
115
+ $campaignItem->setId(null);
116
+ $campaignItem->setCampaignId($campaignId);
117
+ $campaignItem->setProductId($product->getId());
118
+ $campaignItem->setPrice($this->_applyAdjust($product->getPrice(), $request->getParam('price')));
119
+ $campaignItem->setStockQty($this->_applyAdjust($product->getQty(), $request->getParam('stock_qty')));
120
+ $campaignItem->save();
121
+ }
122
+ return true;
123
+ }
124
+
125
+ private function _applyAdjust($value, $adjust)
126
+ {
127
+ if (strpos($adjust, '%')) {
128
+ $adjust = str_replace(array(',', '%'), array('.', ''), $adjust);
129
+ $percent = $value * (1 + $adjust / 100);
130
+ if (strpos($adjust, '-')) {
131
+ $value -= $percent;
132
+ } else {
133
+ $value += $percent;
134
+ }
135
+ } else {
136
+ $adjust = str_replace(',', '.', $adjust);
137
+ $value += $adjust;
138
+ }
139
+ return $value;
140
+ }
141
+
142
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Campaign/Item.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Campaign_Item extends CsuMarketSystem_OpteMais_Model_Abstract
15
+ {
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('optemais/campaign_item');
20
+ }
21
+
22
+ protected function _beforeSave()
23
+ {
24
+ foreach ($this->getData() as $key => $value) {
25
+ if (in_array($key, array('from_date', 'to_date')) && $value) {
26
+ $value = Mage::app()->getLocale()->date(
27
+ $value,
28
+ Varien_Date::DATE_INTERNAL_FORMAT,
29
+ null,
30
+ false
31
+ );
32
+ $this->setData($key, $value);
33
+ }
34
+ }
35
+ return parent::_beforeSave();
36
+ }
37
+
38
+ public function getItemByParams($params = array())
39
+ {
40
+ return $this->getResource()->getItemByParams($params);
41
+ }
42
+
43
+ public function getItemsByParams($params = array(), $limit = null)
44
+ {
45
+ return $this->getResource()->getItemsByParams($params, $limit);
46
+ }
47
+
48
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Estimate/Rate.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Estimate_Rate
15
+ {
16
+ /**
17
+ * Customer object,
18
+ * if customer isn't logged in it quals to false
19
+ *
20
+ * @var Mage_Customer_Model_Customer|boolean
21
+ */
22
+ protected $_customer = null;
23
+
24
+ /**
25
+ * Sales quote object to add products for shipping estimation
26
+ *
27
+ * @var Mage_Sales_Model_Quote
28
+ */
29
+ protected $_quote = null;
30
+
31
+ /**
32
+ * Product model
33
+ *
34
+ * @var Mage_Catalog_Model_Product
35
+ */
36
+ protected $_products = array();
37
+
38
+ /**
39
+ * Estimation result
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_result = array();
44
+
45
+ /**
46
+ * Delivery address information
47
+ *
48
+ * @var array
49
+ */
50
+ protected $_addressInfo = null;
51
+
52
+ /**
53
+ * Set address info for estimation
54
+ *
55
+ * @param array $info
56
+ *
57
+ * @return $this
58
+ */
59
+ public function setAddressInfo($info)
60
+ {
61
+ $this->_addressInfo = $info;
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * Retrieve address information
67
+ *
68
+ * @return array
69
+ */
70
+ public function getAddressInfo()
71
+ {
72
+ return $this->_addressInfo;
73
+ }
74
+
75
+ /**
76
+ * Set a product for the estimation
77
+ *
78
+ * @param Mage_Catalog_Model_Product $product
79
+ *
80
+ * @return $this
81
+ */
82
+ public function setProduct(Mage_Catalog_Model_Product $product)
83
+ {
84
+ if ($product->isConfigurable()) {
85
+ $cartInfo = $product->getAddToCartInfo();
86
+ $_product = false;
87
+ if (isset($cartInfo['related_product'])) {
88
+ if ($cartInfo['related_product'] != '') {
89
+ $_product = Mage::getModel('catalog/product')->load($cartInfo['related_product']);
90
+ } else {
91
+ $collection = $product->getTypeInstance()->getUsedProductCollection();
92
+ foreach ($collection as $_product) {
93
+ if ($_product->getIsInStock()) {
94
+ break;
95
+ }
96
+ }
97
+ $_product->load($_product->getId());
98
+ }
99
+
100
+ } else {
101
+ $collection = $product->getTypeInstance()->getUsedProductCollection();
102
+ foreach ($collection as $_product) {
103
+ if ($_product->getIsInStock()) {
104
+ break;
105
+ }
106
+ }
107
+ $_product->load($_product->getId());
108
+ }
109
+
110
+ if ($cartInfo && $_product) {
111
+ $_product->setAddToCartInfo($cartInfo);
112
+ }
113
+
114
+ } else {
115
+ $_product = $product;
116
+ }
117
+ $this->_products[] = $_product;
118
+ return $this;
119
+ }
120
+
121
+ /**
122
+ * Retrieve product for the estimation
123
+ */
124
+ public function getProducts()
125
+ {
126
+ return $this->_products;
127
+ }
128
+
129
+ /**
130
+ * Retrieve shipping rate result
131
+ *
132
+ * @return array|null
133
+ */
134
+ public function getResult()
135
+ {
136
+ return $this->_result;
137
+ }
138
+
139
+ /**
140
+ * Retrieve list of shipping rates
141
+ *
142
+ * @return $this
143
+ */
144
+ public function estimate()
145
+ {
146
+
147
+ $addressInfo = (array)$this->getAddressInfo();
148
+ if (empty($addressInfo['cart'])) {
149
+ $this->resetQuote();
150
+ }
151
+
152
+ if (!isset($addressInfo['country_id'])) {
153
+ Mage::throwException(
154
+ Mage::helper('optemais')->__('Por favor, especifique um país válido')
155
+ );
156
+ }
157
+
158
+ $shippingAddress = $this->getQuote()->getShippingAddress();
159
+
160
+ $shippingAddress->setCountryId($addressInfo['country_id']);
161
+
162
+ if (isset($addressInfo['region_id'])) {
163
+ $shippingAddress->setRegionId($addressInfo['region_id']);
164
+ }
165
+
166
+ if (isset($addressInfo['postcode'])) {
167
+ $shippingAddress->setPostcode($addressInfo['postcode']);
168
+ }
169
+
170
+ if (isset($addressInfo['region'])) {
171
+ $shippingAddress->setRegion($addressInfo['region']);
172
+ }
173
+
174
+ if (isset($addressInfo['city'])) {
175
+ $shippingAddress->setCity($addressInfo['city']);
176
+ }
177
+
178
+ $shippingAddress->setCollectShippingRates(true);
179
+
180
+ if (isset($addressInfo['coupon_code'])) {
181
+ $this->getQuote()->setCouponCode($addressInfo['coupon_code']);
182
+ }
183
+
184
+ $products = $this->getProducts();
185
+
186
+ $this->getQuote()->removeAllItems();
187
+
188
+ foreach ($products as $product) {
189
+ $addToCartInfo = (array)$product->getAddToCartInfo();
190
+
191
+ if (!($product instanceof Mage_Catalog_Model_Product) || !$product->getId()) {
192
+ Mage::throwException(
193
+ Mage::helper('optemais')->__('Por favor, especifique um produto válido')
194
+ );
195
+ }
196
+
197
+ $request = new Varien_Object($addToCartInfo);
198
+
199
+ if ($product->getStockItem()) {
200
+ $minimumQty = $product->getStockItem()->getMinSaleQty();
201
+ if ($minimumQty > 0 && $request->getQty() < $minimumQty) {
202
+ $request->setQty($minimumQty);
203
+ }
204
+ }
205
+
206
+ $result = $this->getQuote()->addProduct($product, $request);
207
+ if (is_string($result)) {
208
+ Mage::throwException($result);
209
+ }
210
+
211
+ Mage::dispatchEvent(
212
+ 'checkout_cart_product_add_after',
213
+ array('quote_item' => $result, 'product' => $product)
214
+ );
215
+
216
+ }
217
+
218
+ $this->getQuote()->collectTotals();
219
+ $this->_result = $shippingAddress->getGroupedAllShippingRates();
220
+ return $this->_result;
221
+ }
222
+
223
+ /**
224
+ * Retrieve sales quote object
225
+ *
226
+ * @return Mage_Sales_Model_Quote
227
+ */
228
+ public function getQuote()
229
+ {
230
+ return Mage::getSingleton('checkout/session')->getQuote();
231
+ }
232
+
233
+
234
+ /**
235
+ * Reset quote object
236
+ *
237
+ * @return $this
238
+ */
239
+ public function resetQuote()
240
+ {
241
+ $this->getQuote()->removeAllAddresses();
242
+
243
+ if ($this->getCustomer()) {
244
+ $this->getQuote()->setCustomer($this->getCustomer());
245
+ }
246
+
247
+ return $this;
248
+ }
249
+
250
+ /**
251
+ * Retrieve currently logged in customer,
252
+ * if customer isn't logged it returns false
253
+ *
254
+ * @return Mage_Customer_Model_Customer|boolean
255
+ */
256
+ public function getCustomer()
257
+ {
258
+ if ($this->_customer === null) {
259
+ $customerSession = Mage::getSingleton('customer/session');
260
+ if ($customerSession->isLoggedIn()) {
261
+ $this->_customer = $customerSession->getCustomer();
262
+ } else {
263
+ $this->_customer = false;
264
+ }
265
+ }
266
+
267
+ return $this->_customer;
268
+ }
269
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Observer.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Observer
15
+ {
16
+
17
+ public function addMassActionToProductGrid($observer)
18
+ {
19
+ if (!Mage::helper('optemais')->isActive()) {
20
+ return $this;
21
+ }
22
+ /** @var $block Mage_Adminhtml_Block_Widget_Grid_Massaction_Abstract */
23
+ $block = $observer->getBlock();
24
+ $block->getMassactionBlock()->addItem(
25
+ 'optemais_add_to_campaign', array(
26
+ 'label' => $block->__('Adicionar à Campanha OPTe+'),
27
+ 'url' => $block->getUrl('adminhtml/optemais_campaign/addItems'),
28
+ )
29
+ );
30
+ }
31
+
32
+ public function afterUpdateAttributes($observer)
33
+ {
34
+ $productIds = $observer->getProductIds();
35
+ if (!$productIds) {
36
+ $productIds = $observer->getProducts();
37
+ }
38
+ if (!$productIds) {
39
+ return false;
40
+ }
41
+ Mage::getSingleton('core/resource')->getConnection('core_write')
42
+ ->update(
43
+ 'catalog_product_entity',
44
+ array('updated_at' => Mage::getSingleton('core/date')->gmtDate()),
45
+ array('entity_id IN (?)' => $productIds)
46
+ );
47
+
48
+ }
49
+
50
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Order.php ADDED
@@ -0,0 +1,782 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Order
15
+ {
16
+
17
+ const DEFAULT_COUNTRY_ID = 'BR';
18
+ const CHANGE_STATUS_APPROVED = "APR";
19
+ const CHANGE_STATUS_CANCELED = "CAN";
20
+
21
+ private $_optemaisStatuses = array(
22
+ '1' => 'Pedido Aprovado',
23
+ '2' => 'Pedido Cancelado',
24
+ '3' => 'Aguardando Liberação',
25
+ '4' => 'Pedido Pendente',
26
+ '5' => 'Pedido Entregue',
27
+ '9' => 'Pedido Devolvido',
28
+ );
29
+
30
+ private $_configStatuses = array(
31
+ '1' => 'status_approved',
32
+ '2' => 'status_canceled',
33
+ '3' => 'status_await_release',
34
+ '4' => 'status_pending',
35
+ '5' => 'status_delivered',
36
+ '9' => 'status_refunded',
37
+ );
38
+
39
+ private $_validChangeStatus = array(
40
+ self::CHANGE_STATUS_APPROVED,
41
+ self::CHANGE_STATUS_CANCELED
42
+ );
43
+
44
+ private $_requiredOrderDataParams = array(
45
+ 'PedidoParceiro',
46
+ 'Destinatario' => array(
47
+ 'CpfCnpj',
48
+ 'Email',
49
+ 'Nome',
50
+ 'Telefone'
51
+ ),
52
+ 'EnderecoEntrega' => array(
53
+ 'Bairro',
54
+ 'CEP',
55
+ 'Cidade',
56
+ 'Estado',
57
+ 'Logradouro',
58
+ 'Numero'
59
+ ),
60
+ 'ValorFrete',
61
+ 'Produtos',
62
+ 'ValorTotalPedido',
63
+ 'ValorTotal'
64
+ );
65
+
66
+ private $_statuses = null;
67
+ private $_regions = null;
68
+
69
+ public function createOrder($orderData)
70
+ {
71
+ /** @var CsuMarketSystem_OpteMais_Helper_Data $helper */
72
+ $helper = Mage::helper('optemais');
73
+ try {
74
+
75
+ $validatesResult = $this->_validatesOrderData($orderData);
76
+ if (!$validatesResult['status']) {
77
+ throw new Exception($helper->__("Dados inválidos ou faltando: [%s]",implode(",",$validatesResult['rows'])));
78
+ }
79
+
80
+ $websiteId = Mage::app()->getWebsite()->getId();
81
+ $storeId = Mage::getStoreConfig('optemais/config_order/default_store_id');
82
+ $store = Mage::app()->getStore();
83
+
84
+ if (is_null($storeId)) {
85
+ $storeId = Mage::app()->getStore()->getId();
86
+ }
87
+
88
+ /** @var Mage_Sales_Model_Quote $quote */
89
+ $quote = Mage::getModel('sales/quote')
90
+ ->setStoreId($storeId);
91
+
92
+ $customerCnpj = null;
93
+ $customerTipopessoa = null;
94
+ $customerRazaoSocial = null;
95
+
96
+ $attributeCpf = null;
97
+ $attributeCnpj = null;
98
+ $attributeTipoPessoa = null;
99
+ $attributeRazaoSocial = null;
100
+
101
+ $customerDocument = $orderData['Destinatario']['CpfCnpj'];
102
+ $customerName = $orderData['Destinatario']['Nome'];
103
+
104
+ $customerTipopessoa = $this->_validateDocument($customerDocument);
105
+
106
+ if ($customerTipopessoa == 'pj') {
107
+ $attributeCnpj = Mage::getStoreConfig('optemais/config_order/attribute_cnpj');
108
+ $attributeRazaoSocial = Mage::getStoreConfig('optemais/config_order/attribute_razao_social');
109
+ if (isset($attributeCnpj)) {
110
+ $customerCnpj = $helper->formatCnpj($customerDocument);
111
+ }
112
+ $customerCpf = '';
113
+ } else {
114
+ $attributeCpf = Mage::getStoreConfig('optemais/config_order/attribute_cpf');
115
+ $customerCpf = $helper->formatCpf($customerDocument);
116
+ }
117
+
118
+ $attributeTipoPessoa = Mage::getStoreConfig('optemais/config_order/attribute_tipo_pessoa');
119
+
120
+ $separatorIndex = strpos($customerName, " ");
121
+ if ($separatorIndex !== false) {
122
+ $customerFirstName = substr($customerName, 0, $separatorIndex);
123
+ $customerLastName = substr($customerName, $separatorIndex + 1);
124
+ } else {
125
+ $customerFirstName = $customerName;
126
+ $customerLastName = $customerName;
127
+ }
128
+
129
+ $phoneNumber = $orderData['Destinatario']['Telefone'];
130
+ $celNumber = $orderData['Destinatario']['TelefoneCelular'];
131
+ $postalCode = $orderData['EnderecoEntrega']['CEP'];
132
+ $street = $orderData['EnderecoEntrega']['Logradouro'];
133
+ $number = $orderData['EnderecoEntrega']['Numero'];
134
+ $additionalInfo = $orderData['EnderecoEntrega']['Complemento'];
135
+ $district = $orderData['EnderecoEntrega']['Bairro'];
136
+ $streetRows = $this->_getStreet($street, $number, $additionalInfo, $district);
137
+ $city = $orderData['EnderecoEntrega']['Cidade'];
138
+ $regionCode = $orderData['EnderecoEntrega']['Estado'];
139
+
140
+ $countryId = $this->_getCountryId($city);
141
+ $regionId = $this->_getRegionIdByCode($regionCode, $countryId);
142
+
143
+ $address = array(
144
+ 'firstname' => $customerFirstName,
145
+ 'lastname' => $customerLastName,
146
+ 'street' => $streetRows,
147
+ 'city' => $city,
148
+ 'postcode' => $postalCode,
149
+ 'country_id' => $countryId,
150
+ 'telephone' => $phoneNumber,
151
+ 'fax' => $celNumber,
152
+ 'customer_password' => '',
153
+ 'confirm_password' => '',
154
+ 'use_for_shipping' => '1',
155
+ );
156
+
157
+ if ($regionId) {
158
+ $address['region_id'] = $regionId;
159
+ } else {
160
+ $address['region'] = $regionCode;
161
+ }
162
+
163
+ try {
164
+ $email = $orderData['Destinatario']['Email'];
165
+ $customer = Mage::getModel('customer/customer')
166
+ ->setWebsiteId($websiteId)
167
+ ->loadByEmail($email);
168
+ if (!$customer->getId()) {
169
+ $customer->setId(null);
170
+ $password = $customer->generatePassword(8);
171
+ $customer->setWebsiteId($websiteId)
172
+ ->setStore($store)
173
+ ->setFirstname($customerFirstName)
174
+ ->setLastname($customerLastName)
175
+ ->setEmail($email)
176
+ ->setPassword($password);
177
+ if ($attributeRazaoSocial) {
178
+ $customer->setData($attributeRazaoSocial, $customerRazaoSocial);
179
+ }
180
+ if ($attributeTipoPessoa && ($valueTipoPessoa = Mage::getStoreConfig('optemais/config_config_order/tipo_pessoa_value_' . $customerTipopessoa))) {
181
+ $customer->setData($attributeTipoPessoa, $valueTipoPessoa);
182
+ }
183
+ if ($customerTipopessoa == 'pj' && $attributeCnpj) {
184
+ $customer->setData($attributeCnpj, $customerCnpj);
185
+ } elseif ($customerCpf && $attributeCpf) {
186
+ $customer->setData($attributeCpf, $customerCpf);
187
+ }
188
+ $customer->save();
189
+ }
190
+ } catch (Exception $e) {
191
+ throw new Exception($e->getMessage());
192
+ }
193
+
194
+ Mage::log($customer->getId());
195
+ Mage::log($customer->getEmail());
196
+
197
+ try {
198
+ /** @var Mage_Customer_Model_Address $addressCustomer */
199
+ $addressCustomer = Mage::getModel('customer/address');
200
+ $addressCustomer->setCustomerId($customer->getId())
201
+ ->setFirstname($customerFirstName)
202
+ ->setLastname($customerLastName)
203
+ ->setCountryId($countryId)
204
+ ->setPostcode($postalCode)
205
+ ->setCity($city)
206
+ ->setTelephone($phoneNumber)
207
+ ->setStreet($streetRows)
208
+ ->setIsDefaultBilling('1')
209
+ ->setIsDefaultShipping('1')
210
+ ->setSaveInAddressBook('1');
211
+ if ($regionId) {
212
+ $addressCustomer->setRegionId($regionId);
213
+ } else {
214
+ $addressCustomer->setRegion($regionCode);
215
+ }
216
+ $addressCustomer->save();
217
+ } catch (Exception $e) {
218
+ throw new Exception($e->getMessage());
219
+ }
220
+
221
+ if (!isset($orderData['Produtos']) || !$orderData['Produtos']) {
222
+ throw new Exception($helper->__('Não foi possível importar o pedido %s, não há produtos comprados nesse pedido.', $orderData['PedidoParceiro']));
223
+ }
224
+
225
+ foreach ($orderData['Produtos'] as $itemProduct) {
226
+ $sku = trim($itemProduct['Sku']);
227
+ /** @var Mage_Catalog_Model_Product $product */
228
+ $product = Mage::getModel('catalog/product');
229
+ $product->load($product->getIdBySku($sku));
230
+ $buyInfo = array('qty' => $itemProduct['Quantidade']);
231
+ if ($product->getId()) {
232
+ if ($parentId = $this->_getParentIds($product)) {
233
+ $attributes = $this->_getAttributesByParentId($parentId);
234
+ $options = array();
235
+ foreach ($attributes as $attribute) {
236
+ $options[(int)$attribute['id']] = (int)$product->getData($attribute['code']);
237
+ }
238
+ /** @var Mage_Catalog_Model_Product $parent */
239
+ $parent = Mage::getModel('catalog/product')->load($parentId);
240
+ $buyInfo = array(
241
+ 'product' => $parent->getId(),
242
+ 'qty' => $itemProduct['Quantidade'],
243
+ 'super_attribute' => $options,
244
+ );
245
+ $product = $parent;
246
+ }
247
+ $item = $quote->addProduct($product, new Varien_Object($buyInfo));
248
+ if (is_object($item) && $item->getParentItem()) {
249
+ $item = $item->getParentItem();
250
+ $item->setOriginalCustomPrice($itemProduct['PrecoVenda']);
251
+ $item->setCustomPrice($itemProduct['PrecoVenda']);
252
+ $item->getProduct()->setIsSuperMode(true);
253
+ } elseif (is_string($item) && $item == 'Please specify the product required option(s).') {
254
+ throw new Exception($helper->__('Pedidos com produtos (%s) com opções customizáveis não serão integrados.', $itemProduct['Sku']));
255
+ } elseif (is_string($item)) {
256
+ throw new Exception($helper->__('Não foi possível adicionar o produto (%s) ao pedido. Erro: %s.', $itemProduct['Sku'], $item));
257
+ }
258
+ } else {
259
+ throw new Exception($helper->__('Produto com SKU (%s) não existe na loja, cadastre para que o pedido seja importado.', $itemProduct['Sku']));
260
+ }
261
+ }
262
+
263
+ $quote->getBillingAddress()
264
+ ->addData($address);
265
+
266
+ $shippingMethodCode = Mage::getStoreConfig('optemais/config_order/shipping_method');
267
+ $shippingMethodData = $helper->getShippingMethodData($shippingMethodCode);
268
+ $totalFreight = $orderData['ValorFrete'];
269
+
270
+ $rate = Mage::getModel('sales/quote_address_rate')
271
+ ->setCode($shippingMethodCode)
272
+ ->setMethod($shippingMethodData['method'])
273
+ ->setMethodTitle($shippingMethodData['method_title'])
274
+ ->setCarrier($shippingMethodData['carrier'])
275
+ ->setCarrierTitle($shippingMethodData['carrier_title'])
276
+ ->setPrice($totalFreight);
277
+
278
+ $quote->getShippingAddress()
279
+ ->addData($address);
280
+
281
+ $ccInstallmentsKey = null;
282
+ if(isset($orderData['IdFormaPagamento']) && isset($orderData['DadosCartaoCredito'])) {
283
+ $methodData = $this->_getMethodDataByCcType($orderData['IdFormaPagamento']);
284
+ $ccInstallmentsKey = 'cc_installments';
285
+ if($data = $this->_getConfigDataForPaymentMethod($methodData['code'])) {
286
+ if($data['param_installment']) $ccInstallmentsKey = $data['param_installment'];
287
+ }
288
+ $paymentData = array(
289
+ 'store_id' => $storeId,
290
+ 'cc_custom_payment_id' => 0,
291
+ 'method' => $methodData['code'],
292
+ 'cc_type' => $methodData['cc_type'],
293
+ 'cc_number' => $orderData['DadosCartaoCredito']['Numero'],
294
+ 'cc_number_enc' => Mage::getSingleton('payment/info')->encrypt($orderData['DadosCartaoCredito']['Numero']),
295
+ 'cc_owner' => $orderData['DadosCartaoCredito']['Nome'],
296
+ 'cc_exp_month' => $orderData['DadosCartaoCredito']['ValidadeMes'],
297
+ 'cc_exp_year' => $orderData['DadosCartaoCredito']['ValidadeAno'],
298
+ 'cc_last4' => substr($orderData['DadosCartaoCredito']['Numero'],-4),
299
+ 'cc_cid' => $orderData['DadosCartaoCredito']['CodigoVerificador']
300
+ );
301
+ } else {
302
+ $paymentData = array('method' => 'optemais_modelc');
303
+ }
304
+
305
+ $quote->getShippingAddress()
306
+ ->addShippingRate($rate)
307
+ ->setShippingMethod($shippingMethodCode)
308
+ ->setPaymentMethod($paymentData['method'])
309
+ ->setCollectShippingRates(false)
310
+ ->collectTotals();
311
+
312
+ $quote->assignCustomer($customer);
313
+
314
+ Mage::unregister('order_created_by_optemais');
315
+ Mage::register('order_created_by_optemais', true);
316
+
317
+ $quote->getPayment()->setAdditionalInformation('created_by_optemais', true);
318
+ $quote->getPayment()->importData($paymentData);
319
+
320
+ if($ccInstallmentsKey) {
321
+ $quote->getPayment()->setAdditionalInformation($ccInstallmentsKey,$orderData['DadosCartaoCredito']['QuantidadeParcelas']);
322
+ }
323
+
324
+ $quote->save();
325
+
326
+ // Para os métodos de pagamento que pegam informações da Session
327
+ Mage::getSingleton('checkout/session')->setQuoteId($quote->getId());
328
+ Mage::getSingleton('checkout/session')->getQuote()->setCustomer($customer);
329
+
330
+ /** @var Mage_Sales_Model_Service_Quote $service */
331
+ $service = Mage::getModel('sales/service_quote', $quote);
332
+ $service->submitAll();
333
+
334
+ if ($service->getOrder()) {
335
+ $service->getOrder()->addStatusHistoryComment($helper->__('Pedido importado da CSU OPTe+'));
336
+ $service->getOrder()->save();
337
+ } else {
338
+ throw new Exception($helper->__('Não foi possível importar o pedido %s.', $orderData['PedidoParceiro']));
339
+ }
340
+ Mage::unregister('order_created_by_optemais');
341
+ return array(
342
+ 'Status' => true,
343
+ 'Mensagem' => null,
344
+ 'CodigoPedido' => $service->getOrder()->getIncrementId(),
345
+ 'PedidoParceiro' => $orderData['PedidoParceiro'],
346
+ );
347
+ } catch (Exception $e) {
348
+ Mage::unregister('order_created_by_optemais');
349
+ Mage::logException($e);
350
+ return array(
351
+ 'Status' => false,
352
+ 'Mensagem' => Mage::helper('adminhtml')->__($e->getMessage()),
353
+ 'CodigoPedido' => null,
354
+ 'PedidoParceiro' => $orderData['PedidoParceiro'],
355
+ );
356
+ }
357
+ }
358
+
359
+ public function _getConfigDataForPaymentMethod($method) {
360
+ $items = unserialize(Mage::getStoreConfig('optemais/config_order/payment_method'));
361
+ foreach($items['payment_method_code'] as $pos => $code) {
362
+ if($code == $method) {
363
+ return array(
364
+ 'code'=>$code,
365
+ 'qty_installments'=>$items['qty_installments'][$pos],
366
+ 'interest'=>$items['interest'][$pos],
367
+ 'param_installment'=>$items['param_installment'][$pos]
368
+ );
369
+ }
370
+ }
371
+ return array();
372
+ }
373
+
374
+ private function _validatesOrderData($orderData)
375
+ {
376
+ if (!$orderData) {
377
+ return array('status' => false, 'rows' => array('JSON inválido'));
378
+ }
379
+ $missing = array();
380
+ foreach ($this->_requiredOrderDataParams as $key => $value) {
381
+ if (is_array($value)) {
382
+ if (!isset($orderData[$key])) {
383
+ $missing[] = $key;
384
+ }
385
+ foreach ($value as $item) {
386
+ if (!isset($orderData[$key][$item])) {
387
+ $missing[] = $item;
388
+ }
389
+ }
390
+ } elseif (!isset($orderData[$value])) {
391
+ $missing[] = $value;
392
+ }
393
+ }
394
+ return array('status' => count($missing) == 0,'rows'=>$missing);
395
+ }
396
+
397
+ private function _validateDocument($document)
398
+ {
399
+ $document = str_replace(array(',', '-', '.', ' '), '', $document);
400
+ if (strlen($document) > 11) {
401
+ return 'pj';
402
+ }
403
+ return 'pf';
404
+ }
405
+
406
+ private function _getRegionIdByCode($code, $countryId)
407
+ {
408
+ if (!$this->_regions) {
409
+ $collection = Mage::getModel('directory/region')->getCollection();
410
+ $collection->addFieldToFilter('country_id', $countryId);
411
+ /** @var Mage_Directory_Model_Region $item */
412
+ foreach ($collection as $item) {
413
+ $this->_regions[$item->getCode()] = $item->getId();
414
+ }
415
+ }
416
+ return isset($this->_regions[$code]) ? $this->_regions[$code] : null;
417
+ }
418
+
419
+
420
+ protected function _getCountryId($city)
421
+ {
422
+ $collection = Mage::getModel('directory/region')->getResourceCollection();
423
+ $collection->addFieldToFilter('name', $city);
424
+ if (count($collection) < 1) {
425
+ $collection = null;
426
+ $collection = Mage::getModel('directory/region')->getResourceCollection();
427
+ $collection->addFieldToFilter('default_name', $city);
428
+ }
429
+ foreach ($collection as $item) {
430
+ return $item->getCountryId();
431
+ }
432
+ return self::DEFAULT_COUNTRY_ID;
433
+ }
434
+
435
+ protected function _getStreet($address, $number, $additionalInfo, $district)
436
+ {
437
+ $lines = Mage::getStoreConfig('customer/address/street_lines');
438
+ $lines = $lines ? $lines : 2;
439
+ if ($lines == 3) {
440
+ return $address . "\n" . $number . " " . $additionalInfo . "\n" . $district;
441
+ }
442
+ if ($lines == 4) {
443
+ return $address . "\n" . $number . "\n" . $additionalInfo . "\n" . $district;
444
+ }
445
+ return $address . " " . $number . "\n " . $additionalInfo . " " . $district;
446
+ }
447
+
448
+ private function _getParentIds(Mage_Catalog_Model_Product $product)
449
+ {
450
+ /** @var Mage_Catalog_Model_Resource_Product_Type_Configurable $resource */
451
+ $resource = Mage::getResourceSingleton('catalog/product_type_configurable');
452
+ $parentIds = $resource->getParentIdsByChild($product->getId());
453
+ return $parentIds ? $parentIds[0] : false;
454
+ }
455
+
456
+ private function _getAttributesByParentId($parentId)
457
+ {
458
+ $product = Mage::getModel('catalog/product')->load($parentId);
459
+ $attributes = array();
460
+ if (!$product->getId()) {
461
+ return $attributes;
462
+ }
463
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
464
+ foreach ($productAttributeOptions as $attribute) {
465
+ $attributes[] = array('id' => $attribute['attribute_id'], 'code' => $attribute['attribute_code']);
466
+ }
467
+ return $attributes;
468
+ }
469
+
470
+ public function changeStatus($params)
471
+ {
472
+ /** @var Mage_Sales_Model_Order $order */
473
+ try {
474
+ $orderIncrementId = isset($params['IdPedido']) && $params['IdPedido'] ? $params['IdPedido'] : false;
475
+ $status = isset($params['Status']) && $params['Status'] ? $params['Status'] : false;
476
+ if (!$orderIncrementId) {
477
+ return array('status' => false, 'invalid_params' => array('IdPedido'), 'data' => array('Confirmado' => false));
478
+ }
479
+ if (!$status || !in_array($status, $this->_validChangeStatus)) {
480
+ return array('status' => false, 'invalid_params' => array('Status'), 'data' => array('Confirmado' => false));
481
+ }
482
+ $order = Mage::getModel('sales/order');
483
+ $order->loadByIncrementId($orderIncrementId);
484
+ if ($order->getId()) {
485
+ if ($status == self::CHANGE_STATUS_APPROVED) {
486
+ if (!$this->_createInvoice($order)) {
487
+ throw new Exception(Mage::helper("optemais")->__('O status atual do pedido não permite aprovaçao'));
488
+ }
489
+ } else {
490
+ if (!$this->_cancel($order)) {
491
+ throw new Exception(Mage::helper("optemais")->__('O status atual do pedido não permite cancelamento'));
492
+ }
493
+ }
494
+ return array('status' => true, 'not_found' => false, 'data' => array('Confirmado' => true));
495
+ }
496
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Pedido'), 'data' => array('Confirmado' => false));
497
+ } catch (Exception $e) {
498
+ return array('status' => false, 'not_found' => false, 'message' => $e->getMessage(), 'data' => array('Confirmado' => false));
499
+ }
500
+ }
501
+
502
+ public function getTrackingInfo($params)
503
+ {
504
+ /** @var Mage_Sales_Model_Order $order */
505
+ try {
506
+ $orderIncrementId = isset($params['IdPedido']) && $params['IdPedido'] ? $params['IdPedido'] : false;
507
+ if (!$orderIncrementId) {
508
+ return array('status' => false, 'invalid_params' => array('IdPedido'));
509
+ }
510
+ $order = Mage::getModel('sales/order');
511
+ $order->loadByIncrementId($orderIncrementId);
512
+ if ($order->getId()) {
513
+ $statusHistory = array();
514
+ /** @var Mage_Sales_Model_Order_Status_History $status */
515
+ foreach ($order->getAllStatusHistory() as $status) {
516
+ $statusData = $this->_getStatusData($status->getStatus());
517
+ if (!$statusData['code']) continue;
518
+ $statusHistory[$status->getStatus()] = array(
519
+ 'CodDescricao' => $statusData['code'],
520
+ 'Descricao' => $statusData['label'],
521
+ 'Data' => Mage::helper('core')->formatDate($status->getCreatedAt(),Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true),
522
+ );
523
+ }
524
+ $trackingItems = array();
525
+ /** @var Mage_Sales_Model_Order_Item $item */
526
+ foreach ($order->getAllVisibleItems() as $item) {
527
+ $trackingItems[] = array(
528
+ 'Sku' => $item->getSku(),
529
+ 'Trackings' => $statusHistory,
530
+ );
531
+ }
532
+ $statusData = $this->_getStatusData($order->getStatus());
533
+ $data = array(
534
+ 'ProdutosTracking' => $trackingItems,
535
+ 'CodDescricao' => $statusData['code'],
536
+ 'Descricao' => $statusData['label'],
537
+ );
538
+ return array('status' => true, 'not_found' => false, 'data' => $data);
539
+ }
540
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Pedido'));
541
+ } catch (Exception $e) {
542
+ return array('status' => false, 'not_found' => false, 'message' => $e->getMessage());
543
+ }
544
+ }
545
+
546
+ public function getPaymentMethods($campaignId = null)
547
+ {
548
+ /** @var Mage_Sales_Model_Order $order */
549
+ try {
550
+ if($campaignId) {
551
+ $campaign = Mage::getModel('optemais/campaign')->load($campaignId);
552
+ if ($campaign->getId()) {
553
+ $data = array('FormaPagamento'=>$this->_getPaymentMethodsData($campaign->getPaymentMethods()));
554
+ return array('status' => true, 'not_found' => false, 'data' => $data);
555
+ }
556
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Campanha'));
557
+ } else {
558
+ $items = unserialize(Mage::getStoreConfig('optemais/config_order/payment_method'));
559
+ $data = array('FormaPagamento'=>$this->_getPaymentMethodsData($items));
560
+ return array('status' => true, 'not_found' => false, 'data' => $data);
561
+ }
562
+ } catch (Exception $e) {
563
+ return array('status' => false, 'not_found' => false, 'message' => $e->getMessage());
564
+ }
565
+ }
566
+
567
+ private function _getPaymentMethodsData($items)
568
+ {
569
+ $data = array();
570
+ if($items) {
571
+ $paymentMethods = array();
572
+ foreach($items['payment_method_code'] as $value) {
573
+ if(!$value) continue;
574
+ $ccTypes = $this->_getCcTypes($value);
575
+ if(count($ccTypes)>0) {
576
+ foreach($ccTypes as $ccType => $ccTypeCode) {
577
+ $paymentMethods[] = array('IdFormaPagamento' => $ccType, 'Nome' => Mage::getStoreConfig('payment/'.$value.'/title'), 'CodigoBandeira' => $ccTypeCode['cc_type']);
578
+ }
579
+ } else {
580
+ $paymentMethods[] = array('IdFormaPagamento' => $value, 'Nome' => Mage::getStoreConfig('payment/'.$value.'/title'), 'CodigoBandeira' => '');
581
+ }
582
+ }
583
+ $data = array($paymentMethods);
584
+ }
585
+ return $data;
586
+ }
587
+
588
+ private function _getMethodDataByCcType($ccType)
589
+ {
590
+ $ccTypes = $this->_getCcTypes();
591
+ return isset($ccTypes[$ccType]) ? $ccTypes[$ccType] : array('code'=>$ccType,'cc_type'=>null);
592
+ }
593
+
594
+ private function _getCcTypes($methodCode = null)
595
+ {
596
+ $items = array();
597
+ if($methodCode) {
598
+ $availableMethods = array($methodCode);
599
+ } else {
600
+ $allAvailablePaymentMethods = Mage::getModel('payment/config')->getAllMethods();
601
+ $availableMethods = array_keys($allAvailablePaymentMethods);
602
+ }
603
+ foreach($availableMethods as $methodCode) {
604
+ if ($method = Mage::helper('payment')->getMethodInstance($methodCode)) {
605
+ $availableTypes = $method->getConfigData('cctypes');
606
+ if ($availableTypes) {
607
+ $availableTypes = explode(',', $availableTypes);
608
+ foreach ($availableTypes as $availableType) {
609
+ $items[$methodCode .'_' . $availableType] = array('code' => $methodCode,'cc_type'=>$availableType);
610
+ }
611
+ }
612
+ }
613
+ }
614
+ return $items;
615
+ }
616
+
617
+ public function getInstallments($params)
618
+ {
619
+ try {
620
+ $paymentMethodId = isset($params['IdFormaPagamento']) && $params['IdFormaPagamento'] ? $params['IdFormaPagamento'] : false;
621
+ $campaignId = isset($params['IdCampanha']) && $params['IdCampanha'] ? $params['IdCampanha'] : false;
622
+ $queryValue = isset($params['ValorAParcelar']) && $params['ValorAParcelar'] ? $params['ValorAParcelar'] : false;
623
+ if (!$queryValue) {
624
+ return array('status' => false, 'invalid_params' => array('ValorAParcelar'));
625
+ }
626
+ if($campaignId) {
627
+ $campaign = Mage::getModel('optemais/campaign')->load($campaignId);
628
+ if ($campaign->getId()) {
629
+ $paymentMethods = $this->_getInstallmentsData($campaign->getPaymentMethods(),$queryValue,$paymentMethodId);
630
+ $data = array('OpcoesParcelamento'=>$paymentMethods);
631
+ return array('status' => true, 'not_found' => false, 'data' => $data);
632
+ }
633
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Campanha'));
634
+ } else {
635
+ $data = array('OpcoesParcelamento'=>array());
636
+ if($config = Mage::getStoreConfig('optemais/config_order/payment_method')) {
637
+ if($items = unserialize($config)) {
638
+ $paymentMethods = $this->_getInstallmentsData($items,$queryValue,$paymentMethodId);
639
+ if(!$paymentMethods && $paymentMethodId) {
640
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Forma de Pagamento'));
641
+ }
642
+ $data = array('OpcoesParcelamento'=>$paymentMethods);
643
+ }
644
+ }
645
+ return array('status' => true, 'not_found' => false, 'data' => $data);
646
+ }
647
+ } catch (Exception $e) {
648
+ return array('status' => false, 'not_found' => false, 'message' => $e->getMessage());
649
+ }
650
+ }
651
+
652
+ private function _getInstallmentsData($items,$queryValue,$paymentMethodId = null) {
653
+ $paymentMethods = array();
654
+ /** @var CsuMarketSystem_OpteMais_Helper_Data $helper */
655
+ $helper = Mage::helper('optemais');
656
+ foreach($items['payment_method_code'] as $key => $value) {
657
+ if(!$value) continue;
658
+ $queryValue = (float)str_replace(array(',','%'),array('.',''),$queryValue);
659
+ $qtyInstallments = $items['qty_installments'][$key] ? (integer)$items['qty_installments'][$key] : 1;
660
+ $interest = number_format((float)str_replace(array(',','%'),array('.',''),$items['interest'][$key]), 2, '.', '');
661
+ $priceWithInterest = (float)$interest > 0
662
+ ? $helper->getPriceWithInterest($queryValue,$interest,$qtyInstallments)
663
+ : $queryValue;
664
+ $ccTypes = $this->_getCcTypes($value);
665
+ if(count($ccTypes)>0) {
666
+ foreach($ccTypes as $ccType => $ccTypeCode) {
667
+ if($paymentMethodId && $ccType != $paymentMethodId) continue;
668
+ $paymentMethods[] = array(
669
+ 'IdFormaPagamento' => $ccType,
670
+ 'QuantidadeParcelas' => $items['qty_installments'][$key],
671
+ 'TaxaJurosAoMes' => $interest,
672
+ 'ValorParcela' => number_format((float)$priceWithInterest,2,'.',''),
673
+ 'ValorTotal' => number_format((float)$priceWithInterest*$qtyInstallments,2,'.',''),
674
+ );
675
+ }
676
+ } else {
677
+ if($paymentMethodId && $value != $paymentMethodId) continue;
678
+ $paymentMethods[] = array(
679
+ 'IdFormaPagamento' => $value,
680
+ 'QuantidadeParcelas' => $items['qty_installments'][$key],
681
+ 'TaxaJurosAoMes' => $interest,
682
+ 'ValorParcela' => number_format((float)$priceWithInterest,2,'.',''),
683
+ 'ValorTotal' => number_format((float)$priceWithInterest*$qtyInstallments,2,'.',''),
684
+ );
685
+ }
686
+ }
687
+ return $paymentMethods;
688
+ }
689
+
690
+ private function _getStatusData($orderStatusCode)
691
+ {
692
+ if (!$this->_statuses) {
693
+ foreach ($this->_optemaisStatuses as $code => $label) {
694
+ if ($config = Mage::getStoreConfig('optemais/config_order_status/' . $this->_configStatuses[$code])) {
695
+ $this->_statuses[$config] = array('code' => $code, 'label' => Mage::helper('optemais')->__($label));
696
+ }
697
+ }
698
+ }
699
+ $statusCode = isset($this->_statuses[$orderStatusCode]['code'])
700
+ ? $this->_statuses[$orderStatusCode]['code']
701
+ : null;
702
+ $statusLabel = isset($this->_statuses[$orderStatusCode]['label'])
703
+ ? $this->_statuses[$orderStatusCode]['label']
704
+ : null;
705
+ return array('code' => $statusCode, 'label' => $statusLabel);
706
+ }
707
+
708
+ /**
709
+ * Create invoice
710
+ *
711
+ * @param Mage_Sales_Model_Order @order
712
+ *
713
+ * @return int|bool
714
+ */
715
+ protected function _createInvoice(Mage_Sales_Model_Order $order)
716
+ {
717
+ if (!$order->canInvoice()) {
718
+ return false;
719
+ }
720
+ $invoice = $order->prepareInvoice(array());
721
+ if ($invoice) {
722
+ $invoice->register()->pay();
723
+ $invoice->addComment(Mage::helper('optemais')->__("Pedido Aprovado pela OPTe+"));
724
+ $invoice->getOrder()->setIsInProcess(true);
725
+ Mage::getModel('core/resource_transaction')
726
+ ->addObject($invoice)
727
+ ->addObject($invoice->getOrder())
728
+ ->save();
729
+ $order->addStatusHistoryComment(Mage::helper('optemais')->__("Pedido Aprovado pela OPTe+"));
730
+ $order->save();
731
+ return $invoice->getIncrementId();
732
+ }
733
+ return true;
734
+ }
735
+
736
+ /**
737
+ * Create new credit memo for order
738
+ *
739
+ * @param Mage_Sales_Model_Order @order
740
+ *
741
+ * @return int|bool
742
+ */
743
+ protected function _createCreditMemo(Mage_Sales_Model_Order $order)
744
+ {
745
+ /** @var $service Mage_Sales_Model_Service_Order */
746
+ $service = Mage::getModel('sales/service_order', $order);
747
+ /** @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
748
+ $creditmemo = $service->prepareCreditmemo(array());
749
+ if ($creditmemo) {
750
+ $creditmemo->setPaymentRefundDisallowed(true)->register();
751
+ $creditmemo->addComment(Mage::helper('optemais')->__("Pedido Cancelado/Devolvido pela OPTe+"));
752
+ Mage::getModel('core/resource_transaction')
753
+ ->addObject($creditmemo)
754
+ ->addObject($creditmemo->getOrder())
755
+ ->save();
756
+ return $creditmemo->getIncrementId();
757
+ }
758
+ return false;
759
+ }
760
+
761
+ /**
762
+ * Cancel order
763
+ *
764
+ * @param Mage_Sales_Model_Order @order
765
+ *
766
+ * @return bool
767
+ */
768
+ protected function _cancel(Mage_Sales_Model_Order $order)
769
+ {
770
+ if (($order->hasInvoices() || $order->hasShipments()) && $order->canCreditmemo()) {
771
+ return $this->_createCreditMemo($order, Mage::helper('optemais')->__("Pedido Cancelado pela OPTe+"));
772
+ }
773
+ if (!$order->canCancel()) {
774
+ return false;
775
+ }
776
+ $order->addStatusHistoryComment("Pedido Cancelado pela OPTe+", Mage_Sales_Model_Order::STATE_CANCELED);
777
+ $order->cancel();
778
+ $order->save();
779
+ return true;
780
+ }
781
+
782
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Payment/Modelc.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Payment_Modelc extends Mage_Payment_Model_Method_Abstract
15
+ {
16
+ protected $_code = 'optemais_modelc';
17
+ protected $_infoBlockType = 'optemais/payment_info_modelc';
18
+ protected $_canUseCheckout = false;
19
+
20
+ public function isAvailable($quote = null)
21
+ {
22
+ return Mage::registry('order_created_by_optemais');
23
+ }
24
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Product.php ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Product
15
+ {
16
+
17
+ const MODE_FULL = 'full';
18
+ const MODE_PARTIAL = 'partial';
19
+ const IMAGE_FULL = 'Grande';
20
+ const IMAGE_SMALL = 'Media';
21
+ const IMAGE_THUMBNAIL = 'Pequena';
22
+
23
+ /** @var Mage_Catalog_Model_Resource_Category_Collection */
24
+ protected $_categoryCollection = null;
25
+
26
+ protected $_productCollection = null;
27
+ protected $_parentCategories = array();
28
+ protected $_productParentChildIs = array();
29
+ protected $_totalRecords = 0;
30
+
31
+ public function getProducts($mode = self::MODE_FULL, $fromHours = 0, $currentPage = 0)
32
+ {
33
+ $collection = $this->_getProductCollection($currentPage);
34
+ $items = array();
35
+ $descriptionAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_description');
36
+ $brandAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_brand');
37
+ $colorAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_color');
38
+ $sizeAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_size');
39
+ $voltageAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_voltage');
40
+ $eanAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_ean');
41
+ $refIdAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_refid');
42
+ $useParentImages = Mage::getStoreConfig('optemais/config_product/use_parent_images');
43
+ $fromHours = strtotime("-$fromHours hours");
44
+ /** @var $p Mage_Catalog_Model_Product */
45
+ foreach ($collection as $p) {
46
+ $categories = $this->_getParentCategories($p);
47
+ // Não é aceito produtos sem categorias
48
+ if (!$categories) {
49
+ continue;
50
+ }
51
+ $categoryIds = implode("/", array_keys($categories));
52
+ $skus = array();
53
+ if ($p->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
54
+ $childProducts = isset($this->_productParentChildIs[$p->getId()]) ? $this->_productParentChildIs[$p->getId()] : array();
55
+ if ($childProducts) {
56
+ $hasChangedParent = strtotime($p->getUpdatedAt()) >= $fromHours;
57
+ $hasChangedChild = false;
58
+ /** @var $child Mage_Catalog_Model_Product */
59
+ foreach ($childProducts as $childId) {
60
+ $child = Mage::getModel('catalog/product')->load($childId);
61
+ if ($mode == self::MODE_PARTIAL && (strtotime($child->getUpdatedAt()) >= $fromHours)) {
62
+ $hasChangedChild = true;
63
+ }
64
+ $skuSpecification = $this->_getSkuSpecifications($child);
65
+ if (!$skuSpecification) {
66
+ continue;
67
+ }
68
+ /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
69
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($child);
70
+ $stockQty = intval($stockItem->getQty());
71
+ if (Mage::getStoreConfigFlag('optemais/config_product/discount_min_qty')) {
72
+ $stockQty -= intval($stockItem->getMinQty());
73
+ }
74
+ if ($stockQty < 0) {
75
+ $stockQty = 0;
76
+ }
77
+ $skus[] = array(
78
+ 'CodSku' => $child->getSku(),
79
+ 'PrecoDe' => number_format((float)$child->getPrice(), 2, '.', ''),
80
+ 'PrecoPor' => number_format((float)$child->getFinalPrice(), 2, '.', ''),
81
+ 'Estoque' => intval($stockQty),
82
+ 'Ativo' => $child->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED ? true : false,
83
+ 'Cor' => $child->getData($colorAttribute) && $colorAttribute ? $child->getAttributeText($colorAttribute) : '',
84
+ 'Tamanho' => $child->getData($sizeAttribute) && $sizeAttribute ? $child->getAttributeText($sizeAttribute) : '',
85
+ 'Voltagem' => $child->getData($voltageAttribute) && $voltageAttribute ? $child->getAttributeText($voltageAttribute) : '',
86
+ 'IdsAlternativo' => array(
87
+ 'Ean' => $child->getData($eanAttribute) && $eanAttribute ? $child->getData($eanAttribute) : '',
88
+ 'RefId' => $child->getData($refIdAttribute) && $refIdAttribute ? $child->getData($refIdAttribute) : '',
89
+ ),
90
+ 'EspecificacaoSku' => $skuSpecification,
91
+ 'Imagens' => $this->_getImages($child, $p, $useParentImages)
92
+ );
93
+ }
94
+ if ($mode == self::MODE_PARTIAL && !$hasChangedChild && !$hasChangedParent) {
95
+ continue;
96
+ }
97
+ }
98
+ } else {
99
+ if ($mode == self::MODE_PARTIAL && (strtotime($p->getUpdatedAt()) < $fromHours)) {
100
+ continue;
101
+ }
102
+ $skuSpecification = $this->_getSkuSpecifications($p);
103
+ if (!$skuSpecification) {
104
+ continue;
105
+ }
106
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($p);
107
+ $stockQty = intval($stockItem->getQty());
108
+ if (Mage::getStoreConfigFlag('optemais/config_product/discount_min_qty')) {
109
+ $stockQty -= intval($stockItem->getMinQty());
110
+ }
111
+ if ($stockQty < 0) {
112
+ $stockQty = 0;
113
+ }
114
+ $skus[] = array(
115
+ 'CodSku' => $p->getSku(),
116
+ 'PrecoDe' => number_format((float)$p->getPrice(), 2, '.', ''),
117
+ 'PrecoPor' => number_format((float)$p->getFinalPrice(), 2, '.', ''),
118
+ 'Estoque' => intval($stockQty),
119
+ 'Ativo' => $p->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED ? true : false,
120
+ 'Cor' => $p->getData($colorAttribute) && $colorAttribute ? $p->getAttributeText($colorAttribute) : '',
121
+ 'Tamanho' => $p->getData($sizeAttribute) && $sizeAttribute ? $p->getAttributeText($sizeAttribute) : '',
122
+ 'Voltagem' => $p->getData($voltageAttribute) && $voltageAttribute ? $p->getAttributeText($voltageAttribute) : '',
123
+ 'IdsAlternativo' => array(
124
+ 'Ean' => $p->getData($eanAttribute) && $eanAttribute ? $p->getData($eanAttribute) : '',
125
+ 'RefId' => $p->getData($refIdAttribute) && $refIdAttribute ? $p->getData($refIdAttribute) : '',
126
+ ),
127
+ 'EspecificacaoSku' => $this->_getSkuSpecifications($p),
128
+ 'Imagens' => $this->_getImages($p)
129
+ );
130
+ }
131
+ $items[] = array(
132
+ 'CodProduto' => $p->getId(),
133
+ 'DescricaoDetalhaProduto' => $p->getData($descriptionAttribute),
134
+ 'NomeProduto' => $p->getName(),
135
+ 'IdMarca' => $p->getData($brandAttribute),
136
+ 'NomeMarca' => $p->getData($brandAttribute) && $brandAttribute ? $p->getAttributeText($brandAttribute) : '',
137
+ 'IdsCategorias' => $categoryIds,
138
+ 'Categorias' => $categories,
139
+ 'Sku' => $skus,
140
+ 'EspecificacaoProduto' => $this->_getProductSpecifications($p),
141
+ );
142
+ }
143
+ $result = array(
144
+ 'data' => array()
145
+ );
146
+ if ($currentPage) {
147
+ $pageSize = Mage::getStoreConfig('optemais/config_product/items_per_page');
148
+ $pagesCount = ceil($this->_totalRecords / $pageSize);
149
+ $result['data']['current_page'] = $currentPage;
150
+ $result['data']['pages_count'] = $pagesCount <= 0 ? 1 : $pagesCount;
151
+ }
152
+ $result['data']['rows_count'] = count($items);
153
+ $result['data']['rows'] = $items;
154
+ return $result;
155
+ }
156
+
157
+ public function getAvailabilityProducts($currentPage = 0)
158
+ {
159
+ $items = array();
160
+ $collection = $this->_getProductCollection($currentPage,true);
161
+ /** @var $p Mage_Catalog_Model_Product */
162
+ foreach ($collection as $p) {
163
+ if ($p->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
164
+ $childProducts = isset($this->_productParentChildIs[$p->getId()]) ? $this->_productParentChildIs[$p->getId()] : array();
165
+ if ($childProducts) {
166
+ /** @var $child Mage_Catalog_Model_Product */
167
+ foreach ($childProducts as $childId) {
168
+ $child = Mage::getModel('catalog/product')->load($childId);
169
+ $items[] = $this->_getAvailabilityDataProducts($child);
170
+ }
171
+ }
172
+ } else {
173
+ $items[] = $this->_getAvailabilityDataProducts($p);
174
+ }
175
+ }
176
+ $result = array(
177
+ 'data' => array()
178
+ );
179
+ if ($currentPage) {
180
+ $pageSize = Mage::getStoreConfig('optemais/config_product/items_per_page');
181
+ $pagesCount = ceil($collection->getSize() / $pageSize);
182
+ $result['data']['current_page'] = $currentPage;
183
+ $result['data']['pages_count'] = $pagesCount <= 0 ? 1 : $pagesCount;
184
+ }
185
+ $result['data']['rows_count'] = count($items);
186
+ $result['data']['rows'] = $items;
187
+ return $result;
188
+ }
189
+
190
+ private function _getAvailabilityDataProducts($product) {
191
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
192
+ $stockQty = intval($stockItem->getQty());
193
+ if (Mage::getStoreConfigFlag('optemais/config_product/discount_min_qty')) {
194
+ $stockQty -= intval($stockItem->getMinQty());
195
+ }
196
+ if ($stockQty < 0) {
197
+ $stockQty = 0;
198
+ }
199
+ $campaignItems = Mage::getModel('optemais/campaign_item')->getItemsByParams(
200
+ array(
201
+ 'product_id' => $product->getId(),
202
+ )
203
+ );
204
+ $campaigns = array();
205
+ if ($campaignItems) {
206
+ foreach ($campaignItems as $campaignItem) {
207
+ /** @var CsuMarketSystem_OpteMais_Model_Campaign $campaign */
208
+ $campaign = Mage::getModel('optemais/campaign')->load($campaignItem['campaign_id']);
209
+ if ($campaign->isValid()) {
210
+ $campaigns[] = array(
211
+ 'IdCampanha' => $campaignItem['campaign_id'],
212
+ 'PrecoCampanha' => number_format((float)$campaignItem['price'], 2, '.', ''),
213
+ 'EstoqueCampanha' => intval($campaignItem['stock_qty']),
214
+ 'ProdutoDisponivel' => $campaignItem['stock_qty'] > 0,
215
+ );
216
+ }
217
+ }
218
+ }
219
+ return array(
220
+ 'CodSku' => $product->getSku(),
221
+ 'CodProduto' => $product->getId(),
222
+ 'PrecoDe' => number_format((float)$product->getPrice(), 2, '.', ''),
223
+ 'PrecoPor' => number_format((float)$product->getFinalPrice(), 2, '.', ''),
224
+ 'Estoque' => intval($stockQty),
225
+ 'ProdutoDisponivel' => $stockQty > 0,
226
+ 'Campanha' => $campaigns,
227
+ );
228
+ }
229
+
230
+ /**
231
+ * @param $currentPage integer
232
+ * @param $onlyStock boolean
233
+ *
234
+ * @return Mage_Catalog_Model_Resource_Product_Collection
235
+ */
236
+ private function _getProductCollection($currentPage = 0, $onlyStock = false) {
237
+ if (is_null($this->_productCollection)) {
238
+ $this->_prepareProductCollection($currentPage,$onlyStock);
239
+ }
240
+ return $this->_productCollection;
241
+ }
242
+
243
+ private function _prepareProductCollection($currentPage = 0, $onlyStock = false) {
244
+ /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
245
+ $collection = Mage::getModel('catalog/product')->getCollection();
246
+ $collection->joinField(
247
+ 'category_id', 'catalog/category_product', 'category_id',
248
+ 'product_id = entity_id', null, 'inner'
249
+ );
250
+ if(!$onlyStock) $collection->addPriceData();
251
+ $collection->addAttributeToSelect('*')->addCategoryIds();
252
+ $collection->addAttributeToFilter(
253
+ 'type_id', array('in' => array(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
254
+ Mage_Catalog_Model_Product_Type::TYPE_SIMPLE))
255
+ );
256
+ $collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
257
+ $collection->addAttributeToFilter('entity_id', array('nin' => $this->_getProductChildren()));
258
+ if (Mage::getStoreConfigFlag('optemais/config_product/ignore_invisible')) {
259
+ $collection->addAttributeToFilter('visibility', array('neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE));
260
+ }
261
+ $this->_totalRecords = $collection->getSize();
262
+ $collection->getSelect()->group('e.entity_id');
263
+ $pageSize = Mage::getStoreConfig('optemais/config_product/items_per_page');
264
+ if ($currentPage && $pageSize) {
265
+ $collection->getSelect()->limitPage($currentPage, $pageSize);
266
+ }
267
+ $this->_productCollection = $collection;
268
+ }
269
+
270
+ public function _getProductChildren()
271
+ {
272
+ /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
273
+ $collection = Mage::getModel('catalog/product')->getCollection();
274
+ $collection->addAttributeToFilter('type_id', array('in' => array(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)));
275
+ $collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
276
+ $children = array();
277
+ foreach ($collection as $p) {
278
+ $childIds = $p->getTypeInstance(true)->getChildrenIds($p->getId(), false);
279
+ $this->_productParentChildIs[$p->getId()] = current($childIds);
280
+ if (is_array($childIds)) {
281
+ $children += current($childIds);
282
+ }
283
+ }
284
+ unset($collection);
285
+ return $children;
286
+ }
287
+
288
+ /**
289
+ * @return Mage_Catalog_Model_Resource_Category_Collection|Mage_Catalog_Model_Resource_Category_Flat_Collection
290
+ */
291
+ private function _getCategoryCollection()
292
+ {
293
+ if (is_null($this->_categoryCollection)) {
294
+ $this->_prepareCategoryCollection();
295
+ }
296
+ return $this->_categoryCollection;
297
+ }
298
+
299
+ private function _prepareCategoryCollection()
300
+ {
301
+ if (!Mage::app()->isSingleStoreMode()) {
302
+ $oldStore = Mage::app()->getStore()->getId();
303
+ Mage::app()->setCurrentStore(0);
304
+ }
305
+ $this->_categoryCollection = Mage::getModel('catalog/category')->getCollection()
306
+ ->addAttributeToSelect('*')
307
+ ->addIsActiveFilter()
308
+ ->addNameToResult();
309
+ if (!Mage::app()->isSingleStoreMode()) {
310
+ Mage::app()->setCurrentStore($oldStore);
311
+ } else {
312
+ if (Mage::helper('catalog/category_flat')->isEnabled()) {
313
+ $this->_categoryCollection->addStoreFilter();
314
+ }
315
+ }
316
+ }
317
+
318
+ private function _getParentCategories(Mage_Catalog_Model_Product $product) {
319
+ $tree = array();
320
+ $categoryCollection = $this->_getCategoryCollection();
321
+ if (!$categoryCollection) {
322
+ return array();
323
+ }
324
+ $categoryIds = $product->getCategoryIds();
325
+ $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
326
+ if ($categoryIds) {
327
+ foreach ($categoryIds as $categoryId) {
328
+ if ($categoryId == $rootCategoryId) {
329
+ continue;
330
+ }
331
+ /** @var Mage_Catalog_Model_Category $category */
332
+ if ($category = $categoryCollection->getItemById($categoryId)) {
333
+ $path = array();
334
+ $pathInStore = $category->getPathInStore();
335
+ $pathIds = array_reverse(explode(',', $pathInStore));
336
+ $categories = $category->getParentCategories();
337
+ // Para o caso de categorias pais desativadas
338
+ if (count($pathIds) != count($categories)) {
339
+ continue;
340
+ }
341
+ foreach ($pathIds as $id) {
342
+ if ($id == $rootCategoryId) {
343
+ continue;
344
+ }
345
+ if (isset($categories[$id]) && $categories[$id]->getName()) {
346
+ $path[$id] = $categories[$id]->getName();
347
+ }
348
+ }
349
+ $tree[] = $path;
350
+ }
351
+ }
352
+ }
353
+ $max = 0;
354
+ foreach ($tree as $key => $value) {
355
+ if (count($value) > $max) {
356
+ $max = $key;
357
+ }
358
+ }
359
+ return count($tree) > 0 ? $tree[$max] : $tree;
360
+ }
361
+
362
+
363
+ private function _getImages(Mage_Catalog_Model_Product $product, $parentProduct = null, $useParentImages = false) {
364
+ /** @var Mage_Catalog_Model_Product $product */
365
+ if (!$product->getMediaGallery('images')) {
366
+ $product->load('media_gallery');
367
+ }
368
+ $images = $product->getMediaGallery('images');
369
+ if (!$images && is_object($parentProduct) && $useParentImages) {
370
+ $product = $parentProduct;
371
+ $product->load('media_gallery');
372
+ $images = $product->getMediaGallery('images');
373
+ }
374
+ $items = array();
375
+ foreach ($images as $image) {
376
+ if($image['disabled'] == "1") continue;
377
+ $items[] = array(
378
+ 'ImagemUrl' => $product->getMediaConfig()->getMediaUrl($image['file']),
379
+ 'ImagemNome' => basename($image['file']),
380
+ 'ImagemTamanho' => self::IMAGE_THUMBNAIL,
381
+ 'ImagemId' => isset($image['value_id']) ? $image['value_id'] : null,
382
+ 'Ordem' => $image['position']
383
+ );
384
+ $items[] = array(
385
+ 'ImagemUrl' => $product->getMediaConfig()->getMediaUrl($image['file']),
386
+ 'ImagemNome' => basename($image['file']),
387
+ 'ImagemTamanho' => self::IMAGE_SMALL,
388
+ 'ImagemId' => isset($image['value_id']) ? $image['value_id'] : null,
389
+ 'Ordem' => $image['position']
390
+ );
391
+ $items[] = array(
392
+ 'ImagemUrl' => $product->getMediaConfig()->getMediaUrl($image['file']),
393
+ 'ImagemNome' => basename($image['file']),
394
+ 'ImagemTamanho' => self::IMAGE_FULL,
395
+ 'ImagemId' => isset($image['value_id']) ? $image['value_id'] : null,
396
+ 'Ordem' => $image['position']
397
+ );
398
+ }
399
+ return $items;
400
+ }
401
+
402
+ private function _getProductSpecifications(Mage_Catalog_Model_Product $product) {
403
+ $items = array();
404
+ if ($attributes = Mage::getStoreConfig('optemais/config_attribute/product_specifications')) {
405
+ $attributes = explode(",", $attributes);
406
+ foreach ($attributes as $attributeCode) {
407
+ $attributeValue = $product->getResource()->getAttribute($attributeCode)->getFrontend()->getValue($product);
408
+ $attributeLabel = $product->getResource()->getAttribute($attributeCode)->getFrontend()->getLabel();
409
+ $attributeId = $product->getResource()->getAttribute($attributeCode)->getId();
410
+ $items[] = array(
411
+ 'IdEspecificacaoProduto' => $attributeId,
412
+ 'NomeEspecificacaoProduto' => $attributeLabel,
413
+ 'ValorEspecificacaoProduto' => $attributeValue,
414
+ );
415
+ }
416
+ }
417
+ return $items;
418
+ }
419
+
420
+ private function _getSkuSpecifications(Mage_Catalog_Model_Product $product) {
421
+ $items = array();
422
+ $attributes = array();
423
+ if ($colorAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_color')) {
424
+ $attributes[] = $colorAttribute;
425
+ }
426
+ if ($sizeAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_size')) {
427
+ $attributes[] = $sizeAttribute;
428
+ }
429
+ if ($voltageAttribute = Mage::getStoreConfig('optemais/config_attribute/attribute_product_voltage')) {
430
+ $attributes[] = $voltageAttribute;
431
+ }
432
+ foreach ($attributes as $attributeCode) {
433
+ if (!$product->getData($attributeCode)) {
434
+ continue;
435
+ }
436
+ $attributeValue = $product->getResource()->getAttribute($attributeCode)->getFrontend()->getValue($product);
437
+ $attributeLabel = $product->getResource()->getAttribute($attributeCode)->getFrontend()->getLabel();
438
+ $attributeId = $product->getResource()->getAttribute($attributeCode)->getId();
439
+ if ($attributeValue && $product->getResource()->getAttribute($attributeCode)->getIsConfigurable()) {
440
+ $items[] = array(
441
+ 'IdEspecificacaoSku' => $attributeId,
442
+ 'NomeEspecificacaoSku' => $attributeLabel,
443
+ 'ValorEspecificacaoSku' => $attributeValue,
444
+ );
445
+ }
446
+ }
447
+ return $items;
448
+ }
449
+
450
+ public function getProductBySku($sku) {
451
+ try {
452
+ /** @var Mage_Catalog_Model_Product $product */
453
+ $product = Mage::getModel('catalog/product');
454
+ $product->load($product->getIdBySku($sku));
455
+ if ($product->getId()) {
456
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
457
+ $stockQty = intval($stockItem->getQty());
458
+ if (Mage::getStoreConfigFlag('optemais/config_product/discount_min_qty')) {
459
+ $stockQty -= intval($stockItem->getMinQty());
460
+ }
461
+ if ($stockQty < 0) {
462
+ $stockQty = 0;
463
+ }
464
+ $data = array(
465
+ 'Sku' => $product->getSku(),
466
+ 'PrecoDe' => number_format((float)$product->getPrice(), 2, '.', ''),
467
+ 'PrecoPor' => number_format((float)$product->getFinalPrice(), 2, '.', ''),
468
+ 'QuantidadeEstoque' => $stockQty,
469
+ 'FlagDisponivel' => $stockQty > 0 && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
470
+ 'Nome' => $product->getName(),
471
+ );
472
+ return array('status' => true, 'not_found' => false, 'data' => $data);
473
+ }
474
+ return array('status' => false, 'not_found' => true, 'message' => Mage::helper('optemais')->__('Produto'));
475
+
476
+ } catch (Exception $e) {
477
+ return array('status' => false, 'not_found' => false, 'message' => $e->getMessage());
478
+ }
479
+ }
480
+
481
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Resource_Campaign extends Mage_Core_Model_Resource_Db_Abstract
15
+ {
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('optemais/campaign', 'entity_id');
20
+ }
21
+
22
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Collection.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Resource_Campaign_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
15
+ {
16
+
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->_init('optemais/campaign');
21
+ }
22
+
23
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Item.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Resource_Campaign_Item extends Mage_Core_Model_Resource_Db_Abstract
15
+ {
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('optemais/campaign_item', 'entity_id');
20
+ }
21
+
22
+ public function getItemsByParams($params, $limit = null)
23
+ {
24
+ $adapter = $this->_getReadAdapter();
25
+ $select = $adapter->select()
26
+ ->from($this->getMainTable(), '*');
27
+ foreach ($params as $field => $value) {
28
+ $select->where("$field = ?", $value);
29
+ }
30
+ if ($limit) {
31
+ $select->limit($limit);
32
+ }
33
+ return $adapter->fetchAll($select);
34
+ }
35
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Resource/Campaign/Item/Collection.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Resource_Campaign_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
15
+ {
16
+
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->_init('optemais/campaign_item');
21
+ }
22
+
23
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Response.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Response
15
+ {
16
+
17
+ protected $_status;
18
+ protected $_statusKey;
19
+ protected $_message;
20
+ protected $_messageKey;
21
+
22
+ public function setStatusKey($status)
23
+ {
24
+ $this->_statusKey = $status;
25
+ }
26
+
27
+ public function setStatusValue($status)
28
+ {
29
+ $this->_status = $status;
30
+ }
31
+
32
+ public function setMessageKey($message)
33
+ {
34
+ $this->_messageKey = $message;
35
+ }
36
+
37
+ public function setMessageValue($message)
38
+ {
39
+ $this->_message = $message;
40
+ }
41
+
42
+ public function getResponseData($responseData, $httpResponse)
43
+ {
44
+ $response = array(
45
+ $this->_statusKey => $this->_status,
46
+ $this->_messageKey => $this->_message,
47
+ );
48
+ if ($responseData && is_array($responseData)) {
49
+ $response += $responseData;
50
+ }
51
+ $httpResponse->setBody(json_encode($response));
52
+ $statusCode = is_bool($this->_status) ? 200 : $this->_status;
53
+ return $httpResponse->setHttpResponseCode($statusCode);
54
+ }
55
+
56
+
57
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Shipping.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Shipping
15
+ {
16
+
17
+ public function getShippingRates($params)
18
+ {
19
+ $zipCode = isset($params['CepEntrega']) ? preg_replace('/[^0-9]/', '', $params['CepEntrega']) : false;
20
+ $campaignId = isset($params['IdCampanha']) ? $params['IdCampanha'] : null;
21
+ $items = isset($params['ProdutoFrete']) ? $params['ProdutoFrete'] : array();
22
+ $response = array();
23
+ $response['status'] = false;
24
+ if ($zipCode && $items) {
25
+ $freightDiscount = 0;
26
+ if ($campaignId) {
27
+ /** @var CsuMarketSystem_OpteMais_Model_Campaign $campaign */
28
+ $campaign = Mage::getModel('optemais/campaign')->load($campaignId);
29
+ if ($campaign->isValid()) {
30
+ $freightDiscount = $campaign->getFreightDiscount();
31
+ }
32
+ }
33
+ $cartInfo = array();
34
+ /** @var $estimateRate CsuMarketSystem_OpteMais_Model_Estimate_Rate */
35
+ $estimateRate = Mage::getSingleton('optemais/estimate_rate');
36
+ $configDeliveryTimeVariable = Mage::getStoreConfig('optemais/config_shipping/delivery_time_variable');
37
+ $configDeliveryTimeDefault = Mage::getStoreConfig('optemais/config_shipping/delivery_time_default');
38
+ $configPriceType = Mage::getStoreConfig('optemais/config_shipping/price_type');
39
+ try {
40
+ $itemsRate = array();
41
+ $biggestRateDeliveryTime = 0;
42
+ foreach ($items as $item) {
43
+ /** @var $product Mage_Catalog_Model_Product */
44
+ $product = Mage::getModel('catalog/product');
45
+ $product->load($product->getIdBySku($item['Sku']));
46
+ if ($product) {
47
+ $cInfo = array(
48
+ 'product' => $product->getId(),
49
+ 'qty' => $item['Quantidade'],
50
+ );
51
+ $cartInfo[] = $cInfo;
52
+ $product->setAddToCartInfo($cInfo);
53
+ $estimateRate->setProduct($product);
54
+ $addressInfo = array(
55
+ 'cart' => 0,
56
+ 'country_id' => "BR",
57
+ 'postcode' => $zipCode
58
+ );
59
+ /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
60
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
61
+ $estimateRate->setAddressInfo($addressInfo);
62
+ if (!empty($cartInfo) || !empty($addressInfo)) {
63
+ try {
64
+ $result = $estimateRate->estimate();
65
+ $price = 0;
66
+ if (is_array($result)) {
67
+ foreach ($result as $rates) {
68
+ foreach ($rates as $rate) {
69
+ $deliveryTime = $rate->getData($configDeliveryTimeVariable)
70
+ ? $rate->getData($configDeliveryTimeVariable)
71
+ : $configDeliveryTimeDefault;
72
+ $skip = true;
73
+ if ($configPriceType == CsuMarketSystem_OpteMais_Model_Source_Shipping_Pricetype::BIGGEST_PRICE && $price < $rate->getPrice()) {
74
+ $price = $rate->getPrice();
75
+ $skip = false;
76
+ } elseif ($price > $rate->getPrice() || $price == 0) {
77
+ $price = $rate->getPrice();
78
+ $skip = false;
79
+ }
80
+ if (!$skip) {
81
+ $price = $freightDiscount > 0 && $price > 0
82
+ ? $price - ($price * ($freightDiscount / 100))
83
+ : $price;
84
+ $itemsRate['Sku'] = $product->getSku();
85
+ $itemsRate['ValorFrete'] = $price;
86
+ $itemsRate['QuantidadeEstoque'] = intval($stockItem->getQty());
87
+ $itemsRate['FlagDisponivel'] = $stockItem->getQty() > 0;
88
+ $itemsRate['TempoEntrega'] = intval($deliveryTime);
89
+ $itemsRate['Mensagem'] = $rate->getErrorMessage();
90
+ if ($biggestRateDeliveryTime < $deliveryTime) {
91
+ $biggestRateDeliveryTime = $deliveryTime;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ $response['status'] = true;
98
+ } catch (Exception $e) {
99
+ $response['message'] = Mage::helper('optemais')->__($e->getMessage());
100
+ Mage::logException($e);
101
+ return $response;
102
+ }
103
+ }
104
+ }
105
+ unset($cartInfo);
106
+ $estimateRate->resetQuote();
107
+ }
108
+
109
+ if (!$itemsRate) {
110
+ throw new Exception(Mage::helper('optemais')->__('Sem resultados para os parâmetros informados'));
111
+ }
112
+
113
+ $response['data'] = array();
114
+ $response['data']['ValorTotalFrete'] = $itemsRate['ValorFrete'];
115
+ $response['data']['TempoEntrega'] = intval($biggestRateDeliveryTime);
116
+ $response['data']['ItensFrete'] = $itemsRate;
117
+ $response['data']['Status'] = true;
118
+ $response['data']['Mensagem'] = '';
119
+ } catch (Exception $e) {
120
+ $response['message'] = Mage::helper('optemais')->__($e->getMessage());
121
+ $response['status'] = false;
122
+ Mage::logException($e);
123
+ }
124
+ } else {
125
+ if (!$zipCode) {
126
+ $response['invalid_params'][] = 'CEP';
127
+ }
128
+ if (!$items) {
129
+ $response['invalid_params'][] = 'Produtos';
130
+ }
131
+ }
132
+ return $response;
133
+ }
134
+
135
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Attributes.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Attributes
15
+ {
16
+ /**
17
+ * Retrieves attributes
18
+ *
19
+ * @return array
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ $attributes = Mage::getModel('catalog/product')->getResource()
24
+ ->loadAllAttributes()
25
+ ->getAttributesByCode();
26
+
27
+ $result = array();
28
+ $result[] = array(
29
+ 'value' => '',
30
+ 'label' => Mage::helper('adminhtml')->__('-- Please Select --')
31
+ );
32
+ foreach ($attributes as $attribute) {
33
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
34
+ if ($attribute->getId() && !in_array($attribute->getFrontendInput(), array('multiselect', 'select'))) {
35
+ $result[] = array(
36
+ 'value' => $attribute->getAttributeCode(),
37
+ 'label' => $attribute->getFrontend()->getLabel(),
38
+ );
39
+ }
40
+ }
41
+ return $result;
42
+ }
43
+
44
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Campaign/Actions.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Campaign_Actions
15
+ {
16
+
17
+ const ACTION_NEW = 1;
18
+ const ACTION_EXISTING = 2;
19
+
20
+ public function getOptions()
21
+ {
22
+ return array(
23
+ array('value' => self::ACTION_NEW, 'label' => Mage::helper('optemais')->__('Nova Campanha')),
24
+ array('value' => self::ACTION_EXISTING, 'label' => Mage::helper('optemais')->__('Campanha Existente')),
25
+ );
26
+ }
27
+
28
+
29
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Campaign/Statuses.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Campaign_Statuses
15
+ {
16
+
17
+ const STATE_ACTIVE = 1;
18
+ const STATE_INACTIVE = 0;
19
+
20
+ public function getOptions()
21
+ {
22
+ return array(
23
+ self::STATE_ACTIVE => Mage::helper('optemais')->__('Ativo'),
24
+ self::STATE_INACTIVE => Mage::helper('optemais')->__('Inativo'),
25
+ );
26
+ }
27
+
28
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Customer/Attributes.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Customer_Attributes
15
+ {
16
+ /**
17
+ * Retrieves attributes
18
+ *
19
+ * @return array
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
24
+ ->setEntityTypeFilter( Mage::getModel('customer/customer')->getEntityTypeId() );
25
+
26
+ $result = array();
27
+ $result[] = array(
28
+ 'value' => '',
29
+ 'label' => Mage::helper('adminhtml')->__('-- Please Select --')
30
+ );
31
+ foreach ($attributes as $attribute) {
32
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
33
+ if ($attribute->getId()) {
34
+ $result[] = array(
35
+ 'value' => $attribute->getAttributeCode(),
36
+ 'label' => $attribute->getFrontend()->getLabel(),
37
+ );
38
+ }
39
+ }
40
+ return $result;
41
+ }
42
+
43
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Select/Attributes.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Select_Attributes
15
+ {
16
+ /**
17
+ * Retrieves attributes
18
+ *
19
+ * @return array
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ $attributes = Mage::getModel('catalog/product')->getResource()
24
+ ->loadAllAttributes()
25
+ ->getAttributesByCode();
26
+
27
+ $result = array();
28
+ $result[] = array(
29
+ 'value' => '',
30
+ 'label' => Mage::helper('adminhtml')->__('-- Please Select --')
31
+ );
32
+ foreach ($attributes as $attribute) {
33
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
34
+ if ($attribute->getId() && in_array($attribute->getFrontendInput(), array('multiselect', 'select')) && $attribute->getIsUserDefined()) {
35
+ $result[] = array(
36
+ 'value' => $attribute->getAttributeCode(),
37
+ 'label' => $attribute->getFrontend()->getLabel(),
38
+ );
39
+ }
40
+ }
41
+ return $result;
42
+ }
43
+
44
+ /**
45
+ * Retrieves attributes
46
+ *
47
+ * @return array
48
+ */
49
+ public function getOptions()
50
+ {
51
+ $attributes = Mage::getModel('catalog/product')->getResource()
52
+ ->loadAllAttributes()
53
+ ->getAttributesByCode();
54
+ $result = array();
55
+ foreach ($attributes as $attribute) {
56
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
57
+ if ($attribute->getId() && in_array($attribute->getFrontendInput(), array('multiselect', 'select')) && $attribute->getIsUserDefined()) {
58
+ $result[$attribute->getAttributeCode()] = $attribute->getFrontend()->getLabel();
59
+ }
60
+ }
61
+ return $result;
62
+ }
63
+
64
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Shipping/Pricetype.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Shipping_Pricetype
15
+ {
16
+
17
+ const LOWEST_PRICE = 'lowest_price';
18
+ const BIGGEST_PRICE = 'biggest_price';
19
+
20
+ public function toOptionArray()
21
+ {
22
+ return array(
23
+ array('value' => self::LOWEST_PRICE, 'label' => Mage::helper('optemais')->__('Menor Preço')),
24
+ array('value' => self::BIGGEST_PRICE, 'label' => Mage::helper('optemais')->__('Maior Preço')),
25
+ );
26
+ }
27
+
28
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Shippingmethods.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Shippingmethods
15
+ {
16
+
17
+ public function toOptionArray()
18
+ {
19
+ $carriers = Mage::getSingleton('shipping/config')->getActiveCarriers();
20
+ $shippingMethods = array();
21
+ foreach ($carriers as $carriersCode => $carriersModel) {
22
+ if (!$carriersModel->getAllowedMethods()) {
23
+ continue;
24
+ }
25
+ foreach ($carriersModel->getAllowedMethods() as $methodCode => $methodTitle) {
26
+ $shippingMethods[] = array
27
+ (
28
+ 'value' => $carriersCode . "_" . $methodCode,
29
+ 'label' => $methodTitle
30
+ );
31
+ }
32
+ }
33
+ return $shippingMethods;
34
+ }
35
+
36
+ }
app/code/community/CsuMarketSystem/OpteMais/Model/Source/Stores.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Model_Source_Stores
15
+ {
16
+
17
+ public function toOptionArray()
18
+ {
19
+ $stores = array();
20
+ foreach (Mage::app()->getStores() as $store) {
21
+ $stores[] = array
22
+ (
23
+ 'value' => $store->getId(),
24
+ 'label' => $store->getName()
25
+ );
26
+ }
27
+ return $stores;
28
+ }
29
+
30
+ }
app/code/community/CsuMarketSystem/OpteMais/controllers/Adminhtml/Optemais/CampaignController.php ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_Adminhtml_Optemais_CampaignController extends Mage_Adminhtml_Controller_Action
15
+ {
16
+
17
+ protected function _isAllowed()
18
+ {
19
+ return Mage::getSingleton('admin/session')->isAllowed('admin/promo/optemais_campaign');
20
+ }
21
+
22
+ public function addItemsAction()
23
+ {
24
+ if (!$this->_validateProducts($this->getRequest()->getParam('product'))) {
25
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Produtos inválidos'));
26
+ $this->_redirect('adminhtml/catalog_product/index');
27
+ return false;
28
+ }
29
+ $products = $this->getRequest()->getParam('product');
30
+ if (!is_array($products)) {
31
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Selecione pelo menos um produto'));
32
+ $this->_redirect('adminhtml/catalog_product/index');
33
+ return false;
34
+ } else {
35
+ try {
36
+ foreach ($products as $productId) {
37
+ /** @var Mage_Catalog_Model_Product $product */
38
+ $product = Mage::getModel('catalog/product')->load($productId);
39
+ if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
40
+ throw new Exception(Mage::helper('optemais')->__('Utilize somente [Produtos Simples] para Campanhas'));
41
+ }
42
+ }
43
+ } catch (Exception $e) {
44
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
45
+ $this->_redirect('adminhtml/catalog_product/index');
46
+ return false;
47
+ }
48
+ }
49
+
50
+ $this->loadLayout()
51
+ ->_setActiveMenu('promo')
52
+ ->_addBreadcrumb(Mage::helper('optemais')->__('Adicionar itens à Campanha OPTe+'), Mage::helper('optemais')->__('Adicionar Itens à Campanha OPTe+'))
53
+ ->_addContent($this->getLayout()->createBlock('optemais/adminhtml_campaign_item'))
54
+ ->renderLayout();
55
+ }
56
+
57
+ public function confirmItemsAction()
58
+ {
59
+ /** @var CsuMarketSystem_OpteMais_Model_Campaign $campaign */
60
+ $campaign = Mage::getModel('optemais/campaign');
61
+ if ($this->getRequest()->getParam('action') == CsuMarketSystem_OpteMais_Model_Source_Campaign_Actions::ACTION_EXISTING) {
62
+ try {
63
+ $campaignId = $this->getRequest()->getParam('campaign');
64
+ $campaign->addItemToCampaign($this->getRequest(), $campaignId);
65
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Itens adicionados à campanha com sucesso'));
66
+ } catch (Exception $e) {
67
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
68
+ }
69
+ } else {
70
+ try {
71
+ $campaign->addCampaign($this->getRequest());
72
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Campanha criada com sucesso'));
73
+ } catch (Exception $e) {
74
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
75
+ }
76
+ }
77
+ $this->_redirect('adminhtml/catalog_product/index');
78
+ }
79
+
80
+ protected function _initAction()
81
+ {
82
+ $this->loadLayout()
83
+ ->_setActiveMenu('promo')
84
+ ->_addBreadcrumb(Mage::helper('optemais')->__('Gerenciar Campanhas OPTe+'), Mage::helper('optemais')->__('Gerenciar Campanhas OPTe+'));
85
+ return $this;
86
+ }
87
+
88
+ public function indexAction()
89
+ {
90
+ $this->_initAction()
91
+ ->_addContent($this->getLayout()->createBlock('optemais/adminhtml_campaign'))
92
+ ->renderLayout();
93
+ }
94
+
95
+ public function editAction()
96
+ {
97
+ $id = $this->getRequest()->getParam('id');
98
+ $model = Mage::getModel('optemais/campaign')->load($id);
99
+ if ($model->getId() || $id == 0) {
100
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
101
+ if (!empty($data)) {
102
+ $model->setData($data);
103
+ }
104
+ Mage::register('optemais_campaign', $model);
105
+ $this->loadLayout();
106
+ $this->_setActiveMenu('promo');
107
+ $this->_addBreadcrumb(Mage::helper('optemais')->__('Gerenciar Campanhas OPTe+'), Mage::helper('optemais')->__('Gerenciar Campanhas OPTe+'));
108
+ $this->_addBreadcrumb(Mage::helper('optemais')->__('Nova Campanha'), Mage::helper('optemais')->__('Nova Campanha'));
109
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
110
+ $this->_addContent($this->getLayout()->createBlock('optemais/adminhtml_campaign_edit'))
111
+ ->_addLeft($this->getLayout()->createBlock('optemais/adminhtml_campaign_edit_tabs'));
112
+ $this->renderLayout();
113
+ } else {
114
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Campanha não encontrada'));
115
+ $this->_redirect('*/*/');
116
+ }
117
+ }
118
+
119
+ public function newAction()
120
+ {
121
+ $this->_forward('edit');
122
+ }
123
+
124
+ public function saveAction()
125
+ {
126
+ if ($data = $this->getRequest()->getPost()) {
127
+ $model = Mage::getModel('optemais/campaign');
128
+ $model->setData($data)->setId($this->getRequest()->getParam('id'));
129
+ try {
130
+ $model->save();
131
+ if ($this->getRequest()->getParam('id')) {
132
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Campanha atualizada com sucesso'));
133
+ } else {
134
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Campanha criada com sucesso'));
135
+ }
136
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
137
+ if ($this->getRequest()->getParam('back')) {
138
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
139
+ return;
140
+ }
141
+ $this->_redirect('*/*/');
142
+ return;
143
+ } catch (Exception $e) {
144
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
145
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
146
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
147
+ return;
148
+ }
149
+ }
150
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Não foi possível encontrar a Campanha'));
151
+ $this->_redirect('*/*/');
152
+ }
153
+
154
+ public function deleteAction()
155
+ {
156
+ if ($this->getRequest()->getParam('id') > 0) {
157
+ try {
158
+ $model = Mage::getModel('optemais/campaign')->load($this->getRequest()->getParam('id'));
159
+ $model->delete();
160
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Campanha excluída com sucesso'));
161
+ $this->_redirect('*/*/');
162
+ } catch (Exception $e) {
163
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
164
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
165
+ }
166
+ }
167
+ $this->_redirect('*/*/');
168
+ }
169
+
170
+ public function massDeleteAction()
171
+ {
172
+ $campaigns = $this->getRequest()->getParam('campaign');
173
+ if (!is_array($campaigns)) {
174
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Selecione pelo menos uma campanha'));
175
+ } else {
176
+ try {
177
+ foreach ($campaigns as $campaignId) {
178
+ $model = Mage::getModel('optemais/campaign')->load($campaignId);
179
+ $model->delete();
180
+ }
181
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Total de %d campanha(s) removida(s)', count($campaigns)));
182
+ } catch (Exception $e) {
183
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
184
+ }
185
+ }
186
+ $this->_redirect('*/*/index');
187
+ }
188
+
189
+ public function massDeleteItemAction()
190
+ {
191
+ $products = $this->getRequest()->getParam('product');
192
+ if (!is_array($products)) {
193
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Selecione pelo menos um produto'));
194
+ } else {
195
+ try {
196
+ foreach ($products as $campaignItemId) {
197
+ $model = Mage::getModel('optemais/campaign_item')->load($campaignItemId);
198
+ $model->delete();
199
+ }
200
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('optemais')->__('Total de %d produto(s) removido(s)', count($products)));
201
+ } catch (Exception $e) {
202
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
203
+ }
204
+ }
205
+ $this->_redirectReferer();
206
+ }
207
+
208
+ public function massStatusAction()
209
+ {
210
+ $campaigns = $this->getRequest()->getParam('campaign');
211
+ if (!is_array($campaigns)) {
212
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('optemais')->__('Selecione pelo menos uma campanha'));
213
+ } else {
214
+ try {
215
+ foreach ($campaigns as $campaignId) {
216
+ Mage::getSingleton('optemais/campaign')
217
+ ->load($campaignId)
218
+ ->setIsActive($this->getRequest()->getParam('status'))
219
+ ->setIsMassupdate(true)
220
+ ->save();
221
+ }
222
+ $this->_getSession()->addSuccess(
223
+ $this->__('Total de %d campanha(s) atualizada(s)', count($campaigns))
224
+ );
225
+ } catch (Exception $e) {
226
+ $this->_getSession()->addError($e->getMessage());
227
+ }
228
+ }
229
+ $this->_redirect('*/*/index');
230
+ }
231
+
232
+ public function exportCsvAction()
233
+ {
234
+ $fileName = 'optemais_campanhas.csv';
235
+ $content = $this->getLayout()->createBlock('optemais/adminhtml_campaign_grid')->getCsv();
236
+ $this->_sendUploadResponse($fileName, $content);
237
+ }
238
+
239
+ public function exportXmlAction()
240
+ {
241
+ $fileName = 'optemais_campanhas.xml';
242
+ $content = $this->getLayout()->createBlock('optemais/adminhtml_campaign_grid')->getXml();
243
+ $this->_sendUploadResponse($fileName, $content);
244
+ }
245
+
246
+ public function productGridAction()
247
+ {
248
+ $this->getResponse()->setBody(
249
+ $this->getLayout()
250
+ ->createBlock('optemais/adminhtml_campaign_edit_tab_product_grid')
251
+ ->toHtml()
252
+ );
253
+ }
254
+
255
+ protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
256
+ {
257
+ $response = $this->getResponse();
258
+ $response->setHeader('HTTP/1.1 200 OK', '');
259
+ $response->setHeader('Pragma', 'public', true);
260
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
261
+ $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
262
+ $response->setHeader('Last-Modified', date('r'));
263
+ $response->setHeader('Accept-Ranges', 'bytes');
264
+ $response->setHeader('Content-Length', strlen($content));
265
+ $response->setHeader('Content-type', $contentType);
266
+ $response->setBody($content);
267
+ $response->sendResponse();
268
+ die;
269
+ }
270
+
271
+ private function _validateProducts($products)
272
+ {
273
+ return true;
274
+ }
275
+
276
+ }
app/code/community/CsuMarketSystem/OpteMais/controllers/Api/OrderController.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ require_once(Mage::getModuleDir('controllers', 'CsuMarketSystem_OpteMais') . DS . 'ApiController.php');
15
+
16
+ class CsuMarketSystem_OpteMais_Api_OrderController extends CsuMarketSystem_OpteMais_ApiController
17
+ {
18
+
19
+ public function createOrderAction()
20
+ {
21
+ $orderData = json_decode($this->getRequest()->getRawBody(), true);
22
+ /** @var CsuMarketSystem_OpteMais_Model_Order $order */
23
+ $order = Mage::getModel('optemais/order');
24
+ $response = $order->createOrder($orderData);
25
+ $this->getResponseApi()->setMessageKey('Mensagem');
26
+ $this->getResponseApi()->setStatusKey('Status');
27
+ if ($response['Status']) {
28
+ $this->getResponseApi()->setStatusValue(true);
29
+ $this->getResponseApi()->setMessageValue(null);
30
+ } else {
31
+ $this->getResponseApi()->setStatusValue(false);
32
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['Mensagem']));
33
+ }
34
+ return $this->_setResponse($response);
35
+ }
36
+
37
+ public function changeStatusAction()
38
+ {
39
+ /** @var CsuMarketSystem_OpteMais_Model_Order $order */
40
+ $order = Mage::getModel('optemais/order');
41
+ $response = $order->changeStatus($this->getRequest()->getParams());
42
+ $this->getResponseApi()->setMessageKey('Mensagem');
43
+ $this->getResponseApi()->setStatusKey('Status');
44
+ $info = $response['data'];
45
+ if ($response['status']) {
46
+ $this->getResponseApi()->setStatusValue(true);
47
+ $this->getResponseApi()->setMessageValue(null);
48
+ } else {
49
+ if (isset($response['invalid_params'])) {
50
+ $invalidParams = implode(",", $response['invalid_params']);
51
+ $this->getResponseApi()->setStatusValue(false);
52
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $invalidParams));
53
+ } else {
54
+ $this->getResponseApi()->setStatusValue(false);
55
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
56
+ }
57
+ }
58
+ return $this->_setResponse($info);
59
+ }
60
+
61
+ public function getTrackingInfoAction()
62
+ {
63
+ /** @var CsuMarketSystem_OpteMais_Model_Order $order */
64
+ $order = Mage::getModel('optemais/order');
65
+ $response = $order->getTrackingInfo($this->getRequest()->getParams());
66
+ $this->getResponseApi()->setMessageKey('Mensagem');
67
+ $this->getResponseApi()->setStatusKey('Status');
68
+ if ($response['status']) {
69
+ $info = $response['data'];
70
+ $this->getResponseApi()->setStatusValue(true);
71
+ $this->getResponseApi()->setMessageValue(null);
72
+ return $this->_setResponse($info);
73
+ } else {
74
+ if (isset($response['not_found']) && $response['not_found']) {
75
+ $this->getResponseApi()->setStatusValue(false);
76
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_NOT_FOUND, $response['message']));
77
+ } elseif (isset($response['invalid_params'])) {
78
+ $invalidParams = implode(",", $response['invalid_params']);
79
+ $this->getResponseApi()->setStatusValue(false);
80
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $invalidParams));
81
+ } else {
82
+ $this->getResponseApi()->setStatusValue(false);
83
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
84
+ }
85
+ return $this->_setResponse();
86
+ }
87
+ }
88
+
89
+ public function getPaymentMethodsAction()
90
+ {
91
+ /** @var CsuMarketSystem_OpteMais_Model_Order $order */
92
+ $order = Mage::getModel('optemais/order');
93
+ $response = $order->getPaymentMethods($this->getRequest()->getParams('IdCampanha',null));
94
+ $this->getResponseApi()->setMessageKey('Mensagem');
95
+ $this->getResponseApi()->setStatusKey('Status');
96
+ if ($response['status']) {
97
+ $info = $response['data'];
98
+ $this->getResponseApi()->setStatusValue(true);
99
+ $this->getResponseApi()->setMessageValue(null);
100
+ return $this->_setResponse($info);
101
+ } else {
102
+ if (isset($response['not_found']) && $response['not_found']) {
103
+ $this->getResponseApi()->setStatusValue(false);
104
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_NOT_FOUND, $response['message']));
105
+ } elseif (isset($response['invalid_params'])) {
106
+ $invalidParams = implode(",", $response['invalid_params']);
107
+ $this->getResponseApi()->setStatusValue(false);
108
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $invalidParams));
109
+ } else {
110
+ $this->getResponseApi()->setStatusValue(false);
111
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
112
+ }
113
+ return $this->_setResponse();
114
+ }
115
+ }
116
+
117
+ public function getInstallmentsAction()
118
+ {
119
+ /** @var CsuMarketSystem_OpteMais_Model_Order $order */
120
+ $order = Mage::getModel('optemais/order');
121
+ $response = $order->getInstallments($this->getRequest()->getParams());
122
+ $this->getResponseApi()->setMessageKey('Mensagem');
123
+ $this->getResponseApi()->setStatusKey('Status');
124
+ if ($response['status']) {
125
+ $info = $response['data'];
126
+ $this->getResponseApi()->setStatusValue(true);
127
+ $this->getResponseApi()->setMessageValue(null);
128
+ return $this->_setResponse($info);
129
+ } else {
130
+ if (isset($response['not_found']) && $response['not_found']) {
131
+ $this->getResponseApi()->setStatusValue(false);
132
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_NOT_FOUND, $response['message']));
133
+ } elseif (isset($response['invalid_params'])) {
134
+ $invalidParams = implode(",", $response['invalid_params']);
135
+ $this->getResponseApi()->setStatusValue(false);
136
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $invalidParams));
137
+ } else {
138
+ $this->getResponseApi()->setStatusValue(false);
139
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
140
+ }
141
+ return $this->_setResponse();
142
+ }
143
+ }
144
+
145
+ }
app/code/community/CsuMarketSystem/OpteMais/controllers/Api/ProductController.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ require_once(Mage::getModuleDir('controllers', 'CsuMarketSystem_OpteMais') . DS . 'ApiController.php');
15
+
16
+ class CsuMarketSystem_OpteMais_Api_ProductController extends CsuMarketSystem_OpteMais_ApiController
17
+ {
18
+
19
+ public function listAllAction()
20
+ {
21
+ /** @var CsuMarketSystem_OpteMais_Model_Product $product */
22
+ $product = Mage::getModel('optemais/product');
23
+ $currentPage = $this->getRequest()->getParam('page',0);
24
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_SUCCESS);
25
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_SUCCESS));
26
+ return $this->_setResponse($product->getProducts(CsuMarketSystem_OpteMais_Model_Product::MODE_FULL,0,$currentPage));
27
+ }
28
+
29
+ public function listPartialAction()
30
+ {
31
+ $fromHours = $this->getRequest()->getParam('from_hours');
32
+ if (!$fromHours) {
33
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_INVALID);
34
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $this->__('Parametro [from_hours] invalido')));
35
+ return $this->_setResponse();
36
+ }
37
+ /** @var CsuMarketSystem_OpteMais_Model_Product $product */
38
+ $product = Mage::getModel('optemais/product');
39
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_SUCCESS);
40
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_SUCCESS));
41
+ return $this->_setResponse($product->getProducts(CsuMarketSystem_OpteMais_Model_Product::MODE_PARTIAL, $fromHours));
42
+ }
43
+
44
+ public function listAvailabilityAction()
45
+ {
46
+ $currentPage = $this->getRequest()->getParam('page',0);
47
+ /** @var CsuMarketSystem_OpteMais_Model_Product $product */
48
+ $product = Mage::getModel('optemais/product');
49
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_SUCCESS);
50
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_SUCCESS));
51
+ return $this->_setResponse($product->getAvailabilityProducts($currentPage));
52
+ }
53
+
54
+ public function getProductBySkuAction()
55
+ {
56
+ $sku = $this->getRequest()->getParam('sku');
57
+ /** @var CsuMarketSystem_OpteMais_Model_Product $product */
58
+ $product = Mage::getModel('optemais/product');
59
+ $response = $product->getProductBySku($sku);
60
+ $this->getResponseApi()->setMessageKey('Mensagem');
61
+ $this->getResponseApi()->setStatusKey('Status');
62
+ if ($response['status']) {
63
+ $info = $response['data'];
64
+ $this->getResponseApi()->setStatusValue(true);
65
+ $this->getResponseApi()->setMessageValue(null);
66
+ return $this->_setResponse($info);
67
+ } else {
68
+ if (isset($response['not_found'])) {
69
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_NOT_FOUND);
70
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_NOT_FOUND, $response['message']));
71
+ return $this->_setResponse();
72
+ } else {
73
+ $this->getResponseApi()->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_ERROR);
74
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
75
+ return $this->_setResponse();
76
+ }
77
+ }
78
+ }
79
+
80
+ }
app/code/community/CsuMarketSystem/OpteMais/controllers/Api/ShippingController.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ require_once(Mage::getModuleDir('controllers', 'CsuMarketSystem_OpteMais') . DS . 'ApiController.php');
15
+
16
+ class CsuMarketSystem_OpteMais_Api_ShippingController extends CsuMarketSystem_OpteMais_ApiController
17
+ {
18
+
19
+ public function getRatesAction()
20
+ {
21
+ /** @var CsuMarketSystem_OpteMais_Model_Shipping $shipping */
22
+ $shipping = Mage::getModel('optemais/shipping');
23
+ $response = $shipping->getShippingRates($this->getRequest()->getParams());
24
+ $this->getResponseApi()->setMessageKey('Mensagem');
25
+ $this->getResponseApi()->setStatusKey('Status');
26
+ if ($response['status']) {
27
+ $rates = $response['data'];
28
+ $this->getResponseApi()->setStatusValue(true);
29
+ $this->getResponseApi()->setMessageValue(null);
30
+ return $this->_setResponse($rates);
31
+ } else {
32
+ if (isset($response['invalid_params'])) {
33
+ $invalidParams = implode(",", $response['invalid_params']);
34
+ $this->getResponseApi()->setStatusValue(false);
35
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_INVALID, $invalidParams));
36
+ return $this->_setResponse();
37
+ } else {
38
+ $this->getResponseApi()->setStatusValue(false);
39
+ $this->getResponseApi()->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_ERROR, $response['message']));
40
+ return $this->_setResponse();
41
+ }
42
+ }
43
+ }
44
+
45
+ }
app/code/community/CsuMarketSystem/OpteMais/controllers/ApiController.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ class CsuMarketSystem_OpteMais_ApiController extends Mage_Core_Controller_Front_Action
15
+ {
16
+
17
+ /** @var CsuMarketSystem_OpteMais_Model_Response */
18
+ private $_responseModel = null;
19
+
20
+ public function _construct()
21
+ {
22
+ parent::_construct();
23
+ $this->_responseModel = Mage::getModel('optemais/response');
24
+ $this->_responseModel->setStatusKey('status_code');
25
+ $this->_responseModel->setMessageKey('message');
26
+ }
27
+
28
+ public function getResponseApi()
29
+ {
30
+ return $this->_responseModel;
31
+ }
32
+
33
+ public function preDispatch()
34
+ {
35
+ $this->getResponse()->setHeader('Content-type', 'application/json; charset=UTF-8', true);
36
+ $auth = Zend_Auth::getInstance();
37
+ $auth->setStorage(new Zend_Auth_Storage_Session('auth_user'));
38
+ if (!$auth->hasIdentity()) {
39
+ $config = array(
40
+ 'accept_schemes' => 'basic',
41
+ 'realm' => CsuMarketSystem_OpteMais_Helper_Data::AUTH_REALM,
42
+ 'nonce_timeout' => 3600,
43
+ );
44
+ $adapter = new CsuMarketSystem_OpteMais_Model_Auth_Adapter_Http($config);
45
+ $adapter->setRequest($this->getRequest());
46
+ $adapter->setResponse($this->getResponse());
47
+ $result = $auth->authenticate($adapter);
48
+ if (!$result->isValid()) {
49
+ $auth->clearIdentity();
50
+ $this->getRequest()->setDispatched(true);
51
+ $this->setFlag(
52
+ '',
53
+ Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH,
54
+ true
55
+ );
56
+ $this->_responseModel->setStatusValue(CsuMarketSystem_OpteMais_Helper_Data::STATUS_CODE_NOT_AUTHORIZED);
57
+ $this->_responseModel->setMessageValue($this->__(CsuMarketSystem_OpteMais_Helper_Data::MESSAGE_NOT_AUTHORIZED));
58
+ return $this->_setResponse();
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+
64
+ protected function _setResponse($responseData = array())
65
+ {
66
+ return $this->_responseModel->getResponseData($responseData, $this->getResponse());
67
+ }
68
+
69
+ }
app/code/community/CsuMarketSystem/OpteMais/etc/adminhtml.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+ -->
15
+ <config>
16
+ <menu>
17
+ <promo>
18
+ <children>
19
+ <optemais_campaign translate="title" module="optemais">
20
+ <title>Gerenciar Campanhas OPTe+</title>
21
+ <action>adminhtml/optemais_campaign/index</action>
22
+ <depends>
23
+ <module>CsuMarketSystem_OpteMais</module>
24
+ <config>optemais/config/active</config>
25
+ </depends>
26
+ <sort_order>300</sort_order>
27
+ </optemais_campaign>
28
+ </children>
29
+ </promo>
30
+ </menu>
31
+ <acl>
32
+ <resources>
33
+ <admin>
34
+ <children>
35
+ <system>
36
+ <children>
37
+ <config>
38
+ <children>
39
+ <optemais module="optemais">
40
+ <title>API CSU MarketSystem OPTe+</title>
41
+ <sort_order>300</sort_order>
42
+ </optemais>
43
+ </children>
44
+ </config>
45
+ </children>
46
+ </system>
47
+ <promo>
48
+ <children>
49
+ <optemais_campaign translate="title" module="optemais">
50
+ <title>Gerenciar Campanhas OPTe+</title>
51
+ <sort_order>300</sort_order>
52
+ </optemais_campaign>
53
+ </children>
54
+ </promo>
55
+ </children>
56
+ </admin>
57
+ </resources>
58
+ </acl>
59
+ </config>
app/code/community/CsuMarketSystem/OpteMais/etc/config.xml ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ *
10
+ * @category CsuMarketSystem
11
+ * @package CsuMarketSystem_OpteMais
12
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+ -->
16
+ <config>
17
+ <modules>
18
+ <CsuMarketSystem_OpteMais>
19
+ <version>1.1.0</version>
20
+ </CsuMarketSystem_OpteMais>
21
+ </modules>
22
+ <global>
23
+ <helpers>
24
+ <optemais>
25
+ <class>CsuMarketSystem_OpteMais_Helper</class>
26
+ </optemais>
27
+ </helpers>
28
+ <models>
29
+ <optemais>
30
+ <class>CsuMarketSystem_OpteMais_Model</class>
31
+ <resourceModel>optemais_resource</resourceModel>
32
+ </optemais>
33
+ <optemais_resource>
34
+ <class>CsuMarketSystem_OpteMais_Model_Resource</class>
35
+ <entities>
36
+ <campaign>
37
+ <table>optemais_campaign</table>
38
+ </campaign>
39
+ <campaign_item>
40
+ <table>optemais_campaign_item</table>
41
+ </campaign_item>
42
+ </entities>
43
+ </optemais_resource>
44
+ </models>
45
+ <resources>
46
+ <optemais_setup>
47
+ <setup>
48
+ <module>CsuMarketSystem_OpteMais</module>
49
+ <class>Mage_Eav_Model_Entity_Setup</class>
50
+ </setup>
51
+ <connection>
52
+ <use>core_setup</use>
53
+ </connection>
54
+ </optemais_setup>
55
+ </resources>
56
+ <blocks>
57
+ <optemais>
58
+ <class>CsuMarketSystem_OpteMais_Block</class>
59
+ </optemais>
60
+ </blocks>
61
+ </global>
62
+ <frontend>
63
+ <routers>
64
+ <optemais>
65
+ <use>standard</use>
66
+ <args>
67
+ <module>CsuMarketSystem_OpteMais</module>
68
+ <frontName>optemais</frontName>
69
+ </args>
70
+ </optemais>
71
+ </routers>
72
+ <translate>
73
+ <modules>
74
+ <optemais>
75
+ <files>
76
+ <default>CsuMarketSystem_OpteMais.csv</default>
77
+ </files>
78
+ </optemais>
79
+ </modules>
80
+ </translate>
81
+ </frontend>
82
+ <adminhtml>
83
+ <events>
84
+ <adminhtml_catalog_product_grid_prepare_massaction>
85
+ <observers>
86
+ <optemais>
87
+ <type>singleton</type>
88
+ <class>optemais/observer</class>
89
+ <method>addMassActionToProductGrid</method>
90
+ </optemais>
91
+ </observers>
92
+ </adminhtml_catalog_product_grid_prepare_massaction>
93
+ <catalog_product_attribute_update_after>
94
+ <observers>
95
+ <optemais>
96
+ <type>singleton</type>
97
+ <class>optemais/observer</class>
98
+ <method>afterUpdateAttributes</method>
99
+ </optemais>
100
+ </observers>
101
+ </catalog_product_attribute_update_after>
102
+ <catalog_product_to_website_change>
103
+ <observers>
104
+ <optemais>
105
+ <type>singleton</type>
106
+ <class>optemais/observer</class>
107
+ <method>afterUpdateAttributes</method>
108
+ </optemais>
109
+ </observers>
110
+ </catalog_product_to_website_change>
111
+ <catalog_product_stock_item_mass_change>
112
+ <observers>
113
+ <optemais>
114
+ <type>singleton</type>
115
+ <class>optemais/observer</class>
116
+ <method>afterUpdateAttributes</method>
117
+ </optemais>
118
+ </observers>
119
+ </catalog_product_stock_item_mass_change>
120
+ </events>
121
+ <translate>
122
+ <modules>
123
+ <optemais>
124
+ <files>
125
+ <default>CsuMarketSystem_OpteMais.csv</default>
126
+ </files>
127
+ </optemais>
128
+ </modules>
129
+ </translate>
130
+ <layout>
131
+ <updates>
132
+ <optemais>
133
+ <file>optemais.xml</file>
134
+ </optemais>
135
+ </updates>
136
+ </layout>
137
+ </adminhtml>
138
+ <admin>
139
+ <routers>
140
+ <adminhtml>
141
+ <args>
142
+ <modules>
143
+ <MarketSystem_OpteMais before="Mage_Adminhtml">CsuMarketSystem_OpteMais_Adminhtml</MarketSystem_OpteMais>
144
+ </modules>
145
+ </args>
146
+ </adminhtml>
147
+ </routers>
148
+ </admin>
149
+ <default>
150
+ <payment>
151
+ <optemais_modelc>
152
+ <active>1</active>
153
+ <model>optemais/payment_modelc</model>
154
+ <order_status>pending</order_status>
155
+ <title>Pago na CSU MarketSystem OPTe+</title>
156
+ </optemais_modelc>
157
+ </payment>
158
+ <optemais>
159
+ <config_product>
160
+ <use_parent_images>0</use_parent_images>
161
+ <items_per_page>200</items_per_page>
162
+ <ignore_invisible>1</ignore_invisible>
163
+ <discount_min_qty>1</discount_min_qty>
164
+ </config_product>
165
+ <config_shipping>
166
+ <delivery_time_default>7</delivery_time_default>
167
+ <delivery_time_variable>delivery_time</delivery_time_variable>
168
+ <price_type>lowest_price</price_type>
169
+ </config_shipping>
170
+ <config_order>
171
+ <tipo_pessoa_value_pf>pf</tipo_pessoa_value_pf>
172
+ <tipo_pessoa_value_pj>pj</tipo_pessoa_value_pj>
173
+ </config_order>
174
+ <config_order_status>
175
+ <status_approved>processing</status_approved>
176
+ <status_canceled>canceled</status_canceled>
177
+ <status_pending>pending</status_pending>
178
+ <status_delivered>complete</status_delivered>
179
+ <status_refunded>closed</status_refunded>
180
+ </config_order_status>
181
+ </optemais>
182
+ </default>
183
+ </config>
app/code/community/CsuMarketSystem/OpteMais/etc/system.xml ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ *
10
+ * @category CsuMarketSystem
11
+ * @package CsuMarketSystem_OpteMais
12
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+ -->
16
+ <config>
17
+ <sections>
18
+ <optemais translate="label">
19
+ <label>API CSU MarketSystem OPTe+</label>
20
+ <tab>service</tab>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>500</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <groups>
27
+ <instructions>
28
+ <label>Instruções para Uso e Configurações</label>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>0</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ <comment><![CDATA[
35
+
36
+ <h3>Configurações necessárias</h3>
37
+
38
+ Para o funcionamento de todos os recursos, os atributos devem ser criados com as seguintes configurações:<br/>
39
+ <li>Escopo: Para produtos simples utilizar <b>Visão da Loja</b>;</li>
40
+ <li>Escopo: Para produtos configuráveis utilizar <b>Global</b>;</li>
41
+ <li>Usado na Listagem de Produtos: <b>Sim</b>.</li><br/>
42
+
43
+ <h3>Observações importantes</h3>
44
+
45
+ <li>Produtos desativados, sem categoria ou sem informação para a composição do SKU (como cor, tamanho, etc) não serão considerados na carga;</li>
46
+ ]]>
47
+ </comment>
48
+ </instructions>
49
+ <config>
50
+ <label>Configurações gerais</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>1</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <fields>
57
+ <active>
58
+ <label translate="label">Ativo</label>
59
+ <frontend_type>select</frontend_type>
60
+ <source_model>adminhtml/system_config_source_yesno</source_model>
61
+ <sort_order>1</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>0</show_in_store>
65
+ </active>
66
+ <username>
67
+ <label translate="label">
68
+ <![CDATA[Usuário <span class='required'>*</span>]]></label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>2</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ <validate>required-entry</validate>
75
+ <comment><![CDATA[Usuário autorizado para a integração]]></comment>
76
+ </username>
77
+ <password>
78
+ <label translate="label">
79
+ <![CDATA[Senha <span class='required'>*</span>]]></label>
80
+ <frontend_type>text</frontend_type>
81
+ <sort_order>3</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ <validate>required-entry</validate>
86
+ <comment><![CDATA[Senha autorizada para a integração]]></comment>
87
+ </password>
88
+ </fields>
89
+ </config>
90
+ <config_product>
91
+ <label>Produtos</label>
92
+ <frontend_type>text</frontend_type>
93
+ <sort_order>2</sort_order>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>1</show_in_website>
96
+ <show_in_store>1</show_in_store>
97
+ <fields>
98
+ <use_parent_images>
99
+ <label translate="label">Utilizar imagens do Produto Pai (Configurável) quando não houver imagens no Produto Filho (Simples)</label>
100
+ <frontend_type>select</frontend_type>
101
+ <source_model>adminhtml/system_config_source_yesno</source_model>
102
+ <sort_order>1</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </use_parent_images>
107
+ <items_per_page>
108
+ <label translate="label">
109
+ <![CDATA[Quantidade de itens por página <span class='required'>*</span>]]></label>
110
+ <frontend_type>text</frontend_type>
111
+ <sort_order>2</sort_order>
112
+ <show_in_default>1</show_in_default>
113
+ <show_in_website>1</show_in_website>
114
+ <show_in_store>1</show_in_store>
115
+ <validate>required-entry</validate>
116
+ <comment><![CDATA[Utilizado para carga de produtos e disponibilidade]]></comment>
117
+ </items_per_page>
118
+ <!--<ignore_invisible>-->
119
+ <!--<label translate="label">Ignorar produtos simples invisíveis (Não Exibir Individualmente)</label>-->
120
+ <!--<frontend_type>select</frontend_type>-->
121
+ <!--<source_model>adminhtml/system_config_source_yesno</source_model>-->
122
+ <!--<sort_order>3</sort_order>-->
123
+ <!--<show_in_default>1</show_in_default>-->
124
+ <!--<show_in_website>1</show_in_website>-->
125
+ <!--<show_in_store>0</show_in_store>-->
126
+ <!--</ignore_invisible>-->
127
+ <discount_min_qty translate="label">
128
+ <label>Descontar a quantidade mínima configurada para o cálculo de estoque</label>
129
+ <frontend_type>select</frontend_type>
130
+ <source_model>adminhtml/system_config_source_yesno</source_model>
131
+ <sort_order>4</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ <comment>Calcula o estoque descontando a quantidade mínima configurada no produto</comment>
136
+ </discount_min_qty>
137
+ </fields>
138
+ </config_product>
139
+ <config_attribute>
140
+ <label>Atributos</label>
141
+ <frontend_type>text</frontend_type>
142
+ <sort_order>3</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>1</show_in_store>
146
+ <fields>
147
+ <attribute_product_description translate="label,comment">
148
+ <label><![CDATA[Descrição Detalhada <span class='required'>*</span>]]></label>
149
+ <frontend_type>select</frontend_type>
150
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Attributes</source_model>
151
+ <sort_order>1</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>1</show_in_store>
155
+ <validate>validate-one-select</validate>
156
+ <comment><![CDATA[Atributo que representa a Descrição Detalhada de Produtos]]></comment>
157
+ </attribute_product_description>
158
+ <attribute_product_brand translate="label,comment">
159
+ <label><![CDATA[Marca <span class='required'>*</span>]]></label>
160
+ <frontend_type>select</frontend_type>
161
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Select_Attributes</source_model>
162
+ <sort_order>2</sort_order>
163
+ <show_in_default>1</show_in_default>
164
+ <show_in_website>1</show_in_website>
165
+ <show_in_store>1</show_in_store>
166
+ <validate>validate-one-select</validate>
167
+ <comment><![CDATA[Atributo que representa a Marca de Produtos]]></comment>
168
+ </attribute_product_brand>
169
+ <attribute_product_color translate="label,comment">
170
+ <label>Cor</label>
171
+ <frontend_type>select</frontend_type>
172
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Select_Attributes</source_model>
173
+ <sort_order>3</sort_order>
174
+ <show_in_default>1</show_in_default>
175
+ <show_in_website>1</show_in_website>
176
+ <show_in_store>1</show_in_store>
177
+ <comment>
178
+ <![CDATA[Atributo que representa a cor dos produtos.<br/>Exemplo: <b>Vermelho, Preto</b>]]></comment>
179
+ </attribute_product_color>
180
+ <attribute_product_size translate="label,comment">
181
+ <label>Tamanho</label>
182
+ <frontend_type>select</frontend_type>
183
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Select_Attributes</source_model>
184
+ <sort_order>4</sort_order>
185
+ <show_in_default>1</show_in_default>
186
+ <show_in_website>1</show_in_website>
187
+ <show_in_store>1</show_in_store>
188
+ <comment>
189
+ <![CDATA[Atributo que representa o tamanho dos produtos.<br/>Exemplo: <b>36, 37, 34/35</b>]]></comment>
190
+ </attribute_product_size>
191
+ <attribute_product_voltage translate="label,comment">
192
+ <label>Voltagem</label>
193
+ <frontend_type>select</frontend_type>
194
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Select_Attributes</source_model>
195
+ <sort_order>5</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ <comment>
200
+ <![CDATA[Atributo que representa a voltagem dos produtos.<br/>Exemplo: <b>110v, 220v</b>]]></comment>
201
+ </attribute_product_voltage>
202
+ <attribute_product_ean translate="label,comment">
203
+ <label>EAN</label>
204
+ <frontend_type>select</frontend_type>
205
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Attributes</source_model>
206
+ <sort_order>6</sort_order>
207
+ <show_in_default>1</show_in_default>
208
+ <show_in_website>1</show_in_website>
209
+ <show_in_store>1</show_in_store>
210
+ <comment>
211
+ <![CDATA[Atributo que representa o código EAN do produto.]]></comment>
212
+ </attribute_product_ean>
213
+ <attribute_product_refid translate="label,comment">
214
+ <label>RefID</label>
215
+ <frontend_type>select</frontend_type>
216
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Attributes</source_model>
217
+ <sort_order>7</sort_order>
218
+ <show_in_default>1</show_in_default>
219
+ <show_in_website>1</show_in_website>
220
+ <show_in_store>1</show_in_store>
221
+ <comment>
222
+ <![CDATA[Atributo que representa o código RefID do produto.]]></comment>
223
+ </attribute_product_refid>
224
+ <product_specifications translate="label,comment">
225
+ <label>Especificações do Produto</label>
226
+ <frontend_type>multiselect</frontend_type>
227
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Attributes</source_model>
228
+ <sort_order>8</sort_order>
229
+ <show_in_default>1</show_in_default>
230
+ <show_in_website>1</show_in_website>
231
+ <show_in_store>1</show_in_store>
232
+ </product_specifications>
233
+ </fields>
234
+ </config_attribute>
235
+ <config_shipping>
236
+ <label>Configurações de Entrega</label>
237
+ <frontend_type>text</frontend_type>
238
+ <sort_order>4</sort_order>
239
+ <show_in_default>1</show_in_default>
240
+ <show_in_website>1</show_in_website>
241
+ <show_in_store>1</show_in_store>
242
+ <fields>
243
+ <delivery_time_variable>
244
+ <label translate="label">
245
+ <![CDATA[Nome da variável no módulo de frete para o Prazo de Entrega]]></label>
246
+ <frontend_type>text</frontend_type>
247
+ <sort_order>1</sort_order>
248
+ <show_in_default>1</show_in_default>
249
+ <show_in_website>1</show_in_website>
250
+ <show_in_store>1</show_in_store>
251
+ <comment><![CDATA[Opção avançada: Entre em contato com suporte de sua loja.]]></comment>
252
+ </delivery_time_variable>
253
+ <delivery_time_default>
254
+ <label translate="label">
255
+ <![CDATA[Prazo padrão de Entrega]]></label>
256
+ <frontend_type>text</frontend_type>
257
+ <sort_order>2</sort_order>
258
+ <show_in_default>1</show_in_default>
259
+ <show_in_website>1</show_in_website>
260
+ <show_in_store>1</show_in_store>
261
+ <comment><![CDATA[Será utilizado caso o serviço de frete não retorne o prazo de entrega nos cálculos de frete.]]></comment>
262
+ </delivery_time_default>
263
+ <price_type translate="label,comment">
264
+ <label>Tipo de preço de frete para ser enviado para CSU</label>
265
+ <frontend_type>multiselect</frontend_type>
266
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Shipping_Pricetype</source_model>
267
+ <sort_order>3</sort_order>
268
+ <show_in_default>1</show_in_default>
269
+ <show_in_website>1</show_in_website>
270
+ <show_in_store>1</show_in_store>
271
+ <comment><![CDATA[Só é aceito um preço de frete por produto na CSU OPTe+, como o Magento pode resultar mais de um preço, é necessário que defina-se um tipo (menor ou maior) de preço para ser enviado.]]></comment>
272
+ </price_type>
273
+ </fields>
274
+ </config_shipping>
275
+ <config_order>
276
+ <label>Configurações de Pedido</label>
277
+ <frontend_type>text</frontend_type>
278
+ <sort_order>5</sort_order>
279
+ <show_in_default>1</show_in_default>
280
+ <show_in_website>1</show_in_website>
281
+ <show_in_store>1</show_in_store>
282
+ <fields>
283
+ <default_store_id translate="label">
284
+ <label>Loja Padrão para Pedidos</label>
285
+ <frontend_type>select</frontend_type>
286
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Stores</source_model>
287
+ <sort_order>1</sort_order>
288
+ <show_in_default>1</show_in_default>
289
+ <show_in_website>1</show_in_website>
290
+ <show_in_store>1</show_in_store>
291
+ </default_store_id>
292
+ <shipping_method translate="label">
293
+ <label>Método de Envio Padrão para Pedidos</label>
294
+ <frontend_type>select</frontend_type>
295
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Shippingmethods</source_model>
296
+ <sort_order>2</sort_order>
297
+ <show_in_default>1</show_in_default>
298
+ <show_in_website>1</show_in_website>
299
+ <show_in_store>1</show_in_store>
300
+ </shipping_method>
301
+ <attribute_cpf translate="label,comment">
302
+ <label><![CDATA[Atributo CPF]]></label>
303
+ <frontend_type>select</frontend_type>
304
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Customer_Attributes</source_model>
305
+ <sort_order>3</sort_order>
306
+ <show_in_default>1</show_in_default>
307
+ <show_in_website>1</show_in_website>
308
+ <show_in_store>1</show_in_store>
309
+ <comment><![CDATA[Atributo que representa o CPF no cadastro do cliente]]></comment>
310
+ </attribute_cpf>
311
+ <attribute_cnpj translate="label,comment">
312
+ <label><![CDATA[Atributo CNPJ]]></label>
313
+ <frontend_type>select</frontend_type>
314
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Customer_Attributes</source_model>
315
+ <sort_order>4</sort_order>
316
+ <show_in_default>1</show_in_default>
317
+ <show_in_website>1</show_in_website>
318
+ <show_in_store>1</show_in_store>
319
+ <comment><![CDATA[Atributo que representa o CNPJ no cadastro do cliente]]></comment>
320
+ </attribute_cnpj>
321
+ <attribute_razao_social translate="label,comment">
322
+ <label><![CDATA[Atributo Razão Social]]></label>
323
+ <frontend_type>select</frontend_type>
324
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Customer_Attributes</source_model>
325
+ <sort_order>5</sort_order>
326
+ <show_in_default>1</show_in_default>
327
+ <show_in_website>1</show_in_website>
328
+ <show_in_store>1</show_in_store>
329
+ <comment><![CDATA[Atributo que representa a Razão Social no cadastro do cliente]]></comment>
330
+ </attribute_razao_social>
331
+ <attribute_tipo_pessoa translate="label,comment">
332
+ <label><![CDATA[Atributo Tipo Pessoa]]></label>
333
+ <frontend_type>select</frontend_type>
334
+ <source_model>CsuMarketSystem_OpteMais_Model_Source_Customer_Attributes</source_model>
335
+ <sort_order>6</sort_order>
336
+ <show_in_default>1</show_in_default>
337
+ <show_in_website>1</show_in_website>
338
+ <show_in_store>1</show_in_store>
339
+ <comment><![CDATA[Atributo que representa a Tipo Pessoa (PJ ou PF) no cadastro do cliente]]></comment>
340
+ </attribute_tipo_pessoa>
341
+ <tipo_pessoa_value_pf>
342
+ <label translate="label">
343
+ <![CDATA[Valor para o Tipo Pessoa para Pessoa Física<span class='required'>*</span>]]></label>
344
+ <frontend_type>text</frontend_type>
345
+ <sort_order>7</sort_order>
346
+ <show_in_default>1</show_in_default>
347
+ <show_in_website>1</show_in_website>
348
+ <show_in_store>1</show_in_store>
349
+ <validate>required-entry</validate>
350
+ </tipo_pessoa_value_pf>
351
+ <tipo_pessoa_value_pj>
352
+ <label translate="label">
353
+ <![CDATA[Valor para o Tipo Pessoa para Pessoa Júridica<span class='required'>*</span>]]></label>
354
+ <frontend_type>text</frontend_type>
355
+ <sort_order>8</sort_order>
356
+ <show_in_default>1</show_in_default>
357
+ <show_in_website>1</show_in_website>
358
+ <show_in_store>1</show_in_store>
359
+ <validate>required-entry</validate>
360
+ </tipo_pessoa_value_pj>
361
+ <payment_method translate="label,comment">
362
+ <label>Métodos de Pagamento e Parcelamentos</label>
363
+ <frontend_model>optemais/adminhtml_paymentmethod</frontend_model>
364
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
365
+ <sort_order>9</sort_order>
366
+ <show_in_default>1</show_in_default>
367
+ <show_in_website>1</show_in_website>
368
+ <show_in_store>1</show_in_store>
369
+ <comment><![CDATA[Utilize somente se a finalização dos pedidos no ambiente CSU OPTe+ for utilizar os Métodos de Pagamento de sua loja.]]></comment>
370
+ </payment_method>
371
+ </fields>
372
+ </config_order>
373
+ <config_order_status>
374
+ <label>Configurações de Status de Pedido</label>
375
+ <frontend_type>text</frontend_type>
376
+ <sort_order>6</sort_order>
377
+ <show_in_default>1</show_in_default>
378
+ <show_in_website>1</show_in_website>
379
+ <show_in_store>1</show_in_store>
380
+ <fields>
381
+ <status_approved translate="label,comment">
382
+ <label>Pedido Aprovado</label>
383
+ <frontend_type>select</frontend_type>
384
+ <source_model>adminhtml/system_config_source_order_status</source_model>
385
+ <sort_order>1</sort_order>
386
+ <show_in_default>1</show_in_default>
387
+ <show_in_website>1</show_in_website>
388
+ <show_in_store>1</show_in_store>
389
+ <comment>
390
+ <![CDATA[Status na sua loja que representa o status [Pedido Aprovado] para a CSU OPTe+.]]></comment>
391
+ </status_approved>
392
+ <status_canceled translate="label,comment">
393
+ <label>Pedido Cancelado</label>
394
+ <frontend_type>select</frontend_type>
395
+ <source_model>adminhtml/system_config_source_order_status</source_model>
396
+ <sort_order>2</sort_order>
397
+ <show_in_default>1</show_in_default>
398
+ <show_in_website>1</show_in_website>
399
+ <show_in_store>1</show_in_store>
400
+ <comment>
401
+ <![CDATA[Status na sua loja que representa o status [Pedido Cancelado] para a CSU OPTe+.]]></comment>
402
+ </status_canceled>
403
+ <status_pending translate="label,comment">
404
+ <label>Pedido Pendente</label>
405
+ <frontend_type>select</frontend_type>
406
+ <source_model>adminhtml/system_config_source_order_status</source_model>
407
+ <sort_order>3</sort_order>
408
+ <show_in_default>1</show_in_default>
409
+ <show_in_website>1</show_in_website>
410
+ <show_in_store>1</show_in_store>
411
+ <comment>
412
+ <![CDATA[Status na sua loja que representa o status [Pedido Pendente] para a CSU OPTe+.]]></comment>
413
+ </status_pending>
414
+ <status_await_release translate="label,comment">
415
+ <label>Pedido Aguardando Liberação</label>
416
+ <frontend_type>select</frontend_type>
417
+ <source_model>adminhtml/system_config_source_order_status</source_model>
418
+ <sort_order>4</sort_order>
419
+ <show_in_default>1</show_in_default>
420
+ <show_in_website>1</show_in_website>
421
+ <show_in_store>1</show_in_store>
422
+ <comment>
423
+ <![CDATA[Status na sua loja que representa o status [Pedido Aguardando Liberação] para a CSU OPTe+.]]></comment>
424
+ </status_await_release>
425
+ <status_delivered translate="label,comment">
426
+ <label>Pedido Entregue</label>
427
+ <frontend_type>select</frontend_type>
428
+ <source_model>adminhtml/system_config_source_order_status</source_model>
429
+ <sort_order>5</sort_order>
430
+ <show_in_default>1</show_in_default>
431
+ <show_in_website>1</show_in_website>
432
+ <show_in_store>1</show_in_store>
433
+ <comment>
434
+ <![CDATA[Status na sua loja que representa o status [Pedido Entregue] para a CSU OPTe+.]]></comment>
435
+ </status_delivered>
436
+ <status_refunded translate="label,comment">
437
+ <label>Pedido Devolvido</label>
438
+ <frontend_type>select</frontend_type>
439
+ <source_model>adminhtml/system_config_source_order_status</source_model>
440
+ <sort_order>6</sort_order>
441
+ <show_in_default>1</show_in_default>
442
+ <show_in_website>1</show_in_website>
443
+ <show_in_store>1</show_in_store>
444
+ <comment>
445
+ <![CDATA[Status na sua loja que representa o status [Pedido Devolvido] para a CSU OPTe+.]]></comment>
446
+ </status_refunded>
447
+ </fields>
448
+ </config_order_status>
449
+ </groups>
450
+ </optemais>
451
+ <payment translate="label" module="payment">
452
+ <groups>
453
+ <optemais_modelc translate="label">
454
+ <label>CSU MarketSystem OPTe+</label>
455
+ <sort_order>1000</sort_order>
456
+ <show_in_default>1</show_in_default>
457
+ <show_in_website>1</show_in_website>
458
+ <show_in_store>1</show_in_store>
459
+ <fields>
460
+ <title translate="label">
461
+ <label>Title</label>
462
+ <frontend_type>text</frontend_type>
463
+ <sort_order>20</sort_order>
464
+ <show_in_default>1</show_in_default>
465
+ <show_in_website>1</show_in_website>
466
+ <show_in_store>1</show_in_store>
467
+ </title>
468
+ </fields>
469
+ </optemais_modelc>
470
+ </groups>
471
+ </payment>
472
+ </sections>
473
+ </config>
app/code/community/CsuMarketSystem/OpteMais/sql/optemais_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+
15
+ /** @var $installer Mage_Core_Model_Resource_Setup */
16
+ $installer = $this;
17
+ $installer->startSetup();
18
+
19
+ if (!$installer->tableExists($installer->getTable('optemais/campaign'))) {
20
+ $table = $installer->getConnection()->newTable(
21
+ $installer->getTable('optemais/campaign')
22
+ );
23
+ $table
24
+ ->addColumn(
25
+ 'entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
26
+ array('unsigned' => true, 'nullable' => false, 'primary' => true, 'identity' => true),
27
+ 'Entity ID'
28
+ )
29
+ ->addColumn(
30
+ 'name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255,
31
+ array('nullable' => false),
32
+ 'Name'
33
+ )
34
+ ->addColumn(
35
+ 'description', Varien_Db_Ddl_Table::TYPE_TEXT, 64,
36
+ array('nullable' => true),
37
+ 'Description'
38
+ )
39
+ ->addColumn(
40
+ 'freight_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '5,2', array(
41
+ 'nullable' => false,
42
+ 'default' => '0.00',
43
+ ), 'Freight Discount'
44
+ )
45
+ ->addColumn(
46
+ 'from_date', Varien_Db_Ddl_Table::TYPE_DATE, null,
47
+ array(),
48
+ 'From Date'
49
+ )
50
+ ->addColumn(
51
+ 'to_date', Varien_Db_Ddl_Table::TYPE_DATE, null,
52
+ array(),
53
+ 'To Date'
54
+ )
55
+ ->addColumn(
56
+ 'is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
57
+ 'nullable' => false,
58
+ 'default' => '0',
59
+ ), 'Is Active'
60
+ )
61
+ ->addColumn(
62
+ 'created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
63
+ array(),
64
+ 'Creation Time'
65
+ )
66
+ ->addColumn(
67
+ 'updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
68
+ array(),
69
+ 'Update Time'
70
+ );
71
+
72
+ $installer->getConnection()->createTable($table);
73
+ }
74
+
75
+ if (!$installer->tableExists($installer->getTable('optemais/campaign_item'))) {
76
+ $table = $installer->getConnection()->newTable(
77
+ $installer->getTable('optemais/campaign_item')
78
+ );
79
+ $table
80
+ ->addColumn(
81
+ 'entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
82
+ array('unsigned' => true, 'nullable' => false, 'primary' => true, 'identity' => true),
83
+ 'Entity ID'
84
+ )
85
+ ->addColumn(
86
+ 'campaign_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
87
+ array('unsigned' => true, 'nullable' => false),
88
+ 'Campaign ID'
89
+ )
90
+ ->addColumn(
91
+ 'product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
92
+ array('unsigned' => true, 'nullable' => false),
93
+ 'Product ID'
94
+ )
95
+ ->addColumn(
96
+ 'price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
97
+ 'nullable' => false,
98
+ 'default' => '0.0000',
99
+ ), 'Price'
100
+ )
101
+ ->addColumn(
102
+ 'stock_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
103
+ 'nullable' => false,
104
+ 'default' => '0.0000',
105
+ ), 'Stock Qty'
106
+ )
107
+ ->addColumn(
108
+ 'created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
109
+ array(),
110
+ 'Creation Time'
111
+ )
112
+ ->addColumn(
113
+ 'updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
114
+ array(),
115
+ 'Update Time'
116
+ )
117
+ ->addIndex(
118
+ $installer->getIdxName(
119
+ 'optemais/campaign_item',
120
+ array('campaign_id', 'product_id'),
121
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
122
+ ),
123
+ array('campaign_id', 'product_id'),
124
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
125
+ )
126
+ ->addIndex(
127
+ $installer->getIdxName(
128
+ 'optemais/campaign_item',
129
+ array('campaign_id')
130
+ ),
131
+ array('campaign_id')
132
+ )
133
+ ->addForeignKey(
134
+ $installer->getFkName(
135
+ 'optemais/campaign_item',
136
+ 'campaign_id',
137
+ 'optemais/campaign',
138
+ 'entity_id'
139
+ ),
140
+ 'campaign_id', $installer->getTable('optemais/campaign'), 'entity_id',
141
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
142
+ );
143
+
144
+ $installer->getConnection()->createTable($table);
145
+
146
+ }
147
+
148
+ $installer->endSetup();
app/code/community/CsuMarketSystem/OpteMais/sql/optemais_setup/mysql4-upgrade-1.0.0-1.1.0.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Open Software License (OSL).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://opensource.org/licenses/osl-3.0.php
8
+ *
9
+ * @category CsuMarketSystem
10
+ * @package CsuMarketSystem_OpteMais
11
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
12
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13
+ */
14
+
15
+ /** @var $installer Mage_Core_Model_Resource_Setup */
16
+ $installer = $this;
17
+ $installer->startSetup();
18
+
19
+ $installer->getConnection()->addColumn($installer->getTable('optemais/campaign'),'payment_methods','TEXT NULL DEFAULT NULL AFTER `is_active`');
20
+
21
+ $installer->endSetup();
app/design/adminhtml/default/default/template/optemais/payment/info/modelc.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var $this CsuMarketSystem_OpteMais_Block_Payment_Info_Modelc */
3
+ if ($_info = $this->getInfo()) {
4
+ if ($_info->getOrder()) {
5
+ $payment = $_info->getOrder()->getPayment();
6
+ echo "<b><p>" . $this->__($_info->getMethodInstance()->getTitle()) . "</b></p>";
7
+ }
8
+ }
app/etc/modules/CsuMarketSystem_OpteMais.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://opensource.org/licenses/osl-3.0.php
9
+ *
10
+ * @category CsuMarketSystem
11
+ * @package CsuMarketSystem_OpteMais
12
+ * @copyright Copyright (c) 2016 CSU MarketSystem [www.csu.com.br]
13
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
+ */
15
+ -->
16
+ <config>
17
+ <modules>
18
+ <CsuMarketSystem_OpteMais>
19
+ <active>true</active>
20
+ <codePool>community</codePool>
21
+ </CsuMarketSystem_OpteMais>
22
+ </modules>
23
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>CsuMarketSystem_OpteMais</name>
4
+ <version>1.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Extens&#xE3;o oficial para integra&#xE7;&#xE3;o com o Marketplace OPTe+.</summary>
10
+ <description>Tenha sua loja totalmente integrada com o maior e mais completo Shopping de E-Commerce.&#xD;
11
+ &#xD;
12
+ Para mais informa&#xE7;&#xF5;es: www.optemais.com.br.</description>
13
+ <notes>- Integra&#xE7;&#xE3;o de todo Cat&#xE1;logo (Produtos, Categorias, Atributos e Imagens);&#xD;
14
+ - Cria&#xE7;&#xE3;o de Campanhas;&#xD;
15
+ - Integra&#xE7;&#xE3;o de Pedidos feitos no ambiente da Opte+;</notes>
16
+ <authors><author><name>csumarketsystem</name><user>MAG003432004</user><email>integracaomagento@csu.com.br</email></author></authors>
17
+ <date>2016-06-06</date>
18
+ <time>17:22:58</time>
19
+ <contents><target name="magecommunity"><dir><dir name="CsuMarketSystem"><dir name="OpteMais"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Campaign"><dir name="Edit"><file name="Form.php" hash="0224ccec20310daa354451bdb885ed94"/><dir name="Tab"><file name="Form.php" hash="b6420075c95c1fac234d6693c554b1b0"/><dir name="Product"><file name="Grid.php" hash="f807064e42b11f90736d7a9dca6e2e32"/></dir></dir><file name="Tabs.php" hash="6192f47626cae96918725c265de897eb"/></dir><file name="Edit.php" hash="5fb37aa5528c5bc139bb63126367ebd8"/><file name="Grid.php" hash="88ca48431fecc2500781f49c00c91020"/><dir name="Item"><dir name="Edit"><file name="Form.php" hash="16e4a16e4462309f91ced2eabf30dcf8"/></dir></dir><file name="Item.php" hash="b4c60842f3a73b173ffb9145c178549a"/></dir><file name="Campaign.php" hash="44884ffbc6464f2d95031f45db33dc85"/><file name="Paymentmethod.php" hash="820e3a125362a300c8fca3974e362ba2"/></dir><dir name="Payment"><dir name="Info"><file name="Modelc.php" hash="0a84f429477de898996b0235b65c20ca"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7a1db5b05bc92cca0f1b4ce4fd3b9aec"/></dir><dir name="Model"><file name="Abstract.php" hash="bf404d2900f5da8c166905ae974344d5"/><dir name="Auth"><dir name="Adapter"><file name="Http.php" hash="849b630e8ce379aee56f967d2b65129f"/></dir></dir><dir name="Campaign"><file name="Item.php" hash="76ee48d568206a365b353b25e923ca02"/></dir><file name="Campaign.php" hash="5a68924b6446fa4a1b3b8c06167dfe80"/><dir name="Estimate"><file name="Rate.php" hash="7ab5fc907916144492899e0a526a29ae"/></dir><file name="Observer.php" hash="d40e07a79f07a1d0617ea97a94ec42a6"/><file name="Order.php" hash="62dd398643016e95679547ffc7c7d27b"/><dir name="Payment"><file name="Modelc.php" hash="112fb964895c98495a5a88b580b2720e"/></dir><file name="Product.php" hash="2c8f2d50b856c5476fed6a1d804823e5"/><dir name="Resource"><dir name="Campaign"><file name="Collection.php" hash="e795201d0f518e5e231a69ed4b4016a4"/><dir name="Item"><file name="Collection.php" hash="4e37c2359c649fd9d8a64df7b1ff6915"/></dir><file name="Item.php" hash="8dbba236eda0e15f01b53df639594f63"/></dir><file name="Campaign.php" hash="8d92b66c14476101b684d3bf2f19d985"/></dir><file name="Response.php" hash="46c92e2fde679ce9c68a089143ce9d55"/><file name="Shipping.php" hash="5a3a24a9cb3a76b62ec8b2ca8b4e2be6"/><dir name="Source"><file name="Attributes.php" hash="a81b2d8547f98268942f9aa5579270b6"/><dir name="Campaign"><file name="Actions.php" hash="be6831dec28e0eac7681fc0cb08cf5bc"/><file name="Statuses.php" hash="e614d614d0a49086693f2a2c28e75158"/></dir><dir name="Customer"><file name="Attributes.php" hash="492032dbe0f81c25d712a50ae123f52d"/></dir><dir name="Select"><file name="Attributes.php" hash="e0761b838ed646a96cc1e7cb80f4fdf0"/></dir><dir name="Shipping"><file name="Pricetype.php" hash="4580b8399fddcad4d6d9a6af9f5a5314"/></dir><file name="Shippingmethods.php" hash="b339f7c3f90f15a8b95f4d3b5d2ecb2c"/><file name="Stores.php" hash="6768255eaacb89d9c72ee8e0e3a232a8"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Optemais"><file name="CampaignController.php" hash="c3b2ddc1554f291a8d32e57d20bf561a"/></dir></dir><dir name="Api"><file name="OrderController.php" hash="ede2f74890e94f8ee15aa34c9347e5ce"/><file name="ProductController.php" hash="f3c88c8f09d6be7df71af47025e1b4ee"/><file name="ShippingController.php" hash="e78e99c63e183872aca0e7b48f590b14"/></dir><file name="ApiController.php" hash="7893369fc96e4c9ebab1048dc49d9241"/></dir><dir name="etc"><file name="adminhtml.xml" hash="5b9452d590d86a1f072b47f772c2d1ff"/><file name="config.xml" hash="4b8437339760f1741decfd281445a2bd"/><file name="system.xml" hash="ce122d69111e5dd24dc24e7d7b16562b"/></dir><dir name="sql"><dir name="optemais_setup"><file name="mysql4-install-1.0.0.php" hash="319a1b52745b3c20622346e197854842"/><file name="mysql4-upgrade-1.0.0-1.1.0.php" hash="79f1694a928ea66c85aef99d443fe06c"/></dir></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="optemais"><dir><dir name="payment"><dir name="info"><file name="modelc.phtml" hash="6c2e5bb34b9ae9c97c291fa3bb9c759f"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="CsuMarketSystem_OpteMais.xml" hash="cf6ea247e3b860f2dac4758ac643a767"/></dir></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php></required></dependencies>
22
+ </package>