SKYBOZ456 - Version 1.2.3

Version Notes

Skybox Checkout enables a Magento ecommerce site to sell instantly to 180 countries & territories and accept payment in 140 local currencies. SkyBOX Checkout is a combination of technology tools & services to help retailers expand overseas while offering a localized full landed cost calculation to international shoppers. SkyBOX Checkout takes on full risk of fraud screening & international payments while providing competitive international shipping with full tracking via its proprietary logistics network.

Download this release

Release Info

Developer Emilio Lizarraga
Extension SKYBOZ456
Version 1.2.3
Comparing to
See all releases


Code changes from version 1.2.2 to 1.2.3

Files changed (105) hide show
  1. app/code/community/Skybox/Catalog/Block/Bundle/Price.php +149 -149
  2. app/code/community/Skybox/Catalog/Block/Catalog/Category/Tab/Skyboxcheckout.php +125 -125
  3. app/code/community/Skybox/Catalog/Block/Product/List.php +468 -468
  4. app/code/community/Skybox/Catalog/Block/Product/Price.php +242 -221
  5. app/code/community/Skybox/Catalog/Block/Product/Widget/New.php +48 -48
  6. app/code/community/Skybox/Catalog/Model/Api/Product.php +937 -889
  7. app/code/community/Skybox/Catalog/Model/Observer.php +270 -249
  8. app/code/community/Skybox/Catalog/Model/Product/Attribute/Source/Categories.php +38 -38
  9. app/code/community/Skybox/Catalog/Model/Product/Type/Price.php +64 -64
  10. app/code/community/Skybox/Catalog/Model/Resource/Setup.php +11 -11
  11. app/code/community/Skybox/Catalog/etc/config.xml +174 -174
  12. app/code/community/Skybox/Catalog/sql/skyboxcatalog_setup/mysql4-install-0.1.0.php +70 -70
  13. app/code/community/Skybox/Checkout/Block/Cart/Item/Renderer.php +11 -11
  14. app/code/community/Skybox/Checkout/Block/Cart/Sidebar.php +32 -32
  15. app/code/community/Skybox/Checkout/Block/Cart/Totals.php +157 -171
  16. app/code/community/Skybox/Checkout/Block/Checkout/Cart.php +45 -45
  17. app/code/community/Skybox/Checkout/Block/Checkout/Cart/Sidebar.php +16 -16
  18. app/code/community/Skybox/Checkout/Block/Checkout/Links.php +26 -26
  19. app/code/community/Skybox/Checkout/Block/Checkout/Onepage/Link.php +43 -43
  20. app/code/community/Skybox/Checkout/Block/Sales/Order/Total.php +45 -45
  21. app/code/community/Skybox/Checkout/Helper/Data.php +156 -133
  22. app/code/community/Skybox/Checkout/Helper/Url.php +58 -58
  23. app/code/community/Skybox/Checkout/Model/Api/Checkout.php +222 -220
  24. app/code/community/Skybox/Checkout/Model/Carrier.php +36 -36
  25. app/code/community/Skybox/Checkout/Model/Cart.php +689 -586
  26. app/code/community/Skybox/Checkout/Model/Creditmemo/Total.php +17 -17
  27. app/code/community/Skybox/Checkout/Model/Invoice/Total.php +17 -17
  28. app/code/community/Skybox/Checkout/Model/Observer.php +292 -292
  29. app/code/community/Skybox/Checkout/Model/Pay.php +11 -11
  30. app/code/community/Skybox/Checkout/Model/Quote/Address/Total/Rmt.php +87 -73
  31. app/code/community/Skybox/Checkout/Model/Quote/Address/Total/Tax.php +5 -5
  32. app/code/community/Skybox/Checkout/Model/Quote/SubTotal.php +103 -103
  33. app/code/community/Skybox/Checkout/Model/Quote/Total.php +304 -276
  34. app/code/community/Skybox/Checkout/Model/Quote/Total2.php +7 -7
  35. app/code/community/Skybox/Checkout/Model/Quote/Total3.php +6 -6
  36. app/code/community/Skybox/Checkout/Model/Quote/Total4.php +6 -6
  37. app/code/community/Skybox/Checkout/Model/Quote/Total5.php +6 -6
  38. app/code/community/Skybox/Checkout/Model/Quote/Total6.php +6 -6
  39. app/code/community/Skybox/Checkout/Model/Quote/Total7.php +6 -6
  40. app/code/community/Skybox/Checkout/Model/Quote/Total8.php +7 -7
  41. app/code/community/Skybox/Checkout/controllers/CalculateController.php +127 -127
  42. app/code/community/Skybox/Checkout/controllers/InternationalController.php +66 -65
  43. app/code/community/Skybox/Checkout/controllers/ProcessController.php +335 -300
  44. app/code/community/Skybox/Checkout/etc/config.xml +467 -467
  45. app/code/community/Skybox/Checkout/etc/system.xml +127 -127
  46. app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-install-0.1.0.php +132 -132
  47. app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-0.1.0-0.1.1.php +71 -71
  48. app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-0.1.0-0.1.2.php +18 -18
  49. app/code/community/Skybox/Core/Exception.php +19 -19
  50. app/code/community/Skybox/Core/Helper/Allow.php +236 -0
  51. app/code/community/Skybox/Core/Helper/Data.php +11 -11
  52. app/code/community/Skybox/Core/Helper/Email.php +52 -52
  53. app/code/community/Skybox/Core/Model/Api/Abstract.php +440 -369
  54. app/code/community/Skybox/Core/Model/Api/Restful.php +362 -345
  55. app/code/community/Skybox/Core/Model/Config.php +249 -247
  56. app/code/community/Skybox/Core/Model/Logservice.php +16 -16
  57. app/code/community/Skybox/Core/Model/Mysql4.php +16 -16
  58. app/code/community/Skybox/Core/Model/Mysql4/Logservice.php +22 -22
  59. app/code/community/Skybox/Core/Model/Mysql4/Logservice/Collection.php +17 -17
  60. app/code/community/Skybox/Core/Model/Session.php +29 -29
  61. app/code/community/Skybox/Core/Model/Standard.php +292 -287
  62. app/code/community/Skybox/Core/etc/config.xml +59 -59
  63. app/code/community/Skybox/Core/sql/skyboxcore_setup/mysql4-install-0.1.0.php +69 -69
  64. app/code/community/Skybox/International/Helper/Data.php +77 -72
  65. app/code/community/Skybox/International/Model/Config.php +15 -15
  66. app/code/community/Skybox/International/etc/adminhtml.xml +39 -39
  67. app/code/community/Skybox/International/etc/config.xml +60 -60
  68. app/code/community/Skybox/International/etc/system.xml +133 -133
  69. app/code/community/Skybox/Services/Model/Api.php +309 -309
  70. app/code/community/Skybox/Services/Model/Api/V2.php +11 -11
  71. app/code/community/Skybox/Services/etc/api.xml +37 -37
  72. app/code/community/Skybox/Services/etc/config.xml +25 -25
  73. app/code/community/Skybox/Services/etc/wsdl.xml +141 -141
  74. app/code/community/Skybox/Services/etc/wsi.xml +159 -159
  75. app/design/adminhtml/default/default/layout/skyboxcatalog.xml +7 -7
  76. app/design/adminhtml/default/default/layout/skyboxinternational.xml +14 -14
  77. app/design/frontend/base/default/layout/skyboxcheckout.xml +155 -155
  78. app/design/frontend/base/default/template/skybox/checkout/cart.phtml +291 -356
  79. app/design/frontend/base/default/template/skybox/checkout/cart/item/default.phtml +294 -294
  80. app/design/frontend/base/default/template/skybox/checkout/cart/shipping.phtml +160 -160
  81. app/design/frontend/base/default/template/skybox/checkout/cart/sidebar.phtml +80 -80
  82. app/design/frontend/base/default/template/skybox/checkout/cart/sidebar/default.phtml +146 -146
  83. app/design/frontend/base/default/template/skybox/checkout/cart_list.phtml +195 -195
  84. app/design/frontend/base/default/template/skybox/checkout/onepage.phtml +3 -3
  85. app/design/frontend/base/default/template/skybox/checkout/onepage/link.phtml +41 -41
  86. app/design/frontend/base/default/template/skybox/checkout/pagecheckout.phtml +31 -31
  87. app/design/frontend/base/default/template/skybox/checkout/skyboxcheckout.phtml +399 -437
  88. app/design/frontend/base/default/template/skybox/checkout/skyboxsuccess.phtml +28 -28
  89. app/etc/modules/Skybox_All.xml +35 -35
  90. js/skybox/adminhtml.category.js +10 -10
  91. js/skybox/jquery.ba-resize.min.js +8 -8
  92. js/skybox/jquery.fancybox.js +2020 -0
  93. js/skybox/jquery.min.js +3 -3
  94. js/skybox/load-jquery.js +8 -8
  95. js/skybox/main.js +137 -0
  96. package.xml +4 -4
  97. skin/frontend/base/default/css/skybox/blank.gif +0 -0
  98. skin/frontend/base/default/css/skybox/fancybox_loading.gif +0 -0
  99. skin/frontend/base/default/css/skybox/fancybox_loading@2x.gif +0 -0
  100. skin/frontend/base/default/css/skybox/fancybox_overlay.png +0 -0
  101. skin/frontend/base/default/css/skybox/fancybox_sprite.png +0 -0
  102. skin/frontend/base/default/css/skybox/fancybox_sprite@2x.png +0 -0
  103. skin/frontend/base/default/css/skybox/jquery.fancybox.css +274 -0
  104. skin/frontend/base/default/css/skybox/style.css +109 -0
  105. skin/frontend/base/default/js/skybox/catalog.product.configurable.js +125 -125
app/code/community/Skybox/Catalog/Block/Bundle/Price.php CHANGED
@@ -1,150 +1,150 @@
1
- <?php
2
- /**
3
- * Skybox Checkout
4
- *
5
- * @category Mage
6
- * @package Skybox_Catalog
7
- * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
- */
9
-
10
- /**
11
- * Bundle product price block
12
- *
13
- * @category Skybox
14
- * @package Skybox_Catalog
15
- */
16
- class Skybox_Catalog_Block_Bundle_Price extends Mage_Bundle_Block_Catalog_Product_Price
17
- {
18
- /*
19
- * @var string $_cache_code
20
- */
21
- public $_cache_code = null;
22
-
23
- public function getCacheCode()
24
- {
25
- if ($this->_cache_code == null) {
26
- /* @var $config Skybox_Core_Model_Config */
27
- $config = Mage::getModel("skyboxcore/config");
28
- $skyboxUser = $config->getSession()->getSkyboxUser();
29
- $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
30
- $this->_cache_code = $cache_code;
31
- }
32
- Mage::log("[bundle/price] Cache Code: " . $cache_code, null, 'cache.log', true);
33
- return $this->_cache_code;
34
- }
35
-
36
- /*
37
- protected function _construct()
38
- {
39
- //parent::__construct();
40
- $this->addData(array(
41
- 'cache_lifetime' => 120 //seconds
42
- ));
43
- }
44
- */
45
-
46
- public function getCacheKey()
47
- {
48
- $cache_key = "B_PRODUCT_" . $this->getProduct()->getId() . "_" . $this->getCacheCode();
49
- return $cache_key;
50
- }
51
-
52
- public function getCacheTags()
53
- {
54
- $cache_tag = $this->getProduct()->getId() . "_B_" . $this->getCacheCode();
55
- return array(Mage_Catalog_Model_Product::CACHE_TAG . $cache_tag);
56
- }
57
-
58
- /**
59
- * Retrieve API Product
60
- *
61
- * @return Skybox_Catalog_Model_Api_Product
62
- */
63
- protected function _getApi()
64
- {
65
- if (null === $this->_api) {
66
- $this->_api = Mage::getModel('skyboxcatalog/api_product');
67
- }
68
- return $this->_api;
69
- }
70
-
71
- /**
72
- * Convert block to html string
73
- *
74
- * @return string
75
- */
76
- public function _toHtml()
77
- {
78
- //return parent::_toHtml();
79
- Mage::log("CatalogBlockPrice__toHtmlbundle ", null, 'orden.log', true);
80
- if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
81
- return '';
82
- } elseif ($this->_getApi()->HasError()) {
83
- //$error_code = $this->_getApi()->getStatusCode();
84
- $message = $this->_getApi()->getStatusMessage();
85
- //return '<div style="color:#FF0000;">' . $message . '</div>';
86
- Mage::log("[bundle/price] Some parameter doesn't given to Calculate Price: " . $this->_getApi()->getStatusMessage(), null, 'skyboxcheckout.log', true);
87
- }
88
-
89
- /* @var $product Mage_Catalog_Model_Product */
90
- $product = $this->getProduct();
91
- $type = $product->getTypeId();
92
- $route_name = Mage::app()->getRequest()->getRouteName();
93
- //Mage::log("ROUTER; ". $route_name, null, 'cart.log', true);
94
-
95
- if ($type == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $this->getTemplate() == 'bundle/catalog/product/price.phtml') {
96
- if ($route_name == 'catalog') {
97
- return $this->calculatePrice($product);
98
- }
99
-
100
- // Note: we can't get the "Final Price".
101
- // Moreover, we show "From XXX to XXX" price Block.
102
- //return parent::_toHtml();
103
-
104
- // Note: We make a product type: 'bundle_fixed' to calculate Price and Weight dynamically
105
- return $this->calculatePrice($product, 'bundle_fixed');
106
- }
107
- }
108
-
109
- /**
110
- * Calculate Price HTML output
111
- *
112
- * @param Mage_Catalog_Model_Product $product
113
- * @return string
114
- */
115
- protected function calculatePrice($product, $bundleType = 'bundle')
116
- {
117
- //Mage::log(__FILE__.' # '.__LINE__.' ~ '. __METHOD__.' => enter calculatePrice', null, 'tracer.log', true);
118
- $stockItem = $product->getStockItem();
119
- if (!$stockItem->getIsInStock()) {
120
- return ''; // Out of Stock
121
- }
122
-
123
- $finalPrice = $product->getFinalPrice();
124
- $finalPrice = ($finalPrice > 0) ? $finalPrice : null;
125
-
126
- /*
127
- //$weight = $product->getWeight();
128
- $weight = $product->getTypeInstance(true)->getWeight($product);
129
- Mage::log("[Bundle] " . $product->getName() . " : " . $finalPrice . " - [weight] " . $weight, null, 'cart.log', true);
130
- */
131
-
132
- //$template = $this->_getApi()->CalculatePrice($product, null, null, 'bundle')
133
- //$template = $this->_getApi()->CalculatePrice($product, null, $finalPrice, 'bundle')
134
- $template = $this->_getApi()->CalculatePrice($product, null, $finalPrice, $bundleType)
135
- ->GetTemplateProduct();
136
-
137
- $extraHtml = '<p class="label" id="skybox-configurable-price-from-'
138
- . $product->getId()
139
- . $this->getIdSuffix()
140
- . '">'
141
- . $template
142
- . '</p>'
143
- . '<div style="clear:both"></div>';
144
- //$priceHtml = parent::_toHtml();
145
- #manually insert extra html needed by the extension into the normal price html
146
-
147
- //substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
148
- return $extraHtml;
149
- }
150
}
1
+ <?php
2
+ /**
3
+ * Skybox Checkout
4
+ *
5
+ * @category Mage
6
+ * @package Skybox_Catalog
7
+ * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
+ */
9
+
10
+ /**
11
+ * Bundle product price block
12
+ *
13
+ * @category Skybox
14
+ * @package Skybox_Catalog
15
+ */
16
+ class Skybox_Catalog_Block_Bundle_Price extends Mage_Bundle_Block_Catalog_Product_Price
17
+ {
18
+ /*
19
+ * @var string $_cache_code
20
+ */
21
+ public $_cache_code = null;
22
+
23
+ public function getCacheCode()
24
+ {
25
+ if ($this->_cache_code == null) {
26
+ /* @var $config Skybox_Core_Model_Config */
27
+ $config = Mage::getModel("skyboxcore/config");
28
+ $skyboxUser = $config->getSession()->getSkyboxUser();
29
+ $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
30
+ $this->_cache_code = $cache_code;
31
+ }
32
+ Mage::log("[bundle/price] Cache Code: " . $cache_code, null, 'cache.log', true);
33
+ return $this->_cache_code;
34
+ }
35
+
36
+ /*
37
+ protected function _construct()
38
+ {
39
+ //parent::__construct();
40
+ $this->addData(array(
41
+ 'cache_lifetime' => 120 //seconds
42
+ ));
43
+ }
44
+ */
45
+
46
+ public function getCacheKey()
47
+ {
48
+ $cache_key = "B_PRODUCT_" . $this->getProduct()->getId() . "_" . $this->getCacheCode();
49
+ return $cache_key;
50
+ }
51
+
52
+ public function getCacheTags()
53
+ {
54
+ $cache_tag = $this->getProduct()->getId() . "_B_" . $this->getCacheCode();
55
+ return array(Mage_Catalog_Model_Product::CACHE_TAG . $cache_tag);
56
+ }
57
+
58
+ /**
59
+ * Retrieve API Product
60
+ *
61
+ * @return Skybox_Catalog_Model_Api_Product
62
+ */
63
+ protected function _getApi()
64
+ {
65
+ if (null === $this->_api) {
66
+ $this->_api = Mage::getModel('skyboxcatalog/api_product');
67
+ }
68
+ return $this->_api;
69
+ }
70
+
71
+ /**
72
+ * Convert block to html string
73
+ *
74
+ * @return string
75
+ */
76
+ public function _toHtml()
77
+ {
78
+ //return parent::_toHtml();
79
+ Mage::log("CatalogBlockPrice__toHtmlbundle ", null, 'orden.log', true);
80
+ if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
81
+ return '';
82
+ } elseif ($this->_getApi()->HasError()) {
83
+ //$error_code = $this->_getApi()->getStatusCode();
84
+ $message = $this->_getApi()->getStatusMessage();
85
+ //return '<div style="color:#FF0000;">' . $message . '</div>';
86
+ Mage::log("[bundle/price] Some parameter doesn't given to Calculate Price: " . $this->_getApi()->getStatusMessage(), null, 'skyboxcheckout.log', true);
87
+ }
88
+
89
+ /* @var $product Mage_Catalog_Model_Product */
90
+ $product = $this->getProduct();
91
+ $type = $product->getTypeId();
92
+ $route_name = Mage::app()->getRequest()->getRouteName();
93
+ //Mage::log("ROUTER; ". $route_name, null, 'cart.log', true);
94
+
95
+ if ($type == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $this->getTemplate() == 'bundle/catalog/product/price.phtml') {
96
+ if ($route_name == 'catalog') {
97
+ return $this->calculatePrice($product);
98
+ }
99
+
100
+ // Note: we can't get the "Final Price".
101
+ // Moreover, we show "From XXX to XXX" price Block.
102
+ //return parent::_toHtml();
103
+
104
+ // Note: We make a product type: 'bundle_fixed' to calculate Price and Weight dynamically
105
+ return $this->calculatePrice($product, 'bundle_fixed');
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Calculate Price HTML output
111
+ *
112
+ * @param Mage_Catalog_Model_Product $product
113
+ * @return string
114
+ */
115
+ protected function calculatePrice($product, $bundleType = 'bundle')
116
+ {
117
+ //Mage::log(__FILE__.' # '.__LINE__.' ~ '. __METHOD__.' => enter calculatePrice', null, 'tracer.log', true);
118
+ $stockItem = $product->getStockItem();
119
+ if (!$stockItem->getIsInStock()) {
120
+ return ''; // Out of Stock
121
+ }
122
+
123
+ $finalPrice = $product->getFinalPrice();
124
+ $finalPrice = ($finalPrice > 0) ? $finalPrice : null;
125
+
126
+ /*
127
+ //$weight = $product->getWeight();
128
+ $weight = $product->getTypeInstance(true)->getWeight($product);
129
+ Mage::log("[Bundle] " . $product->getName() . " : " . $finalPrice . " - [weight] " . $weight, null, 'cart.log', true);
130
+ */
131
+
132
+ //$template = $this->_getApi()->CalculatePrice($product, null, null, 'bundle')
133
+ //$template = $this->_getApi()->CalculatePrice($product, null, $finalPrice, 'bundle')
134
+ $template = $this->_getApi()->CalculatePrice($product, null, $finalPrice, $bundleType)
135
+ ->GetTemplateProduct();
136
+
137
+ $extraHtml = '<p class="label" id="skybox-configurable-price-from-'
138
+ . $product->getId()
139
+ . $this->getIdSuffix()
140
+ . '">'
141
+ . $template
142
+ . '</p>'
143
+ . '<div style="clear:both"></div>';
144
+ //$priceHtml = parent::_toHtml();
145
+ #manually insert extra html needed by the extension into the normal price html
146
+
147
+ //substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
148
+ return $extraHtml;
149
+ }
150
}
app/code/community/Skybox/Catalog/Block/Catalog/Category/Tab/Skyboxcheckout.php CHANGED
@@ -1,126 +1,126 @@
1
- <?php
2
- /**
3
- * Skybox Catalog
4
- *
5
- * @category Skybox
6
- * @package Skybox_Catalog
7
- * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
- */
9
-
10
- /**
11
- * Admin form widget
12
- *
13
- * @category Skybox
14
- * @package Skybox_Catalog
15
- */
16
- class Skybox_Catalog_Block_Catalog_Category_Tab_Skyboxcheckout extends Mage_Adminhtml_Block_Widget_Form
17
- {
18
- public $_commodities = null;
19
-
20
- private function _getCommoditiesData()
21
- {
22
- if ($this->_commodities == null) {
23
-
24
- /* var @api_checkout Skybox_Checkout_Model_Api_Checkout*/
25
- $api_checkout = Mage::getModel('skyboxcheckout/api_checkout');
26
- $categories = $api_checkout->GetCategories();
27
-
28
- $options = array('' => '');
29
-
30
- foreach ($categories as $obj) {
31
- $item = array(
32
- $obj->IdCommoditie => $obj->Description,
33
- );
34
- //$options = array_merge($options, $item);
35
- $options = array_replace($options, $item);
36
- }
37
- $this->_commodities = $options;
38
- }
39
- return $this->_commodities;
40
- }
41
-
42
- protected function _prepareForm()
43
- {
44
- $model = Mage::registry('category');
45
-
46
- $form = new Varien_Data_Form(array(
47
- 'id' => 'edit_form',
48
- 'action' => $this->getData('action'),
49
- 'method' => 'post',
50
- 'enctype' => 'multipart/form-data'
51
- ));
52
-
53
- // Form 1
54
- // -----------------------------------------------------------------
55
-
56
- $fieldset = $form->addFieldset('form1_fieldset',
57
- array('legend' => Mage::helper('catalog')->__('For New Products'))
58
- );
59
-
60
- if ($model->getId()) {
61
- $fieldset->addField('attribute_id', 'hidden', array(
62
- 'name' => 'attribute_id',
63
- ));
64
- }
65
-
66
- $options = $this->_getCommoditiesData();
67
-
68
- $fieldset->addField('skybox_category_id', 'select', array(
69
- 'name' => 'skybox_category_id',
70
- 'label' => Mage::helper('catalog')->__('Default commodity'),
71
- 'title' => Mage::helper('catalog')->__('Default commodity'),
72
- //'note' => Mage::helper('catalog')->__('Custom Attribute note'),
73
- 'values' => $options
74
- ));
75
-
76
- // Form 2
77
- // -----------------------------------------------------------------
78
-
79
- $fieldset = $form->addFieldset('form2_fieldset',
80
- array('legend' => Mage::helper('catalog')->__('For Existing Products in Category')));
81
-
82
- // Buttons
83
- $buttons = ' <br/>';
84
- $buttons .= '<br/><button type="button" onclick = "categorySubmit2(\'' . $this->getSaveUrl() . '\', true)" > Apply All Products </button>';
85
- $buttons .= '<br/><br/><button type="button" onclick = "categorySubmit3(\'' . $this->getSaveUrl() . '\', true)" > Apply All Products without Commodities </button>';
86
-
87
- $fieldset->addField('skybox_category_id_select', 'select', array(
88
- 'name' => 'skybox_category_id_select',
89
- 'label' => Mage::helper('catalog')->__('Select commodity'),
90
- 'title' => Mage::helper('catalog')->__('Select commodity'),
91
- 'values' => $options,
92
- 'after_element_html' => $buttons
93
- ));
94
-
95
- $fieldset->addField('apply_button', 'hidden', array(
96
- 'name' => 'apply_button',
97
- ));
98
-
99
- //Mage::log("category->getData()", null, 'skyboxcheckout.log', false);
100
- //Mage::log(print_r($model->getData(), true), null, 'skyboxcheckout.log', false);
101
-
102
- // Set Values
103
- $values = Mage::registry('category')->getData();
104
- $values['apply_button'] = 'nothing';
105
-
106
- $form->setValues($values);
107
- $this->setForm($form);
108
- return parent::_prepareForm();
109
- }
110
-
111
- protected function _getAdditionalElementTypes()
112
- {
113
- return array(
114
- 'apply' => Mage::getConfig()->getBlockClassName('adminhtml / catalog_product_helper_form_apply')
115
- );
116
- }
117
-
118
- public function getSaveUrl(array $args = array())
119
- {
120
- //$params = array('_current' => true);
121
- //$params = array_merge($params, $args);
122
- $params = array();
123
- return $this->getUrl('*/*/save', $params);
124
- }
125
-
126
}
1
+ <?php
2
+ /**
3
+ * Skybox Catalog
4
+ *
5
+ * @category Skybox
6
+ * @package Skybox_Catalog
7
+ * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
+ */
9
+
10
+ /**
11
+ * Admin form widget
12
+ *
13
+ * @category Skybox
14
+ * @package Skybox_Catalog
15
+ */
16
+ class Skybox_Catalog_Block_Catalog_Category_Tab_Skyboxcheckout extends Mage_Adminhtml_Block_Widget_Form
17
+ {
18
+ public $_commodities = null;
19
+
20
+ private function _getCommoditiesData()
21
+ {
22
+ if ($this->_commodities == null) {
23
+
24
+ /* var @api_checkout Skybox_Checkout_Model_Api_Checkout*/
25
+ $api_checkout = Mage::getModel('skyboxcheckout/api_checkout');
26
+ $categories = $api_checkout->GetCategories();
27
+
28
+ $options = array('' => '');
29
+
30
+ foreach ($categories as $obj) {
31
+ $item = array(
32
+ $obj->IdCommoditie => $obj->Description,
33
+ );
34
+ //$options = array_merge($options, $item);
35
+ $options = array_replace($options, $item);
36
+ }
37
+ $this->_commodities = $options;
38
+ }
39
+ return $this->_commodities;
40
+ }
41
+
42
+ protected function _prepareForm()
43
+ {
44
+ $model = Mage::registry('category');
45
+
46
+ $form = new Varien_Data_Form(array(
47
+ 'id' => 'edit_form',
48
+ 'action' => $this->getData('action'),
49
+ 'method' => 'post',
50
+ 'enctype' => 'multipart/form-data'
51
+ ));
52
+
53
+ // Form 1
54
+ // -----------------------------------------------------------------
55
+
56
+ $fieldset = $form->addFieldset('form1_fieldset',
57
+ array('legend' => Mage::helper('catalog')->__('For New Products'))
58
+ );
59
+
60
+ if ($model->getId()) {
61
+ $fieldset->addField('attribute_id', 'hidden', array(
62
+ 'name' => 'attribute_id',
63
+ ));
64
+ }
65
+
66
+ $options = $this->_getCommoditiesData();
67
+
68
+ $fieldset->addField('skybox_category_id', 'select', array(
69
+ 'name' => 'skybox_category_id',
70
+ 'label' => Mage::helper('catalog')->__('Default commodity'),
71
+ 'title' => Mage::helper('catalog')->__('Default commodity'),
72
+ //'note' => Mage::helper('catalog')->__('Custom Attribute note'),
73
+ 'values' => $options
74
+ ));
75
+
76
+ // Form 2
77
+ // -----------------------------------------------------------------
78
+
79
+ $fieldset = $form->addFieldset('form2_fieldset',
80
+ array('legend' => Mage::helper('catalog')->__('For Existing Products in Category')));
81
+
82
+ // Buttons
83
+ $buttons = ' <br/>';
84
+ $buttons .= '<br/><button type="button" onclick = "categorySubmit2(\'' . $this->getSaveUrl() . '\', true)" > Apply All Products </button>';
85
+ $buttons .= '<br/><br/><button type="button" onclick = "categorySubmit3(\'' . $this->getSaveUrl() . '\', true)" > Apply All Products without Commodities </button>';
86
+
87
+ $fieldset->addField('skybox_category_id_select', 'select', array(
88
+ 'name' => 'skybox_category_id_select',
89
+ 'label' => Mage::helper('catalog')->__('Select commodity'),
90
+ 'title' => Mage::helper('catalog')->__('Select commodity'),
91
+ 'values' => $options,
92
+ 'after_element_html' => $buttons
93
+ ));
94
+
95
+ $fieldset->addField('apply_button', 'hidden', array(
96
+ 'name' => 'apply_button',
97
+ ));
98
+
99
+ //Mage::log("category->getData()", null, 'skyboxcheckout.log', false);
100
+ //Mage::log(print_r($model->getData(), true), null, 'skyboxcheckout.log', false);
101
+
102
+ // Set Values
103
+ $values = Mage::registry('category')->getData();
104
+ $values['apply_button'] = 'nothing';
105
+
106
+ $form->setValues($values);
107
+ $this->setForm($form);
108
+ return parent::_prepareForm();
109
+ }
110
+
111
+ protected function _getAdditionalElementTypes()
112
+ {
113
+ return array(
114
+ 'apply' => Mage::getConfig()->getBlockClassName('adminhtml / catalog_product_helper_form_apply')
115
+ );
116
+ }
117
+
118
+ public function getSaveUrl(array $args = array())
119
+ {
120
+ //$params = array('_current' => true);
121
+ //$params = array_merge($params, $args);
122
+ $params = array();
123
+ return $this->getUrl('*/*/save', $params);
124
+ }
125
+
126
}
app/code/community/Skybox/Catalog/Block/Product/List.php CHANGED
@@ -1,468 +1,468 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magento.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magento.com for more information.
20
- *
21
- * @category Mage
22
- * @package Mage_Catalog
23
- * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
-
28
- /**
29
- * Product list
30
- *
31
- * @category Mage
32
- * @package Mage_Catalog
33
- * @author Magento Core Team <core@magentocommerce.com>
34
- */
35
- class Skybox_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List
36
- {
37
- /**
38
- * Default toolbar block name
39
- *
40
- * @var string
41
- */
42
- protected $_defaultToolbarBlock = 'catalog/product_list_toolbar';
43
-
44
- /**
45
- * Product Collection
46
- *
47
- * @var Mage_Eav_Model_Entity_Collection_Abstract
48
- */
49
- protected $_productCollection;
50
-
51
- /**
52
- * Retrieve loaded category collection
53
- *
54
- * @return Mage_Eav_Model_Entity_Collection_Abstract
55
- */
56
- protected function _getProductCollection()
57
- {
58
- if (is_null($this->_productCollection)) {
59
- $layer = $this->getLayer();
60
- /* @var $layer Mage_Catalog_Model_Layer */
61
- if ($this->getShowRootCategory()) {
62
- $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
63
- }
64
-
65
- // if this is a product view page
66
- if (Mage::registry('product')) {
67
- // get collection of categories this product is associated with
68
- $categories = Mage::registry('product')->getCategoryCollection()
69
- ->setPage(1, 1)
70
- ->load();
71
- // if the product is associated with any category
72
- if ($categories->count()) {
73
- // show products from this category
74
- $this->setCategoryId(current($categories->getIterator()));
75
- }
76
- }
77
-
78
- $origCategory = null;
79
- if ($this->getCategoryId()) {
80
- $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
81
- if ($category->getId()) {
82
- $origCategory = $layer->getCurrentCategory();
83
- $layer->setCurrentCategory($category);
84
- $this->addModelTags($category);
85
- }
86
- }
87
- $this->_productCollection = $layer->getProductCollection();
88
-
89
- $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
90
-
91
- if ($origCategory) {
92
- $layer->setCurrentCategory($origCategory);
93
- }
94
- }
95
-
96
- return $this->_productCollection;
97
- }
98
-
99
- /**
100
- * Get catalog layer model
101
- *
102
- * @return Mage_Catalog_Model_Layer
103
- */
104
- public function getLayer()
105
- {
106
- $layer = Mage::registry('current_layer');
107
- if ($layer) {
108
- return $layer;
109
- }
110
- return Mage::getSingleton('catalog/layer');
111
- }
112
-
113
- /**
114
- * Retrieve loaded category collection
115
- *
116
- * @return Mage_Eav_Model_Entity_Collection_Abstract
117
- */
118
- public function getLoadedProductCollection()
119
- {
120
- return $this->_getProductCollection();
121
- }
122
-
123
- /**
124
- * Retrieve current view mode
125
- *
126
- * @return string
127
- */
128
- public function getMode()
129
- {
130
- return $this->getChild('toolbar')->getCurrentMode();
131
- }
132
-
133
- /**
134
- * Retrieve API Product
135
- *
136
- * @return Skybox_Catalog_Model_Api_Product
137
- */
138
- protected function _getApi()
139
- {
140
- if (null === $this->_api) {
141
- $this->_api = Mage::getModel('skyboxcatalog/api_product');
142
- }
143
- return $this->_api;
144
- }
145
-
146
- public function getUrlService($product)
147
- {
148
-
149
- $type = $product->getTypeId();
150
- switch ($type) {
151
- case 'simple':
152
- $template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(), $product->getTypeId());
153
- break;
154
- case 'configurable':
155
- $template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(), $product->getTypeId());
156
- break;
157
- case 'bundle':
158
- $template = $this->_getApi()->getUrl($product, null, $product->getFinalPrice(), 'simple');
159
- break;
160
- }
161
- return $template;
162
- }
163
-
164
- /**
165
- * Need use as _prepareLayout - but problem in declaring collection from
166
- * another block (was problem with search result)
167
- */
168
- protected function _beforeToHtml()
169
- {
170
-
171
- /*ini Load all product of catalog*/
172
-
173
- //var_dump($products); exit;
174
- $session = Mage::getSingleton("core/session", array("name"=>"frontend"));
175
- $sky = $session->getData("skyBox");
176
- /*1 step conexion done*/
177
- $_checkout = Mage::getModel('skyboxcheckout/api_checkout');
178
- $_cartDataURL = "";
179
- $_checkout->InitializeBarSkybox();
180
- $data = $_checkout->getValueAccessService();
181
-
182
- $skyBoxUrlClient = Mage::helper('skyboxinternational/data')->getSkyBoxUrlAPI();
183
- $skyBoxUrlClient = $skyBoxUrlClient . ("multiplecalculate");
184
- //var_dump($skyBoxUrlClient); "https://beta.skyboxcheckout.com/testapi/ApiRest/multiplecalculate"
185
- $products = $this->_getProductCollection();
186
- /*call*/
187
- /*Objeto producto catalogo*/
188
- foreach($products as $prod) {
189
- $product = Mage::getModel('catalog/product')->load($prod->getId());
190
- $data['listproducts'][] = $this->getUrlService($product);
191
- $dataJson = json_encode($data);
192
- }
193
- $this->_getApi()->HtmlTemplateButton();
194
- $template = $this->_getApi()->getHtmlTemplateButton();
195
-
196
- $start = microtime(true);
197
- $resultObjectMultiCurl = $this->file_multi_get_contents_curl($skyBoxUrlClient, $dataJson);
198
-
199
- //var_export($resultObjectMultiCurl);
200
-
201
- /**
202
- * Only works to async version start
203
- */
204
- /*
205
- $time_elapsed_secs = microtime(true) - $start;
206
- echo "<div style='position: absolute;
207
- background: lightgreen;
208
- font-weight: bolder;
209
- z-index: 1111;'>Tiempo de respuesta (Multiple): {$time_elapsed_secs}</div>"."<br/>";
210
-
211
-
212
- $dataMultiCurl = array();
213
- $resultObjectMultiCurl = json_decode($resultObjectMultiCurl);
214
- $resultObjectMultiCurlArray = json_decode(json_encode($resultObjectMultiCurl), true);
215
-
216
- foreach($resultObjectMultiCurlArray['listCalculateResponse'] as $value) {
217
- $dataMultiCurl[$value["HtmlObjectId"]] = $this->getTemplateServicio($value, $template);
218
- }
219
-
220
- $dataMultiCurlVal = array();
221
- $cont = 0;
222
- foreach($products as $key => $prod) {
223
- $dataMultiCurlVal[$prod->getId()] = $dataMultiCurl[$cont];
224
- $cont++;
225
- }
226
- $session->setData("skyBox", $dataMultiCurl);
227
- */
228
- /**
229
- * Only works to async version end
230
- */
231
-
232
- /*end Load all product of catalog*/
233
-
234
-
235
- $toolbar = $this->getToolbarBlock();
236
-
237
- // called prepare sortable parameters
238
- $collection = $this->_getProductCollection();
239
-
240
- // use sortable parameters
241
- if ($orders = $this->getAvailableOrders()) {
242
- $toolbar->setAvailableOrders($orders);
243
- }
244
- if ($sort = $this->getSortBy()) {
245
- $toolbar->setDefaultOrder($sort);
246
- }
247
- if ($dir = $this->getDefaultDirection()) {
248
- $toolbar->setDefaultDirection($dir);
249
- }
250
- if ($modes = $this->getModes()) {
251
- $toolbar->setModes($modes);
252
- }
253
-
254
- // set collection to toolbar and apply sort
255
- $toolbar->setCollection($collection);
256
-
257
- $this->setChild('toolbar', $toolbar);
258
- Mage::dispatchEvent('catalog_block_product_list_collection', array(
259
- 'collection' => $this->_getProductCollection()
260
- ));
261
-
262
- $this->_getProductCollection()->load();
263
-
264
- return parent::_beforeToHtml();
265
- }
266
-
267
- public function getTemplateServicio($objectProduct,$template)
268
- {
269
-
270
-
271
-
272
-
273
-
274
-
275
- /*2step execute get button template*/
276
-
277
- /*var_dump($a->getHtmlTemplateButton());exit;*/
278
-
279
- /*3 step call calculate*/;
280
- if (1) {
281
-
282
- /*$objectProduct = json_decode($objectProduct);
283
- $objectProduct = json_decode(json_encode($objectProduct), true);*/
284
- //var_dump($objectProduct);exit;
285
- foreach ($objectProduct as $key => $value) {
286
- /*echo "==>".$key."<====";
287
- echo "==>".$value."<====";exit;-*/
288
- $template = str_replace('{' . $key . '}', $value, $template);
289
- }
290
-
291
- // Just for {Block} crap
292
- $template = str_replace('{Block}', '', $template);
293
- /*echo "<hit>";
294
- echo($template); exit;
295
- echo "</hit>";*/
296
- /*echo $template; exit;*/
297
- return $template;
298
- }
299
- //exit("debug si es que llega");
300
- /*var_dump($a); exit;
301
- var_dump(Mage::getSingleton('skyboxcore/session')); exit;--*/
302
-
303
-
304
- }
305
-
306
- function file_multi_get_contents_curl($url, $data)
307
- {
308
-
309
- /*var_export($data); exit;*/
310
- if (!function_exists("curl_init")) die("cURL extension is not installed");
311
- $ch = curl_init();
312
- curl_setopt($ch, CURLOPT_URL, $url);
313
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
314
- curl_setopt($ch, CURLOPT_POST, 1);
315
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
316
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
317
- $response = curl_exec($ch);
318
-
319
- /*var_export($response); exit;*/
320
- // Will dump a beauty json :3
321
- //var_dump(json_decode($result, true));
322
- return $response;
323
- /*
324
- $node_count = count($nodes);
325
- $curl_arr = array();
326
- $master = curl_multi_init();
327
- //curl_setopt($master, CURLOPT_SSL_VERIFYPEER, false);
328
- // Will return the response, if false it print the response
329
- //curl_setopt($master, CURLOPT_RETURNTRANSFER, true);
330
-
331
- for($i = 0; $i < count($nodes); $i++)
332
- {
333
- $start = microtime(true);
334
- $url =$nodes[$i];
335
- $curl_arr[$i] = curl_init($url);
336
- curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
337
- curl_multi_add_handle($master, $curl_arr[$i]);
338
- $total_time = round(microtime(true)-$start, 4);
339
- echo "Request #".($i+1).": send {$start} ; delay: {$total_time}"."<br/>";
340
- }
341
-
342
- $start = microtime(true);
343
- do
344
- {
345
- $startMultiExec = microtime(true);
346
- $curl_multi_exec = curl_multi_exec($master,$running);
347
- $totalMultiExec = round(microtime(true)-$startMultiExec, 4);
348
- //echo "Request MultiExec: send {$startMultiExec} ; delay: {$totalMultiExec}"."<br/>";
349
- }
350
- while($running > 0);
351
- $total_time = round(microtime(true)-$start, 4);
352
- echo "Request All: send {$start} ; delay: {$total_time}"."<br/>";
353
-
354
- echo 'results: '."<br/>";
355
- $results = array();
356
- for($i = 0; $i < $node_count; $i++)
357
- {
358
- $preresult = curl_multi_getcontent ( $curl_arr[$i] );
359
- $results[] = $preresult;
360
- echo "<pre>".var_export($results)."</pre>";
361
- echo( $i . '\n' . $results . '\n');
362
- }
363
- echo "<pre>".var_dump($results)."</pre>";
364
-
365
- echo 'done'."<br/>";*/
366
- }
367
-
368
- /**
369
- * Retrieve Toolbar block
370
- *
371
- * @return Mage_Catalog_Block_Product_List_Toolbar
372
- */
373
- public function getToolbarBlock()
374
- {
375
- if ($blockName = $this->getToolbarBlockName()) {
376
- if ($block = $this->getLayout()->getBlock($blockName)) {
377
- return $block;
378
- }
379
- }
380
- $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
381
- return $block;
382
- }
383
-
384
- /**
385
- * Retrieve additional blocks html
386
- *
387
- * @return string
388
- */
389
- public function getAdditionalHtml()
390
- {
391
- return $this->getChildHtml('additional');
392
- }
393
-
394
- /**
395
- * Retrieve list toolbar HTML
396
- *
397
- * @return string
398
- */
399
- public function getToolbarHtml()
400
- {
401
- return $this->getChildHtml('toolbar');
402
- }
403
-
404
- public function setCollection($collection)
405
- {
406
- $this->_productCollection = $collection;
407
- return $this;
408
- }
409
-
410
- public function addAttribute($code)
411
- {
412
- $this->_getProductCollection()->addAttributeToSelect($code);
413
- return $this;
414
- }
415
-
416
- public function getPriceBlockTemplate()
417
- {
418
- return $this->_getData('price_block_template');
419
- }
420
-
421
- /**
422
- * Retrieve Catalog Config object
423
- *
424
- * @return Mage_Catalog_Model_Config
425
- */
426
- protected function _getConfig()
427
- {
428
- return Mage::getSingleton('catalog/config');
429
- }
430
-
431
- /**
432
- * Prepare Sort By fields from Category Data
433
- *
434
- * @param Mage_Catalog_Model_Category $category
435
- * @return Mage_Catalog_Block_Product_List
436
- */
437
- public function prepareSortableFieldsByCategory($category) {
438
- if (!$this->getAvailableOrders()) {
439
- $this->setAvailableOrders($category->getAvailableSortByOptions());
440
- }
441
- $availableOrders = $this->getAvailableOrders();
442
- if (!$this->getSortBy()) {
443
- if ($categorySortBy = $category->getDefaultSortBy()) {
444
- if (!$availableOrders) {
445
- $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();
446
- }
447
- if (isset($availableOrders[$categorySortBy])) {
448
- $this->setSortBy($categorySortBy);
449
- }
450
- }
451
- }
452
-
453
- return $this;
454
- }
455
-
456
- /**
457
- * Retrieve block cache tags based on product collection
458
- *
459
- * @return array
460
- */
461
- public function getCacheTags()
462
- {
463
- return array_merge(
464
- parent::getCacheTags(),
465
- $this->getItemsTags($this->_getProductCollection())
466
- );
467
- }
468
- }
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Product list
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Catalog
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Skybox_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List
36
+ {
37
+ /**
38
+ * Default toolbar block name
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_defaultToolbarBlock = 'catalog/product_list_toolbar';
43
+
44
+ /**
45
+ * Product Collection
46
+ *
47
+ * @var Mage_Eav_Model_Entity_Collection_Abstract
48
+ */
49
+ protected $_productCollection;
50
+
51
+ /**
52
+ * Retrieve loaded category collection
53
+ *
54
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
55
+ */
56
+ protected function _getProductCollection()
57
+ {
58
+ if (is_null($this->_productCollection)) {
59
+ $layer = $this->getLayer();
60
+ /* @var $layer Mage_Catalog_Model_Layer */
61
+ if ($this->getShowRootCategory()) {
62
+ $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
63
+ }
64
+
65
+ // if this is a product view page
66
+ if (Mage::registry('product')) {
67
+ // get collection of categories this product is associated with
68
+ $categories = Mage::registry('product')->getCategoryCollection()
69
+ ->setPage(1, 1)
70
+ ->load();
71
+ // if the product is associated with any category
72
+ if ($categories->count()) {
73
+ // show products from this category
74
+ $this->setCategoryId(current($categories->getIterator()));
75
+ }
76
+ }
77
+
78
+ $origCategory = null;
79
+ if ($this->getCategoryId()) {
80
+ $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
81
+ if ($category->getId()) {
82
+ $origCategory = $layer->getCurrentCategory();
83
+ $layer->setCurrentCategory($category);
84
+ $this->addModelTags($category);
85
+ }
86
+ }
87
+ $this->_productCollection = $layer->getProductCollection();
88
+
89
+ $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
90
+
91
+ if ($origCategory) {
92
+ $layer->setCurrentCategory($origCategory);
93
+ }
94
+ }
95
+
96
+ return $this->_productCollection;
97
+ }
98
+
99
+ /**
100
+ * Get catalog layer model
101
+ *
102
+ * @return Mage_Catalog_Model_Layer
103
+ */
104
+ public function getLayer()
105
+ {
106
+ $layer = Mage::registry('current_layer');
107
+ if ($layer) {
108
+ return $layer;
109
+ }
110
+ return Mage::getSingleton('catalog/layer');
111
+ }
112
+
113
+ /**
114
+ * Retrieve loaded category collection
115
+ *
116
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
117
+ */
118
+ public function getLoadedProductCollection()
119
+ {
120
+ return $this->_getProductCollection();
121
+ }
122
+
123
+ /**
124
+ * Retrieve current view mode
125
+ *
126
+ * @return string
127
+ */
128
+ public function getMode()
129
+ {
130
+ return $this->getChild('toolbar')->getCurrentMode();
131
+ }
132
+
133
+ /**
134
+ * Retrieve API Product
135
+ *
136
+ * @return Skybox_Catalog_Model_Api_Product
137
+ */
138
+ protected function _getApi()
139
+ {
140
+ if (null === $this->_api) {
141
+ $this->_api = Mage::getModel('skyboxcatalog/api_product');
142
+ }
143
+ return $this->_api;
144
+ }
145
+
146
+ public function getUrlService($product)
147
+ {
148
+
149
+ $type = $product->getTypeId();
150
+ switch ($type) {
151
+ case 'simple':
152
+ $template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(), $product->getTypeId());
153
+ break;
154
+ case 'configurable':
155
+ $template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(), $product->getTypeId());
156
+ break;
157
+ case 'bundle':
158
+ $template = $this->_getApi()->getUrl($product, null, $product->getFinalPrice(), 'simple');
159
+ break;
160
+ }
161
+ return $template;
162
+ }
163
+
164
+ /**
165
+ * Need use as _prepareLayout - but problem in declaring collection from
166
+ * another block (was problem with search result)
167
+ */
168
+ protected function _beforeToHtml()
169
+ {
170
+
171
+ /*ini Load all product of catalog*/
172
+
173
+ //var_dump($products); exit;
174
+ $session = Mage::getSingleton("core/session", array("name"=>"frontend"));
175
+ $sky = $session->getData("skyBox");
176
+ /*1 step conexion done*/
177
+ $_checkout = Mage::getModel('skyboxcheckout/api_checkout');
178
+ $_cartDataURL = "";
179
+ $_checkout->InitializeBarSkybox();
180
+ $data = $_checkout->getValueAccessService();
181
+
182
+ $skyBoxUrlClient = Mage::helper('skyboxinternational/data')->getSkyBoxUrlAPI();
183
+ $skyBoxUrlClient = $skyBoxUrlClient . ("multiplecalculate");
184
+ //var_dump($skyBoxUrlClient); "https://beta.skyboxcheckout.com/testapi/ApiRest/multiplecalculate"
185
+ $products = $this->_getProductCollection();
186
+ /*call*/
187
+ /*Objeto producto catalogo*/
188
+ foreach($products as $prod) {
189
+ $product = Mage::getModel('catalog/product')->load($prod->getId());
190
+ $data['listproducts'][] = $this->getUrlService($product);
191
+ $dataJson = json_encode($data);
192
+ }
193
+ $this->_getApi()->HtmlTemplateButton();
194
+ $template = $this->_getApi()->getHtmlTemplateButton();
195
+
196
+ $start = microtime(true);
197
+ $resultObjectMultiCurl = $this->file_multi_get_contents_curl($skyBoxUrlClient, $dataJson);
198
+
199
+ //var_export($resultObjectMultiCurl);
200
+
201
+ /**
202
+ * Only works to async version start
203
+ */
204
+ /*
205
+ $time_elapsed_secs = microtime(true) - $start;
206
+ echo "<div style='position: absolute;
207
+ background: lightgreen;
208
+ font-weight: bolder;
209
+ z-index: 1111;'>Tiempo de respuesta (Multiple): {$time_elapsed_secs}</div>"."<br/>";
210
+
211
+
212
+ $dataMultiCurl = array();
213
+ $resultObjectMultiCurl = json_decode($resultObjectMultiCurl);
214
+ $resultObjectMultiCurlArray = json_decode(json_encode($resultObjectMultiCurl), true);
215
+
216
+ foreach($resultObjectMultiCurlArray['listCalculateResponse'] as $value) {
217
+ $dataMultiCurl[$value["HtmlObjectId"]] = $this->getTemplateServicio($value, $template);
218
+ }
219
+
220
+ $dataMultiCurlVal = array();
221
+ $cont = 0;
222
+ foreach($products as $key => $prod) {
223
+ $dataMultiCurlVal[$prod->getId()] = $dataMultiCurl[$cont];
224
+ $cont++;
225
+ }
226
+ $session->setData("skyBox", $dataMultiCurl);
227
+ */
228
+ /**
229
+ * Only works to async version end
230
+ */
231
+
232
+ /*end Load all product of catalog*/
233
+
234
+
235
+ $toolbar = $this->getToolbarBlock();
236
+
237
+ // called prepare sortable parameters
238
+ $collection = $this->_getProductCollection();
239
+
240
+ // use sortable parameters
241
+ if ($orders = $this->getAvailableOrders()) {
242
+ $toolbar->setAvailableOrders($orders);
243
+ }
244
+ if ($sort = $this->getSortBy()) {
245
+ $toolbar->setDefaultOrder($sort);
246
+ }
247
+ if ($dir = $this->getDefaultDirection()) {
248
+ $toolbar->setDefaultDirection($dir);
249
+ }
250
+ if ($modes = $this->getModes()) {
251
+ $toolbar->setModes($modes);
252
+ }
253
+
254
+ // set collection to toolbar and apply sort
255
+ $toolbar->setCollection($collection);
256
+
257
+ $this->setChild('toolbar', $toolbar);
258
+ Mage::dispatchEvent('catalog_block_product_list_collection', array(
259
+ 'collection' => $this->_getProductCollection()
260
+ ));
261
+
262
+ $this->_getProductCollection()->load();
263
+
264
+ return parent::_beforeToHtml();
265
+ }
266
+
267
+ public function getTemplateServicio($objectProduct,$template)
268
+ {
269
+
270
+
271
+
272
+
273
+
274
+
275
+ /*2step execute get button template*/
276
+
277
+ /*var_dump($a->getHtmlTemplateButton());exit;*/
278
+
279
+ /*3 step call calculate*/;
280
+ if (1) {
281
+
282
+ /*$objectProduct = json_decode($objectProduct);
283
+ $objectProduct = json_decode(json_encode($objectProduct), true);*/
284
+ //var_dump($objectProduct);exit;
285
+ foreach ($objectProduct as $key => $value) {
286
+ /*echo "==>".$key."<====";
287
+ echo "==>".$value."<====";exit;-*/
288
+ $template = str_replace('{' . $key . '}', $value, $template);
289
+ }
290
+
291
+ // Just for {Block} crap
292
+ $template = str_replace('{Block}', '', $template);
293
+ /*echo "<hit>";
294
+ echo($template); exit;
295
+ echo "</hit>";*/
296
+ /*echo $template; exit;*/
297
+ return $template;
298
+ }
299
+ //exit("debug si es que llega");
300
+ /*var_dump($a); exit;
301
+ var_dump(Mage::getSingleton('skyboxcore/session')); exit;--*/
302
+
303
+
304
+ }
305
+
306
+ function file_multi_get_contents_curl($url, $data)
307
+ {
308
+
309
+ /*var_export($data); exit;*/
310
+ if (!function_exists("curl_init")) die("cURL extension is not installed");
311
+ $ch = curl_init();
312
+ curl_setopt($ch, CURLOPT_URL, $url);
313
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
314
+ curl_setopt($ch, CURLOPT_POST, 1);
315
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
316
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
317
+ $response = curl_exec($ch);
318
+
319
+ /*var_export($response); exit;*/
320
+ // Will dump a beauty json :3
321
+ //var_dump(json_decode($result, true));
322
+ return $response;
323
+ /*
324
+ $node_count = count($nodes);
325
+ $curl_arr = array();
326
+ $master = curl_multi_init();
327
+ //curl_setopt($master, CURLOPT_SSL_VERIFYPEER, false);
328
+ // Will return the response, if false it print the response
329
+ //curl_setopt($master, CURLOPT_RETURNTRANSFER, true);
330
+
331
+ for($i = 0; $i < count($nodes); $i++)
332
+ {
333
+ $start = microtime(true);
334
+ $url =$nodes[$i];
335
+ $curl_arr[$i] = curl_init($url);
336
+ curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
337
+ curl_multi_add_handle($master, $curl_arr[$i]);
338
+ $total_time = round(microtime(true)-$start, 4);
339
+ echo "Request #".($i+1).": send {$start} ; delay: {$total_time}"."<br/>";
340
+ }
341
+
342
+ $start = microtime(true);
343
+ do
344
+ {
345
+ $startMultiExec = microtime(true);
346
+ $curl_multi_exec = curl_multi_exec($master,$running);
347
+ $totalMultiExec = round(microtime(true)-$startMultiExec, 4);
348
+ //echo "Request MultiExec: send {$startMultiExec} ; delay: {$totalMultiExec}"."<br/>";
349
+ }
350
+ while($running > 0);
351
+ $total_time = round(microtime(true)-$start, 4);
352
+ echo "Request All: send {$start} ; delay: {$total_time}"."<br/>";
353
+
354
+ echo 'results: '."<br/>";
355
+ $results = array();
356
+ for($i = 0; $i < $node_count; $i++)
357
+ {
358
+ $preresult = curl_multi_getcontent ( $curl_arr[$i] );
359
+ $results[] = $preresult;
360
+ echo "<pre>".var_export($results)."</pre>";
361
+ echo( $i . '\n' . $results . '\n');
362
+ }
363
+ echo "<pre>".var_dump($results)."</pre>";
364
+
365
+ echo 'done'."<br/>";*/
366
+ }
367
+
368
+ /**
369
+ * Retrieve Toolbar block
370
+ *
371
+ * @return Mage_Catalog_Block_Product_List_Toolbar
372
+ */
373
+ public function getToolbarBlock()
374
+ {
375
+ if ($blockName = $this->getToolbarBlockName()) {
376
+ if ($block = $this->getLayout()->getBlock($blockName)) {
377
+ return $block;
378
+ }
379
+ }
380
+ $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
381
+ return $block;
382
+ }
383
+
384
+ /**
385
+ * Retrieve additional blocks html
386
+ *
387
+ * @return string
388
+ */
389
+ public function getAdditionalHtml()
390
+ {
391
+ return $this->getChildHtml('additional');
392
+ }
393
+
394
+ /**
395
+ * Retrieve list toolbar HTML
396
+ *
397
+ * @return string
398
+ */
399
+ public function getToolbarHtml()
400
+ {
401
+ return $this->getChildHtml('toolbar');
402
+ }
403
+
404
+ public function setCollection($collection)
405
+ {
406
+ $this->_productCollection = $collection;
407
+ return $this;
408
+ }
409
+
410
+ public function addAttribute($code)
411
+ {
412
+ $this->_getProductCollection()->addAttributeToSelect($code);
413
+ return $this;
414
+ }
415
+
416
+ public function getPriceBlockTemplate()
417
+ {
418
+ return $this->_getData('price_block_template');
419
+ }
420
+
421
+ /**
422
+ * Retrieve Catalog Config object
423
+ *
424
+ * @return Mage_Catalog_Model_Config
425
+ */
426
+ protected function _getConfig()
427
+ {
428
+ return Mage::getSingleton('catalog/config');
429
+ }
430
+
431
+ /**
432
+ * Prepare Sort By fields from Category Data
433
+ *
434
+ * @param Mage_Catalog_Model_Category $category
435
+ * @return Mage_Catalog_Block_Product_List
436
+ */
437
+ public function prepareSortableFieldsByCategory($category) {
438
+ if (!$this->getAvailableOrders()) {
439
+ $this->setAvailableOrders($category->getAvailableSortByOptions());
440
+ }
441
+ $availableOrders = $this->getAvailableOrders();
442
+ if (!$this->getSortBy()) {
443
+ if ($categorySortBy = $category->getDefaultSortBy()) {
444
+ if (!$availableOrders) {
445
+ $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();
446
+ }
447
+ if (isset($availableOrders[$categorySortBy])) {
448
+ $this->setSortBy($categorySortBy);
449
+ }
450
+ }
451
+ }
452
+
453
+ return $this;
454
+ }
455
+
456
+ /**
457
+ * Retrieve block cache tags based on product collection
458
+ *
459
+ * @return array
460
+ */
461
+ public function getCacheTags()
462
+ {
463
+ return array_merge(
464
+ parent::getCacheTags(),
465
+ $this->getItemsTags($this->_getProductCollection())
466
+ );
467
+ }
468
+ }
app/code/community/Skybox/Catalog/Block/Product/Price.php CHANGED
@@ -1,221 +1,242 @@
1
- <?php
2
- /**
3
- * Skybox Checkout
4
- *
5
- * @category Mage
6
- * @package Skybox_Catalog
7
- * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
- */
9
-
10
- /**
11
- *
12
- * Product price Block
13
- *
14
- * @author C├ęsar Tapia M. <ctapia@skyworldint.com>
15
- */
16
- class Skybox_Catalog_Block_Product_Price extends Mage_Catalog_Block_Product_Price
17
- {
18
- /*
19
- * @var string $_cache_code
20
- */
21
- public $_cache_code = null;
22
-
23
- public function getCacheCode()
24
- {
25
- Mage::log("cache ", null, 'orden.log', true);
26
- if ($this->_cache_code == null) {
27
- /* @var $config Skybox_Core_Model_Config */
28
- $config = Mage::getModel("skyboxcore/config");
29
- $skyboxUser = $config->getSession()->getSkyboxUser();
30
- $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
31
- $this->_cache_code = $cache_code;
32
- }
33
- Mage::log("[product/price] Cache Code: " . $cache_code, null, 'cache.log', true);
34
- return $this->_cache_code;
35
- }
36
-
37
- /*
38
- protected function _construct()
39
- {
40
- //parent::__construct();
41
- $this->addData(array(
42
- 'cache_lifetime' => 120 //seconds
43
- ));
44
- }
45
- */
46
-
47
- public function getCacheKey()
48
- {
49
- $cache_key = "PRODUCT_" . $this->getProduct()->getId() . "_" . $this->getCacheCode();
50
- return $cache_key;
51
- }
52
-
53
- public function getCacheTags()
54
- {
55
- $cache_tag = $this->getProduct()->getId() . "_" . $this->getCacheCode();
56
- return array(Mage_Catalog_Model_Product::CACHE_TAG . $cache_tag);
57
- }
58
-
59
- /**
60
- * Retrieve API Product
61
- *
62
- * @return Skybox_Catalog_Model_Api_Product
63
- */
64
- protected function _getApi()
65
- {
66
- if (null === $this->_api) {
67
- $this->_api = Mage::getModel('skyboxcatalog/api_product');
68
- }
69
- return $this->_api;
70
- }
71
-
72
- /**
73
- * Render block HTML
74
- *
75
- * @return string
76
- */
77
- public function _toHtml()
78
- {
79
- //echo "locationAllow: ".$this->_getApi()->getLocationAllow();
80
- // $activation = (bool)Mage::getStoreConfig('skyboxinternational/skyboxsettings/skyboxactive', Mage::app()->getStore());
81
- $activation = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
82
-
83
- if (!$activation) {
84
- return '';
85
- }
86
- $typeIntegration = Mage::helper('skyboxinternational/data')->getSkyboxIntegration();
87
- //Mage::log(print_r('product\Price::_toHtml', true), null, 'tracer.log', true);
88
- if($this->_getApi()->getLocationAllow() && ($typeIntegration!=3)) { // Rogged
89
- if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
90
- return '';
91
- } elseif ($this->_getApi()->HasError()) {
92
- //$error_code = $this->_getApi()->getStatusCode();
93
- $message = $this->_getApi()->getStatusMessage();
94
- return '';
95
- // return '<div style="color:#FF0000;">' . $message . '</div>';
96
- }
97
-
98
- /* @var $product Mage_Catalog_Model_Product */
99
- $product = $this->getProduct();
100
- $type = $product->getTypeId();
101
- $route_name = Mage::app()->getRequest()->getRouteName();
102
-
103
- // Mage::log(print_r('$route_name: '. $route_name, true), null, 'tracer.log', true);
104
-
105
- // Simple Product
106
- if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/price.phtml') {
107
- return $this->calculatePrice($product);
108
- }
109
-
110
-
111
- if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/view/price_clone.phtml') {
112
- return '';
113
- }
114
-
115
- // Configurable Product
116
- if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/price.phtml') {
117
- /*if ($route_name == 'catalog') {
118
- return '';
119
- }*/
120
-
121
- if(Mage::registry('current_product')) {
122
- return "";
123
- }
124
-
125
- return $this->calculatePrice($product);
126
- }
127
-
128
- if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/view/tierprices.phtml') {
129
- if ($route_name == 'catalog') {
130
- return $this->calculatePrice($product);
131
- }
132
- return '';
133
- }
134
- }
135
- return parent::_toHtml();
136
- }
137
-
138
- /**
139
- * Calculate Price HTML output
140
- *
141
- * @param Mage_Catalog_Model_Product $product
142
- * @return string
143
- */
144
- protected function calculatePrice($product)
145
- {
146
- //Mage::log('Entro calcular producto', null, 'tracer.log', true);
147
- $stockItem = $product->getStockItem();
148
- // if (!$stockItem->getIsInStock()) {
149
- // Mage::log('sin stock', null, 'tracer.log', true);
150
- // return ''; // Out of Stock
151
- // }
152
-
153
- $type = $product->getTypeId();
154
- //Mage::log(print_r('product\Price: '.$type, true), null, 'tracer.log', true);
155
-
156
- if (Mage::registry('current_category')){
157
- /*Async Ini*/
158
- $session = Mage::getSingleton("core/session", array("name"=>"frontend"));
159
- $skyboxPrecio = $session->getData("skyBox");
160
- /*
161
- if($product->getTypeId() == "simple"){
162
- $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
163
- if(!$parentIds)
164
- $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
165
- if(isset($parentIds[0])){
166
- $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
167
- // do stuff here
168
- }
169
- }*/
170
- $template = $skyboxPrecio[$product->getId()];
171
- $template = '<div class="skybox-price-set" product-id="' . $product->getId() . '" id="product-' . $product->getId() . '"></div>';
172
- /*Async End*/
173
- } else {
174
- switch ($type) {
175
- case 'simple':
176
- $template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(), $product->getTypeId())
177
- ->GetTemplateProduct();
178
- break;
179
- case 'configurable':
180
- $template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(), $product->getTypeId())
181
- ->GetTemplateProduct();
182
- break;
183
- case 'bundle':
184
- $template = $this->_getApi()->CalculatePrice($product, null, $product->getFinalPrice(), 'simple')
185
- ->GetTemplateProduct();
186
- break;
187
- }
188
- }
189
-
190
- // Mage::log(print_r('##Product template##', true), null, 'tracer.log', true);
191
- // Mage::log(print_r($template, true), null, 'tracer.log', true);
192
- /*
193
- $extraHtml = ''
194
- . '<div class="price-box">'
195
- . '<p class="label" id="skybox-configurable-price-from-'
196
- . $product->getId()
197
- . $this->getIdSuffix()
198
- . '">'
199
- . $template
200
- . '</p>'
201
- . '</div>'
202
- . '<div style="clear:both"></div>';
203
-
204
- */
205
- $extraHtml = ''
206
- . '<div class="price-box">'
207
- . '<p class="label" id="skybox-configurable-price-from-'
208
- . $product->getId()
209
- . $this->getIdSuffix()
210
- . '">'
211
- . $template
212
- . '</p>'
213
- . '</div>'
214
- . '<div style="clear:both"></div>';
215
- //$priceHtml = parent::_toHtml();
216
- #manually insert extra html needed by the extension into the normal price html
217
-
218
- //substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
219
- return $extraHtml;
220
- }
221
- }
1
+ <?php
2
+ /**
3
+ * Skybox Checkout
4
+ *
5
+ * @category Mage
6
+ * @package Skybox_Catalog
7
+ * @copyright Copyright (c) 2014 - 2017 Skybox Checkout. (http://www.skyboxcheckout.com)
8
+ */
9
+
10
+ /**
11
+ *
12
+ * Product Price Block
13
+ */
14
+ class Skybox_Catalog_Block_Product_Price extends Mage_Catalog_Block_Product_Price
15
+ {
16
+ /*
17
+ * @var string $_cache_code
18
+ */
19
+ public $_cache_code = null;
20
+
21
+ public function getCacheCode()
22
+ {
23
+ Mage::log("cache ", null, 'orden.log', true);
24
+ if ($this->_cache_code == null) {
25
+ /* @var $config Skybox_Core_Model_Config */
26
+ $config = Mage::getModel("skyboxcore/config");
27
+ $skyboxUser = $config->getSession()->getSkyboxUser();
28
+ $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
29
+ $this->_cache_code = $cache_code;
30
+ }
31
+ Mage::log("[product/price] Cache Code: " . $cache_code, null, 'cache.log', true);
32
+ return $this->_cache_code;
33
+ }
34
+
35
+ /*
36
+ protected function _construct()
37
+ {
38
+ //parent::__construct();
39
+ $this->addData(array(
40
+ 'cache_lifetime' => 120 //seconds
41
+ ));
42
+ }
43
+ */
44
+
45
+ public function getCacheKey()
46
+ {
47
+ $cache_key = "PRODUCT_" . $this->getProduct()->getId() . "_" . $this->getCacheCode();
48
+ return $cache_key;
49
+ }
50
+
51
+ public function getCacheTags()
52
+ {
53
+ $cache_tag = $this->getProduct()->getId() . "_" . $this->getCacheCode();
54
+ return array(Mage_Catalog_Model_Product::CACHE_TAG . $cache_tag);
55
+ }
56
+
57
+ /**
58
+ * Retrieve API Product
59
+ *
60
+ * @return Skybox_Catalog_Model_Api_Product
61
+ */
62
+ protected function _getApi()
63
+ {
64
+ if (null === $this->_api) {
65
+ $this->_api = Mage::getModel('skyboxcatalog/api_product');
66
+ }
67
+ return $this->_api;
68
+ }
69
+
70
+ /**
71
+ * Render block HTML
72
+ *
73
+ * @return string
74
+ */
75
+ public function _toHtml()
76
+ {
77
+ $activation = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
78
+
79
+ if (!$activation) {
80
+ return '';
81
+ }
82
+ //$typeIntegration = Mage::getStoreConfig('settings/typeIntegration');
83
+ $typeIntegration = Mage::helper('skyboxinternational/data')->getSkyboxIntegration();
84
+ //Mage::log(print_r('product\Price::_toHtml', true), null, 'tracer.log', true);
85
+ if ($this->_getApi()->getLocationAllow() && ($typeIntegration != 3)) {
86
+ if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
87
+ return '';
88
+ } elseif ($this->_getApi()->HasError()) {
89
+ //$error_code = $this->_getApi()->getStatusCode();
90
+ $message = $this->_getApi()->getStatusMessage();
91
+
92
+ if ($this->_getApi()->_getApi()->ErrorRatesNotFound()) {
93
+ $message = $this->_getApi()->_getApi()->getErrorRatesNotFoundMessage($this->getLanguageId());
94
+ return '<div style="color:#FF0000;">' . $message . '</div>';
95
+ }
96
+
97
+ // return '<div style="color:#FF0000;">' . $message . '</div>';
98
+ return '';
99
+ }
100
+
101
+ /* @var $product Mage_Catalog_Model_Product */
102
+ $product = $this->getProduct();
103
+ $type = $product->getTypeId();
104
+ $route_name = Mage::app()->getRequest()->getRouteName();
105
+
106
+ // Mage::log(print_r('$route_name: '. $route_name, true), null, 'tracer.log', true);
107
+
108
+ // Simple Product
109
+ if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/price.phtml') {
110
+ return $this->calculatePrice($product);
111
+ }
112
+
113
+
114
+ if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/view/price_clone.phtml') {
115
+ return '';
116
+ }
117
+
118
+ // Configurable Product
119
+ if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/price.phtml') {
120
+ /*if ($route_name == 'catalog') {
121
+ return '';
122
+ }*/
123
+
124
+ if (Mage::registry('current_product')) {
125
+ return "";
126
+ }
127
+
128
+ return $this->calculatePrice($product);
129
+ }
130
+
131
+ if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/view/tierprices.phtml') {
132
+ if ($route_name == 'catalog') {
133
+ return $this->calculatePrice($product);
134
+ }
135
+ return '';
136
+ }
137
+ }
138
+ return parent::_toHtml();
139
+ }
140
+
141
+ /**
142
+ * Calculate Price HTML output
143
+ *
144
+ * @param Mage_Catalog_Model_Product $product
145
+ * @return string
146
+ */
147
+ protected function calculatePrice($product)
148
+ {
149
+ //Mage::log('Entro calcular producto', null, 'tracer.log', true);
150
+ $stockItem = $product->getStockItem();
151
+ // if (!$stockItem->getIsInStock()) {
152
+ // Mage::log('sin stock', null, 'tracer.log', true);
153
+ // return ''; // Out of Stock
154
+ // }
155
+
156
+ $type = $product->getTypeId();
157
+ //Mage::log(print_r('product\Price: '.$type, true), null, 'tracer.log', true);
158
+
159
+ if (Mage::registry('current_category') and (!(Mage::registry('current_product')))) {
160
+ /**
161
+ * Apply multiple calculate start
162
+ * When: is different to product detail and you are on catalog category
163
+ */
164
+ $template = '<div class="skybox-price-set" product-id="' . $product->getId() . '" id="product-' . $product->getId() . '"></div>';
165
+ /*
166
+ if($product->getTypeId() == "simple"){
167
+ $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
168
+ if(!$parentIds)
169
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
170
+ if(isset($parentIds[0])){
171
+ $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
172
+ // do stuff here
173
+ }
174
+ }*/
175
+
176
+ /**
177
+ * Apply multiple calculate end
178
+ */
179
+ } else {
180
+ switch ($type) {
181
+ case 'simple':
182
+ $template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
183
+ $product->getTypeId())
184
+ ->GetTemplateProduct();
185
+ break;
186
+ case 'configurable':
187
+ $template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
188
+ $product->getTypeId())
189
+ ->GetTemplateProduct();
190
+ break;
191
+ case 'bundle':
192
+ $template = $this->_getApi()->CalculatePrice($product, null, $product->getFinalPrice(), 'simple')
193
+ ->GetTemplateProduct();
194
+ break;
195
+ }
196
+ }
197
+
198
+ // Mage::log(print_r('##Product template##', true), null, 'tracer.log', true);
199
+ // Mage::log(print_r($template, true), null, 'tracer.log', true);
200
+ /*
201
+ $extraHtml = ''
202
+ . '<div class="price-box">'
203
+ . '<p class="label" id="skybox-configurable-price-from-'
204
+ . $product->getId()
205
+ . $this->getIdSuffix()
206
+ . '">'
207
+ . $template
208
+ . '</p>'
209
+ . '</div>'
210
+ . '<div style="clear:both"></div>';
211
+
212
+ */
213
+ $extraHtml = ''
214
+ . '<div class="price-box">'
215
+ . '<p class="label" id="skybox-configurable-price-from-'
216
+ . $product->getId()
217
+ . $this->getIdSuffix()
218
+ . '">'
219
+ . $template
220
+ . '</p>'
221
+ . '</div>'
222
+ . '<div style="clear:both"></div>';
223
+ //$priceHtml = parent::_toHtml();
224
+ #manually insert extra html needed by the extension into the normal price html
225
+
226
+ //substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
227
+ return $extraHtml;
228
+ }
229
+
230
+
231
+ /**
232
+ * Return the Language Id
233
+ * @return int
234
+ */
235
+ private function getLanguageId()
236
+ {
237
+ $_config = Mage::getModel('skyboxcore/config');
238
+ $cart = $_config->getSession()->getCartSkybox();
239
+ $id = $cart->{'LanguageId'};
240
+ return intval($id);
241
+ }
242
+ }
app/code/community/Skybox/Catalog/Block/Product/Widget/New.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- /**
3
- * Skybox Checkout
4
- *
5
- * @category Skybox
6
- * @package Skybox_Catalog
7
- * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
- */
9
-
10
- /**
11
- * New products widget
12
- *
13
- * @category Skybox
14
- * @package Skybox_Catalog
15
- */
16
- class Skybox_Catalog_Block_Product_Widget_New extends Mage_Catalog_Block_Product_Widget_New
17
- {
18
-
19
- /*
20
- * @var string $_cache_code
21
- */
22
- public $_cache_code = null;
23
-
24
- public function getCacheCode()
25
- {
26
- if ($this->_cache_code == null) {
27
- /* @var $config Skybox_Core_Model_Config */
28
- $config = Mage::getModel("skyboxcore/config");
29
- $skyboxUser = $config->getSession()->getSkyboxUser();
30
- $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
31
- $this->_cache_code = $cache_code;
32
- }
33
- Mage::log("[widget/new] Cache Code: " . $cache_code, null, 'cache.log', true);
34
- return $this->_cache_code;
35
- }
36
-
37
- /**
38
- * Initialize block's cache and template settings
39
- */
40
- protected function _construct()
41
- {
42
- parent::_construct();
43
- $cache_key = Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getCacheCode();
44
- $this->setAttribute("cache_key", $cache_key);
45
- if (Mage::getVersion() == '1.9.1'){
46
- $this->addData(array('cache_lifetime' => null)); // Skip cache generation
47
- }
48
- }
49
}
1
+ <?php
2
+ /**
3
+ * Skybox Checkout
4
+ *
5
+ * @category Skybox
6
+ * @package Skybox_Catalog
7
+ * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
8
+ */
9
+
10
+ /**
11
+ * New products widget
12
+ *
13
+ * @category Skybox
14
+ * @package Skybox_Catalog
15
+ */
16
+ class Skybox_Catalog_Block_Product_Widget_New extends Mage_Catalog_Block_Product_Widget_New
17
+ {
18
+
19
+ /*
20
+ * @var string $_cache_code
21
+ */
22
+ public $_cache_code = null;
23
+
24
+ public function getCacheCode()
25
+ {
26
+ if ($this->_cache_code == null) {
27
+ /* @var $config Skybox_Core_Model_Config */
28
+ $config = Mage::getModel("skyboxcore/config");
29
+ $skyboxUser = $config->getSession()->getSkyboxUser();
30
+ $cache_code = $skyboxUser->CartCountryISOCode . $skyboxUser->CartCityId . $skyboxUser->CartCurrencyISOCode;
31
+ $this->_cache_code = $cache_code;
32
+ }
33
+ Mage::log("[widget/new] Cache Code: " . $cache_code, null, 'cache.log', true);
34
+ return $this->_cache_code;
35
+ }
36
+
37
+ /**
38
+ * Initialize block's cache and template settings
39
+ */
40
+ protected function _construct()
41
+ {
42
+ parent::_construct();
43
+ $cache_key = Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getCacheCode();
44
+ $this->setAttribute("cache_key", $cache_key);
45
+ if (Mage::getVersion() == '1.9.1'){
46
+ $this->addData(array('cache_lifetime' => null)); // Skip cache generation
47
+ }
48
+ }
49
}
app/code/community/Skybox/Catalog/Model/Api/Product.php CHANGED
@@ -1,889 +1,937 @@
1
- <?php
2
-
3
- /**
4
- * Skybox Catalog
5
- *
6
- * @category Skybox
7
- * @package Skybox_Catalog
8
- * @copyright Copyright (c) 2014 Skybox Checkout. (http://www.skyboxcheckout.com)
9
- */
10
- class Skybox_Catalog_Model_Api_Product extends Skybox_Core_Model_Standard
11
- {
12
-
13
- /**
14
- * Model instance
15
- * @var Skybox_Core_Model_Config
16
- */
17
- /*protected $_config = null;
18
-
19
- protected $_typeConfig = "skyboxcore/config";
20
-
21
- protected function getConfig()
22
- {
23
- if(null === $this->_config)
24
- $this->_config = Mage::getModel($this->_typeConfig);
25
- }*/
26
-
27
- /**
28
- * Model instance
29
- * @var Mage_Core_Catalog_Model_Product
30
- */
31
- protected $_product = null;
32
-
33
- protected $_productResult = null;
34
-
35
- protected $_typeProduct = "catalog/product";
36
-
37
- protected $_product_id = null;
38
- protected $_product_data = null;
39
-
40
- public function getProductId()
41
- {
42
- if ($this->_product_id != null) {
43
- return $this->_product_id;
44
- }
45
- return null;
46
- }
47
-
48
- public function getProductData()
49
- {
50
- if ($this->_product_data != null) {
51
- return $this->_product_data;
52
- }
53
- return null;
54
- }
55
-
56
-
57
- /**
58
- * Calculate Price
59
- *
60
- * @param int|Mage_Catalog_Model_Product $product
61
- * @param Varien_Object $request
62
- * @param float $finalPrice
63
- * @param string $type
64
- * @param int $objectId
65
- * @return Mage_Checkout_Model_Cart
66
- */
67
- public function CalculatePrice($product, $request, $finalPrice = null, $type = null, $objectId = 1)
68
- {
69
- Mage::log("ApiProductCatalog ", null, 'orden.log', true);
70
-
71
- //Mage::log(print_r('Product', true), null, 'tracer.log', true);
72
-
73
- //if ($this->getErrorAuthenticate() && !$this->getLocationAllow()) {
74
- if (!$this->getLocationAllow()) {
75
- return $this;
76
- }
77
-
78
- if (!is_object($product)) {
79
- $storeId = Mage::app()->getStore()->getStoreId();
80
- $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product);
81
- }
82
-
83
- $productId = $product->getId();
84
- $_data = null;
85
-
86
- if ($type == null) {
87
- $type = $product->getTypeId();
88
- }
89
-
90
- $defaultSwitch = false;
91
- switch ($type) {
92
- case 'simple':
93
- $finalPrice = isset($finalPrice) ? $finalPrice : $product->getFinalPrice();
94
- $category_id = $product->getSkyboxCategoryId();
95
- $category_id = isset($category_id) ? $product->getSkyboxCategoryId() : 0;
96
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
97
-
98
- $_data = array(
99
- 'object_id' => 1,
100
- 'name' => $product->getName(),
101
- 'sku' => $product->getSku(),
102
- 'category_id' => $category_id,
103
- 'final_price' => $finalPrice,
104
- 'weight' => ($product->getWeight()) ? $product->getWeight() : 1,
105
- 'image_url' => $product->getImageUrl(),
106
- 'typeProduct' => $type,
107
- 'VolWeight' => $volWeight,
108
- 'merchantproductid' => $productId
109
- );
110
- // $this->_calculatePrice($_data);
111
- break;
112
-
113
- case 'configurable':
114
-
115
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
116
- $weight = $product->getTypeInstance(true)->getWeight($product);
117
- $sku = $product->getSku();
118
-
119
- Mage::log("CalculatePrice configurable : " . $finalPrice, null, 'skyboxcheckout.log', false);
120
-
121
- if ($request) {
122
- $childProduct = Mage::getModel('catalog/product_type_configurable')
123
- ->getProductByAttributes($request->getData('super_attribute'), $product);
124
-
125
- $productId = $childProduct->getId();
126
- $sku = $childProduct->getSku();
127
-
128
- }
129
-
130
- $parentItem = null;
131
-
132
- if (isset($request) && !$finalPrice) {
133
- Mage::log("CalculatePrice candidate INI", null, 'skyboxcheckout.log', false);
134
- $_finalPrice = 0;
135
-
136
- $cartCandidates = $product->getTypeInstance(true)
137
- ->prepareForCartAdvanced($request, $product, 'full');
138
-
139
- foreach ($cartCandidates as $candidate) {
140
- // Child items can be sticked together only within their parent
141
- $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
142
- $candidate->setStickWithinParent($stickWithinParent);
143
-
144
- $candidate_getFinalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
145
- Mage::log("CalculatePrice candidate getFinalPrice: " . $candidate_getFinalPrice, null, 'skyboxcheckout.log', false);
146
-
147
- $_finalPrice = $_finalPrice + $candidate_getFinalPrice;
148
- if ($_finalPrice) {
149
- break;
150
- }
151
- }
152
- $finalPrice = $_finalPrice;
153
- Mage::log("CalculatePrice candidate FIN", null, 'skyboxcheckout.log', false);
154
- }
155
-
156
- /* Weight start*/
157
- /*
158
- $options = array();
159
- // Get any super_attribute settings we need
160
- $productAttributesOptions = $product->getTypeInstance(true)->getConfigurableOptions($product);
161
- foreach ($productAttributesOptions as $productAttributeOption) {
162
- $options[$product->getId()] = array();
163
- foreach ($productAttributeOption as $optionValues) {
164
- $val = ($optionValues['option_title']);
165
- $options[$product->getId()][] = array (
166
- $optionValues['sku'] => $optionValues['attribute_code']."=".$val
167
-
168
- ) ;
169
- }
170
-
171
- }
172
- $prod_weight = 1;
173
- if(!empty($optionValues)) {
174
- $a = Mage::getModel('catalog/product')->loadByAttribute('sku',$optionValues['sku']);
175
- //$product->load($product->getIdBySku($optionValues['sku']));
176
- $prod_weight = $a->getWeight();
177
- echo ":::".$prod_weight."::";
178
- }
179
- */
180
- /* Weight end*/
181
-
182
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
183
- $_data = array(
184
- 'object_id' => 1,
185
- 'name' => $product->getName(),
186
- //'sku' => $product->getSku(),
187
- 'sku' => $sku,
188
- 'category_id' => $product->getSkyboxCategoryId(),
189
- 'final_price' => $finalPrice,
190
- 'weight' => $weight ? $weight : 1,
191
- 'image_url' => $product->getImageUrl(),
192
- 'typeProduct' => $type,
193
- 'VolWeight' => $volWeight,
194
- 'merchantproductid' => $productId
195
- );
196
-
197
- // $this->_calculatePrice($_data);
198
- break;
199
-
200
- case 'bundle':
201
- //$_finalPrice = $product->getTotalBundleItemsPrice($product, $request->getQty());
202
- //$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
203
-
204
- //Mage::log(print_r($product, true), null, 'cart.log', true);
205
- //Mage::log("Product: [" . $product->getId() . "] - Class: " . get_class($product), null, 'skyboxcheckout.log', false);
206
-
207
- //Mage::log(print_r($request, true), null, 'cart.log', true);
208
-
209
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
210
- $weight = $product->getTypeInstance(true)->getWeight($product);
211
- $sku = $product->getSku();
212
-
213
- //if (isset($request) && !$finalPrice) {
214
- if (isset($request)) {
215
-
216
- $parentItem = null;
217
- $_finalPrice = null;
218
- $_weight = 0;
219
-
220
- $cartCandidates = $product->getTypeInstance(true)
221
- ->prepareForCartAdvanced($request, $product, 'full');
222
-
223
- foreach ($cartCandidates as $candidate) {
224
- // Child items can be sticked together only within their parent
225
- $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
226
- $candidate->setStickWithinParent($stickWithinParent);
227
-
228
- if (!$_finalPrice) {
229
- $_finalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
230
- //break;
231
- }
232
- //$_weight = $_weight + $candidate->getPriceModel()->getWeight();
233
- $_weight = $_weight + $candidate->getWeight();
234
- }
235
-
236
- $finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
237
- if ($_weight > 0) {
238
- $weight = $_weight;
239
- }
240
- }
241
-
242
- //Mage::log("weight: " . $weight, null, 'cart.log', true);
243
- //Mage::log("sku: " . $sku, null, 'cart.log', true);
244
-
245
- $category_id = $product->getSkyboxCategoryId();
246
- $category_id = isset($category_id) ? $product->getSkyboxCategoryId() : $this->getCommodityFromCategory();
247
-
248
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
249
- $_data = array(
250
- 'object_id' => 1,
251
- 'name' => $product->getName(),
252
- 'sku' => $sku,
253
- 'category_id' => $category_id,
254
- 'final_price' => $finalPrice,
255
- 'weight' => ($weight) ? $weight : 1,
256
- 'image_url' => $product->getImageUrl(),
257
- 'typeProduct' => $type,
258
- 'VolWeight' => $volWeight,
259
- 'merchantproductid' => $productId
260
- );
261
- // $this->_calculatePrice($_data);
262
- break;
263
-
264
- case 'bundle_fixed':
265
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
266
- $skyboxCategoryId = $product->getSkyboxCategoryId();
267
- $weight = $product->getTypeInstance(true)->getWeight($product);
268
- $sku = $product->getSku();
269
-
270
- $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
271
- $product->getTypeInstance(true)->getOptionsIds($product), $product
272
- );
273
-
274
- $_finalPrice = null;
275
- $_weight = 0;
276
- $_skyboxCategoryId = null;
277
-
278
- foreach ($selectionCollection as $option) {
279
- //if ($option->getData('is_default') == 0) continue;
280
-
281
- $product_simple = Mage::getModel('catalog/product')
282
- ->load($option->getId());
283
-
284
- $_finalPrice = $_finalPrice + $product_simple->getFinalPrice();
285
- $_weight = $_weight + $product_simple->getWeight();
286
-
287
- if (!$_skyboxCategoryId) { // Set SkyboxCategory from the first Simple Product
288
- $_skyboxCategoryId = $product_simple->getSkyboxCategoryId();
289
- }
290
- }
291
-
292
- $finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
293
-
294
- if (!$weight) {
295
- $weight = $_weight;
296
- }
297
-
298
- if (!$skyboxCategoryId) {
299
- $skyboxCategoryId = $_skyboxCategoryId;
300
- }
301
-
302
- /*Mage::log("-------------------------", null, 'cart.log', true);
303
- Mage::log("Product: " . $product->getName(), null, 'cart.log', true);
304
- Mage::log("Price: " . $finalPrice, null, 'cart.log', true);
305
- Mage::log("weight: " . $weight, null, 'cart.log', true);
306
- Mage::log("sku: " . $sku, null, 'cart.log', true);*/
307
-
308
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
309
- $_data = array(
310
- 'object_id' => 1,
311
- 'name' => $product->getName(),
312
- 'sku' => $sku,
313
- 'category_id' => $skyboxCategoryId,
314
- 'final_price' => $finalPrice,
315
- 'weight' => ($weight) ? $weight : 1,
316
- 'image_url' => $product->getImageUrl(),
317
- 'typeProduct' => $type,
318
- 'VolWeight' => $volWeight,
319
- 'merchantproductid' => $productId
320
- );
321
-
322
- // $this->_calculatePrice($_data);
323
- break;
324
-
325
- default:
326
- Mage::log("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice", null, 'skyboxcheckout.log', false);
327
- trigger_error("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice");
328
- $defaultSwitch = true;
329
- break;
330
- }
331
-
332
- if (!$defaultSwitch) {
333
- //Mage::log(print_r('EnableTax: ', true), null, 'tracer.log', true);
334
- //Mage::log(print_r($this->getEnabledAddSumTaxToPrice(), true), null, 'tracer.log', true);
335
- if ($this->getEnabledAddSumTaxToPrice()) {
336
- $store = Mage::app()->getStore('default');
337
- $taxCalculation = Mage::getModel('tax/calculation');
338
- $request = $taxCalculation->getRateRequest(null, null, null, $store);
339
- // $product = Mage::registry('current_product');
340
- $taxClassId = $product->getTaxClassId();
341
- $percentTax = $taxCalculation->getRate($request->setProductClassId($taxClassId));
342
-
343
- $taxPrice = $_data['final_price'] * ($percentTax / 100);
344
-
345
- //Mage::log(print_r('Id product: ' . $product->getId(), true), null, 'tracer.log', true);
346
- //Mage::log(print_r('$taxPrice: ' . $taxPrice, true), null, 'tracer.log', true);
347
- //Mage::log(print_r('price: ' . $_data['final_price'], true), null, 'tracer.log', true);
348
- //Mage::log(print_r('$taxPrice+price: ' . ($taxPrice + $_data['final_price']), true), null, 'tracer.log', true);
349
- $comissionSkybox = $_data['final_price'] * (10 / 100);
350
- //Mage::log(print_r('comision skybox: ' . ($comissionSkybox), true), null, 'tracer.log', true);
351
- //Mage::log(print_r('price+comision skybox: ' . ($_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
352
- //Mage::log(print_r('$taxPrice+price+comision: ' . ($taxPrice + $_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
353
- //Mage::log(print_r('comision true: ' . (($taxPrice + $_data['final_price']) * (10 / 100)), true), null, 'tracer.log', true);
354
- $priceReally = ($taxPrice + $_data['final_price']) + ($taxPrice + $_data['final_price']) * (10 / 100);
355
- //Mage::log(print_r('$taxPrice+price+comision true: ' . ($priceReally), true), null, 'tracer.log', true);
356
-
357
-
358
- $_data['final_price'] = $_data['final_price'] + $taxPrice;
359
- }
360
-
361
- //Mage::log(print_r('####################### Data produc params #######################', true), null, 'tracer.log', true);
362
- //Mage::log(print_r($_data, true), null, 'tracer.log', true);
363
- $this->_calculatePrice($_data);
364
- }
365
-
366
- Mage::log("Product Class: " . get_class($product), null, 'skyboxcheckout.log', false);
367
- Mage::log("Product Type: " . $type, null, 'skyboxcheckout.log', false);
368
- Mage::log(print_r($_data, true), null, 'skyboxcheckout.log', false);
369
-
370
- $this->_product_data = $_data;
371
- $this->_product_id = $productId;
372
- return $this;
373
- }
374
-
375
- private function _calculatePrice($data)
376
- {
377
- $msg = sprintf("CalculatePrice: [%s] - [%s] - [%s] - [Category_id: %s] - [Price: %s] - [weight: %s] - [typeProduct: %s]",
378
- $data['object_id'],
379
- $data['sku'],
380
- $data['name'],
381
- $data['category_id'],
382
- $data['final_price'],
383
- $data['weight'],
384
- $data['typeProduct']
385
- );
386
-
387
- Mage::log($msg, null, 'skyboxcheckout.log', false);
388
-
389
- $params = array(
390
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
391
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
392
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi(),
393
- 'htmlobjectid' => $data['object_id'],
394
- 'storeproductcode' => $data['sku'],
395
- 'storeproductname' => $data['name'],
396
- 'storeproductcategory' => $data['category_id'],
397
- 'storeproductprice' => $data['final_price'],
398
- //'storeproductprice' => $product->getFinalPrice(),
399
- 'weight' => ($data['weight']) ? $data['weight'] : 1,
400
- 'weightunit' => $this->getWeightUnit(),
401
- 'storeproductimgurl' => $data['image_url'],
402
- 'merchantproductid' => $data['merchantproductid']
403
- );
404
- $this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_CALCULATE, $params);
405
- }
406
-
407
- public function HtmlTemplateButton()
408
- {
409
- if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow()) {
410
- $params = array(
411
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
412
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
413
- Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi()
414
- );
415
-
416
- $this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_GET_TEMPLATE_BUTTON, $params);
417
- }
418
-
419
- return $this;
420
- }
421
-
422
- public function GetTemplateProduct()
423
- {
424
- Mage::log("ApiProduct ", null, 'orden.log', true);
425
- if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorServiceNotController()) {
426
- //if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorService()) {
427
- $_productResult = $this->getResponse();
428
- $template = $_productResult->TooltipButtonTemplate;
429
- return $template;
430
- // $templateButton = $this->getHtmlTemplateButton();
431
- // if (empty($templateButton))
432
- // $this->HtmlTemplateButton();
433
- //
434
- // /*if($_productResult->{Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_BUTTONERROR})
435
- // {*/
436
- // //Mage::log("_productResult--->" . json_decode($_productResult));
437
- // $templateButton = $this->getHtmlTemplateButton();
438
- // if (!empty($templateButton)) {
439
- // $template = $this->getHtmlTemplateButton();
440
- //// Mage::log(print_r('response template buttom', true), null, 'tracer.log', true);
441
- //// Mage::log(print_r($_productResult, true), null, 'tracer.log', true);
442
- // foreach ($_productResult as $key => $value) {
443
- // $template = str_replace('{' . $key . '}', $value, $template);
444
- // }
445
- //
446
- // // Just for {Block} crap
447
- // $template = str_replace('{Block}', '', $template);
448
- //
449
- // return $template;
450
- // }
451
- //
452
- // $displayUSD = "''"; //CartCountryIso
453
- // /*}else{
454
- // return "Plantilla de error";
455
- // }*/
456
- // //Mage::log(get_class($this) . " GetTemplateProduct() ", null, 'cart.log', true);
457
- } else {
458
- $template = '<div class="skx_content_button"></div>';
459
- return $template;
460
- }
461
- return "";
462
- }
463
-
464
- protected $_isUSD = null;
465
-
466
- public function IsUSD()
467
- {
468
- if (null == $this->_isUSD)
469
- $this->_isUSD = ($this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_CART_CURRENCY_ISO, "") == Skybox_Core_Model_Config::SKYBOX_CURRENCY_USD);
470
- return $this->_isUSD;
471
- }
472
-
473
- public function getCustoms()
474
- {
475
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS, "0");
476
- }
477
-
478
- public function getShipping()
479
- {
480
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING, "0");
481
- }
482
-
483
- public function getInsurance()
484
- {
485
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE, "0");
486
- }
487
-
488
- public function getPrice()
489
- {
490
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_PRICE, "0");
491
- }
492
-
493
- public function getTotalPrice()
494
- {
495
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_TOTAL, "0");
496
- }
497
-
498
- public function getCustomsUSD()
499
- {
500
- return $this->IsUSD() ? $this->getCustoms() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS_USD, "0");
501
- }
502
-
503
- public function getShippingUSD()
504
- {
505
- return $this->IsUSD() ? $this->getShipping() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING_USD, "0");
506
- }
507
-
508
- public function getInsuranceUSD()
509
- {
510
- return $this->IsUSD() ? $this->getInsurance() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE_USD, "0");
511
- }
512
-
513
- public function getPriceUSD()
514
- {
515
- return $this->IsUSD() ? $this->getPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_PRICE_USD, "0");
516
- }
517
-
518
- public function getTotalPriceUSD()
519
- {
520
- return $this->IsUSD() ? $this->getTotalPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_TOTAL_USD, "0");
521
- }
522
-
523
- public function getGuidSkybox()
524
- {
525
- return $this->_getApi()->getGuidApi();
526
- }
527
-
528
- public function getBasePrice()
529
- {
530
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_BASE_PRICE, "0");
531
- }
532
-
533
- public function getBasePriceUSD()
534
- {
535
- return $this->IsUSD() ? $this->getBasePrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_BASE_PRICE_USD, "0");
536
- }
537
-
538
- public function getAdjustPrice()
539
- {
540
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_ADJUST_PRICE, "0");
541
- }
542
-
543
- public function getAdjustPriceUSD()
544
- {
545
- return $this->IsUSD() ? $this->getAdjustPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_ADJUST_PRICE_USD, "0");
546
- }
547
-
548
- public function getAdjustLabel()
549
- {
550
- return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_LABEL_ADJUST, "");
551
- }
552
-
553
- /*Async Ini*/
554
-
555
- public function getUrl($product, $request, $finalPrice = null, $type = null, $objectId = 1)
556
- {
557
- Mage::log("ApiProductCatalog ", null, 'orden.log', true);
558
-
559
- //Mage::log(print_r('Product', true), null, 'tracer.log', true);
560
-
561
- //if ($this->getErrorAuthenticate() && !$this->getLocationAllow()) {
562
- if (!$this->getLocationAllow()) {
563
- return $this;
564
- }
565
-
566
- if (!is_object($product)) {
567
- $storeId = Mage::app()->getStore()->getStoreId();
568
- $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product);
569
- }
570
-
571
- $productId = $product->getId();
572
- $_data = null;
573
-
574
- if ($type == null) {
575
- $type = $product->getTypeId();
576
- }
577
-
578
- $defaultSwitch = true;
579
- switch ($type) {
580
- case 'simple':
581
- $finalPrice = isset($finalPrice) ? $finalPrice : $product->getFinalPrice();
582
- $category_id = $product->getSkyboxCategoryId();
583
- $category_id = isset($category_id) ? $product->getSkyboxCategoryId() : $this->getCommodityFromCategory();
584
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
585
-
586
- $_data = array(
587
- 'object_id' => $product->getId(),
588
- 'name' => $product->getName(),
589
- 'sku' => $product->getSku(),
590
- 'category_id' => $category_id,
591
- 'final_price' => $finalPrice,
592
- 'weight' => ($product->getWeight()) ? $product->getWeight() : 1,
593
- 'image_url' => $product->getImageUrl(),
594
- 'typeProduct' => $type,
595
- 'VolWeight' => $volWeight,
596
- 'merchantproductid' => $productId
597
- );
598
- // $this->_calculatePrice($_data);
599
- break;
600
-
601
- case 'configurable':
602
-
603
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
604
- $weight = $product->getTypeInstance(true)->getWeight($product);
605
- $sku = $product->getSku();
606
-
607
- Mage::log("CalculatePrice configurable : " . $finalPrice, null, 'skyboxcheckout.log', false);
608
-
609
- if ($request) {
610
- $childProduct = Mage::getModel('catalog/product_type_configurable')
611
- ->getProductByAttributes($request->getData('super_attribute'), $product);
612
-
613
- $productId = $childProduct->getId();
614
- $sku = $childProduct->getSku();
615
-
616
- }
617
-
618
- $parentItem = null;
619
-
620
- if (isset($request) && !$finalPrice) {
621
- Mage::log("CalculatePrice candidate INI", null, 'skyboxcheckout.log', false);
622
- $_finalPrice = 0;
623
-
624
- $cartCandidates = $product->getTypeInstance(true)
625
- ->prepareForCartAdvanced($request, $product, 'full');
626
-
627
- foreach ($cartCandidates as $candidate) {
628
- // Child items can be sticked together only within their parent
629
- $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
630
- $candidate->setStickWithinParent($stickWithinParent);
631
-
632
- $candidate_getFinalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
633
- Mage::log("CalculatePrice candidate getFinalPrice: " . $candidate_getFinalPrice, null, 'skyboxcheckout.log', false);
634
-
635
- $_finalPrice = $_finalPrice + $candidate_getFinalPrice;
636
- if ($_finalPrice) {
637
- break;
638
- }
639
- }
640
- $finalPrice = $_finalPrice;
641
- Mage::log("CalculatePrice candidate FIN", null, 'skyboxcheckout.log', false);
642
- }
643
-
644
- $category_id = $product->getSkyboxCategoryId();
645
- $category_id = isset($category_id) ? $product->getSkyboxCategoryId() : $this->getCommodityFromCategory();
646
-
647
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
648
-
649
- $_data = array(
650
- 'object_id' => $product->getId(),
651
- 'name' => $product->getName(),
652
- //'sku' => $product->getSku(),
653
- 'sku' => $sku,
654
- 'category_id' => $category_id,
655
- 'final_price' => $finalPrice,
656
- 'weight' => $weight ? $weight : 1,
657
- 'image_url' => $product->getImageUrl(),
658
- 'typeProduct' => $type,
659
- 'VolWeight' => $volWeight,
660
- 'merchantproductid' => $productId
661
- );
662
-
663
- // $this->_calculatePrice($_data);
664
- break;
665
-
666
- case 'bundle':
667
- //$_finalPrice = $product->getTotalBundleItemsPrice($product, $request->getQty());
668
- //$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
669
-
670
- //Mage::log(print_r($product, true), null, 'cart.log', true);
671
- //Mage::log("Product: [" . $product->getId() . "] - Class: " . get_class($product), null, 'skyboxcheckout.log', false);
672
-
673
- //Mage::log(print_r($request, true), null, 'cart.log', true);
674
-
675
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
676
- $weight = $product->getTypeInstance(true)->getWeight($product);
677
- $sku = $product->getSku();
678
-
679
- //if (isset($request) && !$finalPrice) {
680
- if (isset($request)) {
681
-
682
- $parentItem = null;
683
- $_finalPrice = null;
684
- $_weight = 0;
685
-
686
- $cartCandidates = $product->getTypeInstance(true)
687
- ->prepareForCartAdvanced($request, $product, 'full');
688
-
689
- foreach ($cartCandidates as $candidate) {
690
- // Child items can be sticked together only within their parent
691
- $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
692
- $candidate->setStickWithinParent($stickWithinParent);
693
-
694
- if (!$_finalPrice) {
695
- $_finalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
696
- //break;
697
- }
698
- //$_weight = $_weight + $candidate->getPriceModel()->getWeight();
699
- $_weight = $_weight + $candidate->getWeight();
700
- }
701
-
702
- $finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
703
- if ($_weight > 0) {
704
- $weight = $_weight;
705
- }
706
- }
707
-
708
- //Mage::log("weight: " . $weight, null, 'cart.log', true);
709
- //Mage::log("sku: " . $sku, null, 'cart.log', true);
710
-
711
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
712
- $_data = array(
713
- 'object_id' => $product->getId(),
714
- 'name' => $product->getName(),
715
- 'sku' => $sku,
716
- 'category_id' => $product->getSkyboxCategoryId(),
717
- 'final_price' => $finalPrice,
718
- 'weight' => ($weight) ? $weight : 1,
719
- 'image_url' => $product->getImageUrl(),
720
- 'typeProduct' => $type,
721
- 'VolWeight' => $volWeight,
722
- 'merchantproductid' => $productId
723
- );
724
- // $this->_calculatePrice($_data);
725
- break;
726
-
727
- case 'bundle_fixed':
728
- $finalPrice = isset($finalPrice) ? $finalPrice : null;
729
- $skyboxCategoryId = $product->getSkyboxCategoryId();
730
- $weight = $product->getTypeInstance(true)->getWeight($product);
731
- $sku = $product->getSku();
732
-
733
- $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
734
- $product->getTypeInstance(true)->getOptionsIds($product), $product
735
- );
736
-
737
- $_finalPrice = null;
738
- $_weight = 0;
739
- $_skyboxCategoryId = null;
740
-
741
- foreach ($selectionCollection as $option) {
742
- //if ($option->getData('is_default') == 0) continue;
743
-
744
- $product_simple = Mage::getModel('catalog/product')
745
- ->load($option->getId());
746
-
747
- $_finalPrice = $_finalPrice + $product_simple->getFinalPrice();
748
- $_weight = $_weight + $product_simple->getWeight();
749
-
750
- if (!$_skyboxCategoryId) { // Set SkyboxCategory from the first Simple Product
751
- $_skyboxCategoryId = $product_simple->getSkyboxCategoryId();
752
- }
753
- }
754
-
755
- $finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
756
-
757
- if (!$weight) {
758
- $weight = $_weight;
759
- }
760
-
761
- if (!$skyboxCategoryId) {
762
- $skyboxCategoryId = $_skyboxCategoryId;
763
- }
764
-
765
- /*Mage::log("-------------------------", null, 'cart.log', true);
766
- Mage::log("Product: " . $product->getName(), null, 'cart.log', true);
767
- Mage::log("Price: " . $finalPrice, null, 'cart.log', true);
768
- Mage::log("weight: " . $weight, null, 'cart.log', true);
769
- Mage::log("sku: " . $sku, null, 'cart.log', true);*/
770
-
771
- $volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
772
- $_data = array(
773
- 'object_id' => $product->getId(),
774
- 'name' => $product->getName(),
775
- 'sku' => $sku,
776
- 'category_id' => $skyboxCategoryId,
777
- 'final_price' => $finalPrice,
778
- 'weight' => ($weight) ? $weight : 1,
779
- 'image_url' => $product->getImageUrl(),
780
- 'typeProduct' => $type,
781
- 'VolWeight' => $volWeight,
782
- 'merchantproductid' => $productId
783
- );
784
-
785
- // $this->_calculatePrice($_data);
786
- break;
787
-
788
- default:
789
- Mage::log("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice", null, 'skyboxcheckout.log', false);
790
- trigger_error("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice");
791
- $defaultSwitch = true;
792
- break;
793
- }
794
-
795
- if (!$defaultSwitch) {
796
- //Mage::log(print_r('EnableTax: ', true), null, 'tracer.log', true);
797
- //Mage::log(print_r($this->getEnabledAddSumTaxToPrice(), true), null, 'tracer.log', true);
798
- if ($this->getEnabledAddSumTaxToPrice()) {
799
- $store = Mage::app()->getStore('default');
800
- $taxCalculation = Mage::getModel('tax/calculation');
801
- $request = $taxCalculation->getRateRequest(null, null, null, $store);
802
- // $product = Mage::registry('current_product');
803
- $taxClassId = $product->getTaxClassId();
804
- $percentTax = $taxCalculation->getRate($request->setProductClassId($taxClassId));
805
-
806