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.7 |
Comparing to | |
See all releases |
Code changes from version 1.2.6.3 to 1.2.7
- app/code/community/Skybox/Catalog/Block/Bundle/Price.php +149 -149
- app/code/community/Skybox/Catalog/Block/Catalog/Category/Tab/Skyboxcheckout.php +125 -125
- app/code/community/Skybox/Catalog/Block/Product/List.php +152 -152
- app/code/community/Skybox/Catalog/Block/Product/Price.php +244 -244
- app/code/community/Skybox/Catalog/Block/Product/Widget/New.php +48 -48
- app/code/community/Skybox/Catalog/Model/Api/Product.php +937 -937
- app/code/community/Skybox/Catalog/Model/Observer.php +270 -270
- app/code/community/Skybox/Catalog/Model/Product/Attribute/Source/Categories.php +38 -38
- app/code/community/Skybox/Catalog/Model/Product/Type/Price.php +64 -64
- app/code/community/Skybox/Catalog/Model/Resource/Setup.php +11 -11
- app/code/community/Skybox/Catalog/etc/config.xml +175 -175
- app/code/community/Skybox/Catalog/sql/skyboxcatalog_setup/mysql4-install-0.1.0.php +70 -70
- app/code/community/Skybox/Checkout/Block/Cart/Item/Renderer.php +11 -11
- app/code/community/Skybox/Checkout/Block/Cart/Sidebar.php +32 -32
- app/code/community/Skybox/Checkout/Block/Cart/Totals.php +157 -157
- app/code/community/Skybox/Checkout/Block/Checkout/Cart.php +45 -45
- app/code/community/Skybox/Checkout/Block/Checkout/Cart/Sidebar.php +16 -16
- app/code/community/Skybox/Checkout/Block/Checkout/Links.php +26 -26
- app/code/community/Skybox/Checkout/Block/Checkout/Onepage/Link.php +43 -43
- app/code/community/Skybox/Checkout/Block/Sales/Order/Total.php +71 -71
- app/code/community/Skybox/Checkout/Helper/Data.php +156 -156
- app/code/community/Skybox/Checkout/Helper/Url.php +58 -58
- app/code/community/Skybox/Checkout/Model/Api/Checkout.php +222 -222
- app/code/community/Skybox/Checkout/Model/Carrier.php +36 -36
- app/code/community/Skybox/Checkout/Model/Cart.php +717 -717
- app/code/community/Skybox/Checkout/Model/Creditmemo/Total.php +17 -17
- app/code/community/Skybox/Checkout/Model/Invoice/Total.php +18 -18
- app/code/community/Skybox/Checkout/Model/Observer.php +330 -318
- app/code/community/Skybox/Checkout/Model/Pay.php +11 -11
- app/code/community/Skybox/Checkout/Model/Quote/Address/Total/Rmt.php +112 -112
- app/code/community/Skybox/Checkout/Model/Quote/Address/Total/Tax.php +5 -5
- app/code/community/Skybox/Checkout/Model/Quote/Item.php +36 -36
- app/code/community/Skybox/Checkout/Model/Quote/SubTotal.php +136 -136
- app/code/community/Skybox/Checkout/Model/Quote/Total.php +304 -304
- app/code/community/Skybox/Checkout/Model/Quote/Total2.php +7 -7
- app/code/community/Skybox/Checkout/Model/Quote/Total3.php +6 -6
- app/code/community/Skybox/Checkout/Model/Quote/Total4.php +6 -6
- app/code/community/Skybox/Checkout/Model/Quote/Total5.php +6 -6
- app/code/community/Skybox/Checkout/Model/Quote/Total6.php +6 -6
- app/code/community/Skybox/Checkout/Model/Quote/Total7.php +6 -6
- app/code/community/Skybox/Checkout/Model/Quote/Total8.php +7 -7
- app/code/community/Skybox/Checkout/controllers/CalculateController.php +138 -138
- app/code/community/Skybox/Checkout/controllers/InternationalController.php +89 -89
- app/code/community/Skybox/Checkout/controllers/ProcessController.php +352 -340
- app/code/community/Skybox/Checkout/etc/config.xml +489 -480
- app/code/community/Skybox/Checkout/etc/system.xml +127 -127
- app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-install-0.1.0.php +132 -132
- app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-0.1.0-0.1.1.php +68 -68
- app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-0.1.0-0.1.2.php +16 -16
- app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-1.2.5-1.2.5.2.php +138 -138
- app/code/community/Skybox/Checkout/sql/skyboxcheckout_setup/mysql4-upgrade-1.2.5.2-1.2.6.php +138 -138
- app/code/community/Skybox/Core/Exception.php +19 -19
- app/code/community/Skybox/Core/Helper/Allow.php +236 -236
- app/code/community/Skybox/Core/Helper/Data.php +11 -11
- app/code/community/Skybox/Core/Helper/Email.php +52 -52
- app/code/community/Skybox/Core/Model/Api/Abstract.php +440 -440
- app/code/community/Skybox/Core/Model/Api/Restful.php +365 -364
- app/code/community/Skybox/Core/Model/Config.php +251 -249
- app/code/community/Skybox/Core/Model/Logservice.php +16 -16
- app/code/community/Skybox/Core/Model/Mysql4.php +16 -16
- app/code/community/Skybox/Core/Model/Mysql4/Logservice.php +22 -22
- app/code/community/Skybox/Core/Model/Mysql4/Logservice/Collection.php +17 -17
- app/code/community/Skybox/Core/Model/Session.php +29 -29
- app/code/community/Skybox/Core/Model/Standard.php +292 -292
- app/code/community/Skybox/Core/etc/config.xml +60 -60
- app/code/community/Skybox/Core/sql/skyboxcore_setup/mysql4-install-0.1.0.php +67 -67
- app/code/community/Skybox/International/Helper/Data.php +77 -77
- app/code/community/Skybox/International/Model/Config.php +15 -15
- app/code/community/Skybox/International/Model/StoreType.php +12 -12
- app/code/community/Skybox/International/etc/adminhtml.xml +39 -39
- app/code/community/Skybox/International/etc/config.xml +61 -61
- app/code/community/Skybox/International/etc/system.xml +135 -135
- app/code/community/Skybox/Services/Model/Api.php +309 -309
- app/code/community/Skybox/Services/Model/Api/V2.php +11 -11
- app/code/community/Skybox/Services/etc/api.xml +37 -37
- app/code/community/Skybox/Services/etc/config.xml +26 -26
- app/code/community/Skybox/Services/etc/wsdl.xml +141 -141
- app/code/community/Skybox/Services/etc/wsi.xml +159 -159
- app/design/adminhtml/default/default/layout/skyboxcatalog.xml +7 -7
- app/design/adminhtml/default/default/layout/skyboxinternational.xml +14 -14
- app/design/frontend/base/default/layout/skyboxcheckout.xml +203 -192
- app/design/frontend/base/default/template/skybox/checkout/cart.phtml +177 -177
- app/design/frontend/base/default/template/skybox/checkout/cart/item/default.phtml +294 -294
- app/design/frontend/base/default/template/skybox/checkout/cart/shipping.phtml +10 -160
- app/design/frontend/base/default/template/skybox/checkout/cart/sidebar.phtml +80 -80
- app/design/frontend/base/default/template/skybox/checkout/cart/sidebar/default.phtml +146 -146
- app/design/frontend/base/default/template/skybox/checkout/cart_list.phtml +195 -195
- app/design/frontend/base/default/template/skybox/checkout/multishipping/link.phtml +11 -0
- app/design/frontend/base/default/template/skybox/checkout/onepage.phtml +3 -3
- app/design/frontend/base/default/template/skybox/checkout/onepage/link.phtml +41 -41
- app/design/frontend/base/default/template/skybox/checkout/pagecheckout.phtml +31 -31
- app/design/frontend/base/default/template/skybox/checkout/skyboxcheckout.phtml +357 -357
- app/design/frontend/base/default/template/skybox/checkout/skyboxsuccess.phtml +28 -28
- app/etc/modules/Skybox_All.xml +37 -37
- js/skybox/adminhtml.category.js +10 -10
- js/skybox/jquery.ba-resize.min.js +8 -8
- js/skybox/jquery.fancybox.js +2019 -2019
- js/skybox/jquery.min.js +3 -3
- js/skybox/load-jquery.js +8 -8
- js/skybox/main.js +140 -140
- package.xml +4 -4
- skin/frontend/base/default/css/skybox/jquery.fancybox.css +273 -273
- skin/frontend/base/default/css/skybox/style.css +125 -125
- skin/frontend/base/default/images/skybox/ajax-loading.gif +0 -0
- skin/frontend/base/default/js/skybox/catalog.product.configurable.js +133 -133
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,152 +1,152 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Skybox Checkout
|
4 |
-
*
|
5 |
-
* @category Skybox
|
6 |
-
* @package Skybox_Catalog
|
7 |
-
* @copyright Copyright (c) 2017 Skybox Checkout. (http://www.skyboxcheckout.com)
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Product list
|
12 |
-
*/
|
13 |
-
class Skybox_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List
|
14 |
-
{
|
15 |
-
/**
|
16 |
-
* Retrieve API Product
|
17 |
-
*
|
18 |
-
* @return Skybox_Catalog_Model_Api_Product
|
19 |
-
*/
|
20 |
-
protected function _getApi()
|
21 |
-
{
|
22 |
-
if (null === $this->_api) {
|
23 |
-
$this->_api = Mage::getModel('skyboxcatalog/api_product');
|
24 |
-
}
|
25 |
-
return $this->_api;
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Need use as _prepareLayout - but problem in declaring collection from
|
30 |
-
* another block (was problem with search result)
|
31 |
-
*/
|
32 |
-
protected function _beforeToHtml()
|
33 |
-
{
|
34 |
-
$result = parent::_beforeToHtml();
|
35 |
-
|
36 |
-
if (!$this->isEnable()) {
|
37 |
-
return $result;
|
38 |
-
}
|
39 |
-
|
40 |
-
$api_checkout = Mage::getModel('skyboxcheckout/api_checkout');
|
41 |
-
$api_checkout->InitializeBarSkybox();
|
42 |
-
|
43 |
-
// $session = Mage::getSingleton("core/session", array("name" => "frontend"));
|
44 |
-
// $sky = $session->getData("skyBox");
|
45 |
-
|
46 |
-
$data = $api_checkout->getValueAccessService();
|
47 |
-
|
48 |
-
$skyBoxUrlClient = Mage::helper('skyboxinternational/data')->getSkyBoxUrlAPI();
|
49 |
-
$skyBoxUrlClient = $skyBoxUrlClient . ("multiplecalculate");
|
50 |
-
|
51 |
-
$dataJson = null;
|
52 |
-
$multiCalculate = 1;
|
53 |
-
|
54 |
-
try {
|
55 |
-
// $products = $this->_getProductCollection();
|
56 |
-
$products = $this->getToolbarBlock()->getCollection();
|
57 |
-
|
58 |
-
foreach ($products as $prod) {
|
59 |
-
$product = Mage::getModel('catalog/product')->load($prod->getId());
|
60 |
-
$data['listproducts'][] = $this->getUrlService($product);
|
61 |
-
$dataJson = json_encode($data);
|
62 |
-
}
|
63 |
-
|
64 |
-
$response = $this->multiCalculatePrice($skyBoxUrlClient, $dataJson);
|
65 |
-
// Mage::log(print_r($response, true), null, 'multicalculate.log', true);
|
66 |
-
|
67 |
-
} catch (\Exception $e) {
|
68 |
-
$multiCalculate = 0;
|
69 |
-
// Mage::log(print_r($dataJson, true), null, 'multicalculate.log', true);
|
70 |
-
// Mage::log("[multicalculate] " . $e->getMessage(), null, 'multicalculate.log', true);
|
71 |
-
}
|
72 |
-
|
73 |
-
Mage::unregister('skybox_multicalculate');
|
74 |
-
Mage::register('skybox_multicalculate', $multiCalculate);
|
75 |
-
// Mage::registry('skybox_multicalculate');
|
76 |
-
|
77 |
-
return $result;
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* @param $product
|
82 |
-
* @return array|string
|
83 |
-
*/
|
84 |
-
public function getUrlService($product)
|
85 |
-
{
|
86 |
-
$type = $product->getTypeId();
|
87 |
-
$template = '';
|
88 |
-
|
89 |
-
switch ($type) {
|
90 |
-
case 'simple':
|
91 |
-
$template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(),
|
92 |
-
$product->getTypeId());
|
93 |
-
break;
|
94 |
-
case 'configurable':
|
95 |
-
$template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(),
|
96 |
-
$product->getTypeId());
|
97 |
-
break;
|
98 |
-
case 'bundle':
|
99 |
-
$template = $this->_getApi()->getUrl($product, null, $product->getFinalPrice(), 'simple');
|
100 |
-
break;
|
101 |
-
}
|
102 |
-
return $template;
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Return Multi CalculatePrice
|
107 |
-
*
|
108 |
-
* @param $url
|
109 |
-
* @param $data
|
110 |
-
* @return mixed
|
111 |
-
* @throws Exception
|
112 |
-
*/
|
113 |
-
function multiCalculatePrice($url, $data)
|
114 |
-
{
|
115 |
-
$ch = curl_init();
|
116 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
117 |
-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
118 |
-
curl_setopt($ch, CURLOPT_POST, 1);
|
119 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
120 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
121 |
-
$response = curl_exec($ch);
|
122 |
-
|
123 |
-
$response = json_decode($response, true);
|
124 |
-
|
125 |
-
if ($response['StatusCode'] != 'Success') {
|
126 |
-
throw new \Exception('Missing or invalid data send to MultiCalculate');
|
127 |
-
}
|
128 |
-
return $response;
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* is Enable?
|
133 |
-
*
|
134 |
-
* @return bool
|
135 |
-
*/
|
136 |
-
private function isEnable()
|
137 |
-
{
|
138 |
-
$isModuleEnable = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
|
139 |
-
if (!$isModuleEnable) {
|
140 |
-
return false;
|
141 |
-
}
|
142 |
-
|
143 |
-
/** @var Skybox_Core_Helper_Allow $allowHelper */
|
144 |
-
$allowHelper = Mage::helper('skyboxcore/allow');
|
145 |
-
|
146 |
-
if (!$allowHelper->isPriceEnabled()) {
|
147 |
-
return false;
|
148 |
-
}
|
149 |
-
|
150 |
-
return true;
|
151 |
-
}
|
152 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Skybox Checkout
|
4 |
+
*
|
5 |
+
* @category Skybox
|
6 |
+
* @package Skybox_Catalog
|
7 |
+
* @copyright Copyright (c) 2017 Skybox Checkout. (http://www.skyboxcheckout.com)
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Product list
|
12 |
+
*/
|
13 |
+
class Skybox_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* Retrieve API Product
|
17 |
+
*
|
18 |
+
* @return Skybox_Catalog_Model_Api_Product
|
19 |
+
*/
|
20 |
+
protected function _getApi()
|
21 |
+
{
|
22 |
+
if (null === $this->_api) {
|
23 |
+
$this->_api = Mage::getModel('skyboxcatalog/api_product');
|
24 |
+
}
|
25 |
+
return $this->_api;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Need use as _prepareLayout - but problem in declaring collection from
|
30 |
+
* another block (was problem with search result)
|
31 |
+
*/
|
32 |
+
protected function _beforeToHtml()
|
33 |
+
{
|
34 |
+
$result = parent::_beforeToHtml();
|
35 |
+
|
36 |
+
if (!$this->isEnable()) {
|
37 |
+
return $result;
|
38 |
+
}
|
39 |
+
|
40 |
+
$api_checkout = Mage::getModel('skyboxcheckout/api_checkout');
|
41 |
+
$api_checkout->InitializeBarSkybox();
|
42 |
+
|
43 |
+
// $session = Mage::getSingleton("core/session", array("name" => "frontend"));
|
44 |
+
// $sky = $session->getData("skyBox");
|
45 |
+
|
46 |
+
$data = $api_checkout->getValueAccessService();
|
47 |
+
|
48 |
+
$skyBoxUrlClient = Mage::helper('skyboxinternational/data')->getSkyBoxUrlAPI();
|
49 |
+
$skyBoxUrlClient = $skyBoxUrlClient . ("multiplecalculate");
|
50 |
+
|
51 |
+
$dataJson = null;
|
52 |
+
$multiCalculate = 1;
|
53 |
+
|
54 |
+
try {
|
55 |
+
// $products = $this->_getProductCollection();
|
56 |
+
$products = $this->getToolbarBlock()->getCollection();
|
57 |
+
|
58 |
+
foreach ($products as $prod) {
|
59 |
+
$product = Mage::getModel('catalog/product')->load($prod->getId());
|
60 |
+
$data['listproducts'][] = $this->getUrlService($product);
|
61 |
+
$dataJson = json_encode($data);
|
62 |
+
}
|
63 |
+
|
64 |
+
$response = $this->multiCalculatePrice($skyBoxUrlClient, $dataJson);
|
65 |
+
// Mage::log(print_r($response, true), null, 'multicalculate.log', true);
|
66 |
+
|
67 |
+
} catch (\Exception $e) {
|
68 |
+
$multiCalculate = 0;
|
69 |
+
// Mage::log(print_r($dataJson, true), null, 'multicalculate.log', true);
|
70 |
+
// Mage::log("[multicalculate] " . $e->getMessage(), null, 'multicalculate.log', true);
|
71 |
+
}
|
72 |
+
|
73 |
+
Mage::unregister('skybox_multicalculate');
|
74 |
+
Mage::register('skybox_multicalculate', $multiCalculate);
|
75 |
+
// Mage::registry('skybox_multicalculate');
|
76 |
+
|
77 |
+
return $result;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* @param $product
|
82 |
+
* @return array|string
|
83 |
+
*/
|
84 |
+
public function getUrlService($product)
|
85 |
+
{
|
86 |
+
$type = $product->getTypeId();
|
87 |
+
$template = '';
|
88 |
+
|
89 |
+
switch ($type) {
|
90 |
+
case 'simple':
|
91 |
+
$template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(),
|
92 |
+
$product->getTypeId());
|
93 |
+
break;
|
94 |
+
case 'configurable':
|
95 |
+
$template = $this->_getApi()->getUrl($product->getId(), null, $product->getFinalPrice(),
|
96 |
+
$product->getTypeId());
|
97 |
+
break;
|
98 |
+
case 'bundle':
|
99 |
+
$template = $this->_getApi()->getUrl($product, null, $product->getFinalPrice(), 'simple');
|
100 |
+
break;
|
101 |
+
}
|
102 |
+
return $template;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Return Multi CalculatePrice
|
107 |
+
*
|
108 |
+
* @param $url
|
109 |
+
* @param $data
|
110 |
+
* @return mixed
|
111 |
+
* @throws Exception
|
112 |
+
*/
|
113 |
+
function multiCalculatePrice($url, $data)
|
114 |
+
{
|
115 |
+
$ch = curl_init();
|
116 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
117 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
118 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
119 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
120 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
121 |
+
$response = curl_exec($ch);
|
122 |
+
|
123 |
+
$response = json_decode($response, true);
|
124 |
+
|
125 |
+
if ($response['StatusCode'] != 'Success') {
|
126 |
+
throw new \Exception('Missing or invalid data send to MultiCalculate');
|
127 |
+
}
|
128 |
+
return $response;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* is Enable?
|
133 |
+
*
|
134 |
+
* @return bool
|
135 |
+
*/
|
136 |
+
private function isEnable()
|
137 |
+
{
|
138 |
+
$isModuleEnable = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
|
139 |
+
if (!$isModuleEnable) {
|
140 |
+
return false;
|
141 |
+
}
|
142 |
+
|
143 |
+
/** @var Skybox_Core_Helper_Allow $allowHelper */
|
144 |
+
$allowHelper = Mage::helper('skyboxcore/allow');
|
145 |
+
|
146 |
+
if (!$allowHelper->isPriceEnabled()) {
|
147 |
+
return false;
|
148 |
+
}
|
149 |
+
|
150 |
+
return true;
|
151 |
+
}
|
152 |
+
}
|
app/code/community/Skybox/Catalog/Block/Product/Price.php
CHANGED
@@ -1,244 +1,244 @@
|
|
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 |
-
$isModuleEnable = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
|
78 |
-
|
79 |
-
if (!$isModuleEnable) {
|
80 |
-
return parent::_toHtml();
|
81 |
-
}
|
82 |
-
|
83 |
-
/** @var Skybox_Core_Helper_Allow $allowHelper */
|
84 |
-
$allowHelper = Mage::helper('skyboxcore/allow');
|
85 |
-
|
86 |
-
if ($allowHelper->isPriceEnabled()) {
|
87 |
-
|
88 |
-
if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
|
89 |
-
return '';
|
90 |
-
} elseif ($this->_getApi()->HasError()) {
|
91 |
-
//$error_code = $this->_getApi()->getStatusCode();
|
92 |
-
$message = $this->_getApi()->getStatusMessage();
|
93 |
-
|
94 |
-
if ($this->_getApi()->_getApi()->ErrorRatesNotFound()) {
|
95 |
-
$message = $this->_getApi()->_getApi()->getErrorRatesNotFoundMessage($this->getLanguageId());
|
96 |
-
return '<div style="color:#FF0000;">' . $message . '</div>';
|
97 |
-
}
|
98 |
-
|
99 |
-
// return '<div style="color:#FF0000;">' . $message . '</div>';
|
100 |
-
return '';
|
101 |
-
}
|
102 |
-
|
103 |
-
/* @var Mage_Catalog_Model_Product $product */
|
104 |
-
$product = $this->getProduct();
|
105 |
-
$type = $product->getTypeId();
|
106 |
-
$route_name = Mage::app()->getRequest()->getRouteName();
|
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 |
-
if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/view/price_clone.phtml') {
|
114 |
-
return '';
|
115 |
-
}
|
116 |
-
|
117 |
-
// Configurable Product
|
118 |
-
if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/price.phtml') {
|
119 |
-
|
120 |
-
if (Mage::registry('current_product')) {
|
121 |
-
return "";
|
122 |
-
}
|
123 |
-
|
124 |
-
return $this->calculatePrice($product);
|
125 |
-
}
|
126 |
-
|
127 |
-
if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/view/tierprices.phtml') {
|
128 |
-
if ($route_name == 'catalog') {
|
129 |
-
return $this->calculatePrice($product);
|
130 |
-
}
|
131 |
-
return '';
|
132 |
-
}
|
133 |
-
|
134 |
-
}
|
135 |
-
|
136 |
-
return parent::_toHtml();
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Calculate Price HTML output
|
141 |
-
*
|
142 |
-
* @param Mage_Catalog_Model_Product $product
|
143 |
-
* @return string
|
144 |
-
*/
|
145 |
-
protected function calculatePrice($product)
|
146 |
-
{
|
147 |
-
//Mage::log('Entro calcular producto', null, 'tracer.log', true);
|
148 |
-
$stockItem = $product->getStockItem();
|
149 |
-
// if (!$stockItem->getIsInStock()) {
|
150 |
-
// Mage::log('sin stock', null, 'tracer.log', true);
|
151 |
-
// return ''; // Out of Stock
|
152 |
-
// }
|
153 |
-
|
154 |
-
$type = $product->getTypeId();
|
155 |
-
//Mage::log(print_r('product\Price: '.$type, true), null, 'tracer.log', true);
|
156 |
-
|
157 |
-
$multiCalculate = Mage::registry('skybox_multicalculate');
|
158 |
-
|
159 |
-
// if ($multiCalculate and Mage::registry('current_category') and (!(Mage::registry('current_product')))) {
|
160 |
-
|
161 |
-
if ($multiCalculate && Mage::registry('current_category')) {
|
162 |
-
/**
|
163 |
-
* Apply multiple calculate start
|
164 |
-
* When: is different to product detail and you are on catalog category
|
165 |
-
*/
|
166 |
-
$template = '<div class="skybox-price-set" product-id="' . $product->getId() . '" id="product-' . $product->getId() . '"></div>';
|
167 |
-
/*
|
168 |
-
if($product->getTypeId() == "simple"){
|
169 |
-
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
170 |
-
if(!$parentIds)
|
171 |
-
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
172 |
-
if(isset($parentIds[0])){
|
173 |
-
$parent = Mage::getModel('catalog/product')->load($parentIds[0]);
|
174 |
-
// do stuff here
|
175 |
-
}
|
176 |
-
}*/
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Apply multiple calculate end
|
180 |
-
*/
|
181 |
-
} else {
|
182 |
-
switch ($type) {
|
183 |
-
case 'simple':
|
184 |
-
$template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
|
185 |
-
$product->getTypeId())
|
186 |
-
->GetTemplateProduct();
|
187 |
-
break;
|
188 |
-
case 'configurable':
|
189 |
-
$template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
|
190 |
-
$product->getTypeId())
|
191 |
-
->GetTemplateProduct();
|
192 |
-
break;
|
193 |
-
case 'bundle':
|
194 |
-
$template = $this->_getApi()->CalculatePrice($product, null, $product->getFinalPrice(), 'simple')
|
195 |
-
->GetTemplateProduct();
|
196 |
-
break;
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
// Mage::log(print_r('##Product template##', true), null, 'tracer.log', true);
|
201 |
-
// Mage::log(print_r($template, true), null, 'tracer.log', true);
|
202 |
-
/*
|
203 |
-
$extraHtml = ''
|
204 |
-
. '<div class="price-box">'
|
205 |
-
. '<p class="label" id="skybox-configurable-price-from-'
|
206 |
-
. $product->getId()
|
207 |
-
. $this->getIdSuffix()
|
208 |
-
. '">'
|
209 |
-
. $template
|
210 |
-
. '</p>'
|
211 |
-
. '</div>'
|
212 |
-
. '<div style="clear:both"></div>';
|
213 |
-
|
214 |
-
*/
|
215 |
-
$extraHtml = ''
|
216 |
-
. '<div class="price-box">'
|
217 |
-
. '<p class="label" id="skybox-configurable-price-from-'
|
218 |
-
. $product->getId()
|
219 |
-
. $this->getIdSuffix()
|
220 |
-
. '">'
|
221 |
-
. $template
|
222 |
-
. '</p>'
|
223 |
-
. '</div>'
|
224 |
-
. '<div style="clear:both"></div>';
|
225 |
-
//$priceHtml = parent::_toHtml();
|
226 |
-
#manually insert extra html needed by the extension into the normal price html
|
227 |
-
|
228 |
-
//substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
|
229 |
-
return $extraHtml;
|
230 |
-
}
|
231 |
-
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Return the Language Id
|
235 |
-
* @return int
|
236 |
-
*/
|
237 |
-
private function getLanguageId()
|
238 |
-
{
|
239 |
-
$_config = Mage::getModel('skyboxcore/config');
|
240 |
-
$cart = $_config->getSession()->getCartSkybox();
|
241 |
-
$id = $cart->{'LanguageId'};
|
242 |
-
return intval($id);
|
243 |
-
}
|
244 |
-
}
|
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 |
+
$isModuleEnable = Mage::getModel('skyboxcore/api_restful')->isModuleEnable();
|
78 |
+
|
79 |
+
if (!$isModuleEnable) {
|
80 |
+
return parent::_toHtml();
|
81 |
+
}
|
82 |
+
|
83 |
+
/** @var Skybox_Core_Helper_Allow $allowHelper */
|
84 |
+
$allowHelper = Mage::helper('skyboxcore/allow');
|
85 |
+
|
86 |
+
if ($allowHelper->isPriceEnabled()) {
|
87 |
+
|
88 |
+
if ($this->_getApi()->getErrorAuthenticate() && !$this->_getApi()->getLocationAllow() && $this->_getApi()->HasError()) {
|
89 |
+
return '';
|
90 |
+
} elseif ($this->_getApi()->HasError()) {
|
91 |
+
//$error_code = $this->_getApi()->getStatusCode();
|
92 |
+
$message = $this->_getApi()->getStatusMessage();
|
93 |
+
|
94 |
+
if ($this->_getApi()->_getApi()->ErrorRatesNotFound()) {
|
95 |
+
$message = $this->_getApi()->_getApi()->getErrorRatesNotFoundMessage($this->getLanguageId());
|
96 |
+
return '<div style="color:#FF0000;">' . $message . '</div>';
|
97 |
+
}
|
98 |
+
|
99 |
+
// return '<div style="color:#FF0000;">' . $message . '</div>';
|
100 |
+
return '';
|
101 |
+
}
|
102 |
+
|
103 |
+
/* @var Mage_Catalog_Model_Product $product */
|
104 |
+
$product = $this->getProduct();
|
105 |
+
$type = $product->getTypeId();
|
106 |
+
$route_name = Mage::app()->getRequest()->getRouteName();
|
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 |
+
if ($type == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE && $this->getTemplate() == 'catalog/product/view/price_clone.phtml') {
|
114 |
+
return '';
|
115 |
+
}
|
116 |
+
|
117 |
+
// Configurable Product
|
118 |
+
if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/price.phtml') {
|
119 |
+
|
120 |
+
if (Mage::registry('current_product')) {
|
121 |
+
return "";
|
122 |
+
}
|
123 |
+
|
124 |
+
return $this->calculatePrice($product);
|
125 |
+
}
|
126 |
+
|
127 |
+
if ($type == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->getTemplate() == 'catalog/product/view/tierprices.phtml') {
|
128 |
+
if ($route_name == 'catalog') {
|
129 |
+
return $this->calculatePrice($product);
|
130 |
+
}
|
131 |
+
return '';
|
132 |
+
}
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
return parent::_toHtml();
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Calculate Price HTML output
|
141 |
+
*
|
142 |
+
* @param Mage_Catalog_Model_Product $product
|
143 |
+
* @return string
|
144 |
+
*/
|
145 |
+
protected function calculatePrice($product)
|
146 |
+
{
|
147 |
+
//Mage::log('Entro calcular producto', null, 'tracer.log', true);
|
148 |
+
$stockItem = $product->getStockItem();
|
149 |
+
// if (!$stockItem->getIsInStock()) {
|
150 |
+
// Mage::log('sin stock', null, 'tracer.log', true);
|
151 |
+
// return ''; // Out of Stock
|
152 |
+
// }
|
153 |
+
|
154 |
+
$type = $product->getTypeId();
|
155 |
+
//Mage::log(print_r('product\Price: '.$type, true), null, 'tracer.log', true);
|
156 |
+
|
157 |
+
$multiCalculate = Mage::registry('skybox_multicalculate');
|
158 |
+
|
159 |
+
// if ($multiCalculate and Mage::registry('current_category') and (!(Mage::registry('current_product')))) {
|
160 |
+
|
161 |
+
if ($multiCalculate && Mage::registry('current_category')) {
|
162 |
+
/**
|
163 |
+
* Apply multiple calculate start
|
164 |
+
* When: is different to product detail and you are on catalog category
|
165 |
+
*/
|
166 |
+
$template = '<div class="skybox-price-set" product-id="' . $product->getId() . '" id="product-' . $product->getId() . '"></div>';
|
167 |
+
/*
|
168 |
+
if($product->getTypeId() == "simple"){
|
169 |
+
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
170 |
+
if(!$parentIds)
|
171 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
172 |
+
if(isset($parentIds[0])){
|
173 |
+
$parent = Mage::getModel('catalog/product')->load($parentIds[0]);
|
174 |
+
// do stuff here
|
175 |
+
}
|
176 |
+
}*/
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Apply multiple calculate end
|
180 |
+
*/
|
181 |
+
} else {
|
182 |
+
switch ($type) {
|
183 |
+
case 'simple':
|
184 |
+
$template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
|
185 |
+
$product->getTypeId())
|
186 |
+
->GetTemplateProduct();
|
187 |
+
break;
|
188 |
+
case 'configurable':
|
189 |
+
$template = $this->_getApi()->CalculatePrice($product->getId(), null, $product->getFinalPrice(),
|
190 |
+
$product->getTypeId())
|
191 |
+
->GetTemplateProduct();
|
192 |
+
break;
|
193 |
+
case 'bundle':
|
194 |
+
$template = $this->_getApi()->CalculatePrice($product, null, $product->getFinalPrice(), 'simple')
|
195 |
+
->GetTemplateProduct();
|
196 |
+
break;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
// Mage::log(print_r('##Product template##', true), null, 'tracer.log', true);
|
201 |
+
// Mage::log(print_r($template, true), null, 'tracer.log', true);
|
202 |
+
/*
|
203 |
+
$extraHtml = ''
|
204 |
+
. '<div class="price-box">'
|
205 |
+
. '<p class="label" id="skybox-configurable-price-from-'
|
206 |
+
. $product->getId()
|
207 |
+
. $this->getIdSuffix()
|
208 |
+
. '">'
|
209 |
+
. $template
|
210 |
+
. '</p>'
|
211 |
+
. '</div>'
|
212 |
+
. '<div style="clear:both"></div>';
|
213 |
+
|
214 |
+
*/
|
215 |
+
$extraHtml = ''
|
216 |
+
. '<div class="price-box">'
|
217 |
+
. '<p class="label" id="skybox-configurable-price-from-'
|
218 |
+
. $product->getId()
|
219 |
+
. $this->getIdSuffix()
|
220 |
+
. '">'
|
221 |
+
. $template
|
222 |
+
. '</p>'
|
223 |
+
. '</div>'
|
224 |
+
. '<div style="clear:both"></div>';
|
225 |
+
//$priceHtml = parent::_toHtml();
|
226 |
+
#manually insert extra html needed by the extension into the normal price html
|
227 |
+
|
228 |
+
//substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
|
229 |
+
return $extraHtml;
|
230 |
+
}
|
231 |
+
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Return the Language Id
|
235 |
+
* @return int
|
236 |
+
*/
|
237 |
+
private function getLanguageId()
|
238 |
+
{
|
239 |
+
$_config = Mage::getModel('skyboxcore/config');
|
240 |
+
$cart = $_config->getSession()->getCartSkybox();
|
241 |
+
$id = $cart->{'LanguageId'};
|
242 |
+
return intval($id);
|
243 |
+
}
|
244 |
+
}
|
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,937 +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) ? $category_id : $this->getCommodityFromCategory($product);
|
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(),
|
145 |
-
$product);
|
146 |
-
Mage::log("CalculatePrice candidate getFinalPrice: " . $candidate_getFinalPrice, null,
|
147 |
-
'skyboxcheckout.log', false);
|
148 |
-
|
149 |
-
$_finalPrice = $_finalPrice + $candidate_getFinalPrice;
|
150 |
-
if ($_finalPrice) {
|
151 |
-
break;
|
152 |
-
}
|
153 |
-
}
|
154 |
-
$finalPrice = $_finalPrice;
|
155 |
-
Mage::log("CalculatePrice candidate FIN", null, 'skyboxcheckout.log', false);
|
156 |
-
}
|
157 |
-
|
158 |
-
/* Weight start*/
|
159 |
-
/*
|
160 |
-
$options = array();
|
161 |
-
// Get any super_attribute settings we need
|
162 |
-
$productAttributesOptions = $product->getTypeInstance(true)->getConfigurableOptions($product);
|
163 |
-
foreach ($productAttributesOptions as $productAttributeOption) {
|
164 |
-
$options[$product->getId()] = array();
|
165 |
-
foreach ($productAttributeOption as $optionValues) {
|
166 |
-
$val = ($optionValues['option_title']);
|
167 |
-
$options[$product->getId()][] = array (
|
168 |
-
$optionValues['sku'] => $optionValues['attribute_code']."=".$val
|
169 |
-
|
170 |
-
) ;
|
171 |
-
}
|
172 |
-
|
173 |
-
}
|
174 |
-
$prod_weight = 1;
|
175 |
-
if(!empty($optionValues)) {
|
176 |
-
$a = Mage::getModel('catalog/product')->loadByAttribute('sku',$optionValues['sku']);
|
177 |
-
//$product->load($product->getIdBySku($optionValues['sku']));
|
178 |
-
$prod_weight = $a->getWeight();
|
179 |
-
echo ":::".$prod_weight."::";
|
180 |
-
}
|
181 |
-
*/
|
182 |
-
/* Weight end*/
|
183 |
-
|
184 |
-
$category_id = $product->getSkyboxCategoryId();
|
185 |
-
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
186 |
-
|
187 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
188 |
-
$_data = array(
|
189 |
-
'object_id' => 1,
|
190 |
-
'name' => $product->getName(),
|
191 |
-
//'sku' => $product->getSku(),
|
192 |
-
'sku' => $sku,
|
193 |
-
'category_id' => $category_id,
|
194 |
-
'final_price' => $finalPrice,
|
195 |
-
'weight' => $weight ? $weight : 1,
|
196 |
-
'image_url' => $product->getImageUrl(),
|
197 |
-
'typeProduct' => $type,
|
198 |
-
'VolWeight' => $volWeight,
|
199 |
-
'merchantproductid' => $productId
|
200 |
-
);
|
201 |
-
|
202 |
-
// $this->_calculatePrice($_data);
|
203 |
-
break;
|
204 |
-
|
205 |
-
case 'bundle':
|
206 |
-
//$_finalPrice = $product->getTotalBundleItemsPrice($product, $request->getQty());
|
207 |
-
//$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
208 |
-
|
209 |
-
//Mage::log(print_r($product, true), null, 'cart.log', true);
|
210 |
-
//Mage::log("Product: [" . $product->getId() . "] - Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
211 |
-
|
212 |
-
//Mage::log(print_r($request, true), null, 'cart.log', true);
|
213 |
-
|
214 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
215 |
-
$weight = $product->getTypeInstance(true)->getWeight($product);
|
216 |
-
$sku = $product->getSku();
|
217 |
-
|
218 |
-
//if (isset($request) && !$finalPrice) {
|
219 |
-
if (isset($request)) {
|
220 |
-
|
221 |
-
$parentItem = null;
|
222 |
-
$_finalPrice = null;
|
223 |
-
$_weight = 0;
|
224 |
-
|
225 |
-
$cartCandidates = $product->getTypeInstance(true)
|
226 |
-
->prepareForCartAdvanced($request, $product, 'full');
|
227 |
-
|
228 |
-
foreach ($cartCandidates as $candidate) {
|
229 |
-
// Child items can be sticked together only within their parent
|
230 |
-
$stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
|
231 |
-
$candidate->setStickWithinParent($stickWithinParent);
|
232 |
-
|
233 |
-
if (!$_finalPrice) {
|
234 |
-
$_finalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
|
235 |
-
//break;
|
236 |
-
}
|
237 |
-
//$_weight = $_weight + $candidate->getPriceModel()->getWeight();
|
238 |
-
$_weight = $_weight + $candidate->getWeight();
|
239 |
-
}
|
240 |
-
|
241 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
242 |
-
if ($_weight > 0) {
|
243 |
-
$weight = $_weight;
|
244 |
-
}
|
245 |
-
}
|
246 |
-
|
247 |
-
//Mage::log("weight: " . $weight, null, 'cart.log', true);
|
248 |
-
//Mage::log("sku: " . $sku, null, 'cart.log', true);
|
249 |
-
|
250 |
-
$category_id = $product->getSkyboxCategoryId();
|
251 |
-
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
252 |
-
|
253 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
254 |
-
$_data = array(
|
255 |
-
'object_id' => 1,
|
256 |
-
'name' => $product->getName(),
|
257 |
-
'sku' => $sku,
|
258 |
-
'category_id' => $category_id,
|
259 |
-
'final_price' => $finalPrice,
|
260 |
-
'weight' => ($weight) ? $weight : 1,
|
261 |
-
'image_url' => $product->getImageUrl(),
|
262 |
-
'typeProduct' => $type,
|
263 |
-
'VolWeight' => $volWeight,
|
264 |
-
'merchantproductid' => $productId
|
265 |
-
);
|
266 |
-
// $this->_calculatePrice($_data);
|
267 |
-
break;
|
268 |
-
|
269 |
-
case 'bundle_fixed':
|
270 |
-
|
271 |
-
// @Note: It should be rewrite!!
|
272 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
273 |
-
$skyboxCategoryId = $product->getSkyboxCategoryId();
|
274 |
-
$weight = $product->getTypeInstance(true)->getWeight($product);
|
275 |
-
$sku = $product->getSku();
|
276 |
-
|
277 |
-
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
|
278 |
-
$product->getTypeInstance(true)->getOptionsIds($product), $product
|
279 |
-
);
|
280 |
-
|
281 |
-
$_finalPrice = null;
|
282 |
-
$_weight = 0;
|
283 |
-
$_skyboxCategoryId = null;
|
284 |
-
|
285 |
-
foreach ($selectionCollection as $option) {
|
286 |
-
//if ($option->getData('is_default') == 0) continue;
|
287 |
-
|
288 |
-
$product_simple = Mage::getModel('catalog/product')
|
289 |
-
->load($option->getId());
|
290 |
-
|
291 |
-
$_finalPrice = $_finalPrice + $product_simple->getFinalPrice();
|
292 |
-
$_weight = $_weight + $product_simple->getWeight();
|
293 |
-
|
294 |
-
if (!$_skyboxCategoryId) { // Set SkyboxCategory from the first Simple Product
|
295 |
-
// $_skyboxCategoryId = $product_simple->getSkyboxCategoryId();
|
296 |
-
$_skyboxCategoryId = $product->getSkyboxCategoryId();
|
297 |
-
$_skyboxCategoryId = isset($_skyboxCategoryId) ? $_skyboxCategoryId : $this->getCommodityFromCategory($product);
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
302 |
-
|
303 |
-
if (!$weight) {
|
304 |
-
$weight = $_weight;
|
305 |
-
}
|
306 |
-
|
307 |
-
if (!$skyboxCategoryId) {
|
308 |
-
$skyboxCategoryId = $_skyboxCategoryId;
|
309 |
-
}
|
310 |
-
|
311 |
-
/*Mage::log("-------------------------", null, 'cart.log', true);
|
312 |
-
Mage::log("Product: " . $product->getName(), null, 'cart.log', true);
|
313 |
-
Mage::log("Price: " . $finalPrice, null, 'cart.log', true);
|
314 |
-
Mage::log("weight: " . $weight, null, 'cart.log', true);
|
315 |
-
Mage::log("sku: " . $sku, null, 'cart.log', true);*/
|
316 |
-
|
317 |
-
|
318 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
319 |
-
$_data = array(
|
320 |
-
'object_id' => 1,
|
321 |
-
'name' => $product->getName(),
|
322 |
-
'sku' => $sku,
|
323 |
-
'category_id' => $skyboxCategoryId,
|
324 |
-
'final_price' => $finalPrice,
|
325 |
-
'weight' => ($weight) ? $weight : 1,
|
326 |
-
'image_url' => $product->getImageUrl(),
|
327 |
-
'typeProduct' => $type,
|
328 |
-
'VolWeight' => $volWeight,
|
329 |
-
'merchantproductid' => $productId
|
330 |
-
);
|
331 |
-
|
332 |
-
// $this->_calculatePrice($_data);
|
333 |
-
break;
|
334 |
-
|
335 |
-
default:
|
336 |
-
Mage::log("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice",
|
337 |
-
null, 'skyboxcheckout.log', false);
|
338 |
-
trigger_error("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice");
|
339 |
-
$defaultSwitch = true;
|
340 |
-
break;
|
341 |
-
}
|
342 |
-
|
343 |
-
if (!$defaultSwitch) {
|
344 |
-
//Mage::log(print_r('EnableTax: ', true), null, 'tracer.log', true);
|
345 |
-
//Mage::log(print_r($this->getEnabledAddSumTaxToPrice(), true), null, 'tracer.log', true);
|
346 |
-
if ($this->getEnabledAddSumTaxToPrice()) {
|
347 |
-
$store = Mage::app()->getStore('default');
|
348 |
-
$taxCalculation = Mage::getModel('tax/calculation');
|
349 |
-
$request = $taxCalculation->getRateRequest(null, null, null, $store);
|
350 |
-
// $product = Mage::registry('current_product');
|
351 |
-
$taxClassId = $product->getTaxClassId();
|
352 |
-
$percentTax = $taxCalculation->getRate($request->setProductClassId($taxClassId));
|
353 |
-
|
354 |
-
$taxPrice = $_data['final_price'] * ($percentTax / 100);
|
355 |
-
|
356 |
-
//Mage::log(print_r('Id product: ' . $product->getId(), true), null, 'tracer.log', true);
|
357 |
-
//Mage::log(print_r('$taxPrice: ' . $taxPrice, true), null, 'tracer.log', true);
|
358 |
-
//Mage::log(print_r('price: ' . $_data['final_price'], true), null, 'tracer.log', true);
|
359 |
-
//Mage::log(print_r('$taxPrice+price: ' . ($taxPrice + $_data['final_price']), true), null, 'tracer.log', true);
|
360 |
-
$comissionSkybox = $_data['final_price'] * (10 / 100);
|
361 |
-
//Mage::log(print_r('comision skybox: ' . ($comissionSkybox), true), null, 'tracer.log', true);
|
362 |
-
//Mage::log(print_r('price+comision skybox: ' . ($_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
363 |
-
//Mage::log(print_r('$taxPrice+price+comision: ' . ($taxPrice + $_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
364 |
-
//Mage::log(print_r('comision true: ' . (($taxPrice + $_data['final_price']) * (10 / 100)), true), null, 'tracer.log', true);
|
365 |
-
$priceReally = ($taxPrice + $_data['final_price']) + ($taxPrice + $_data['final_price']) * (10 / 100);
|
366 |
-
//Mage::log(print_r('$taxPrice+price+comision true: ' . ($priceReally), true), null, 'tracer.log', true);
|
367 |
-
|
368 |
-
|
369 |
-
$_data['final_price'] = $_data['final_price'] + $taxPrice;
|
370 |
-
}
|
371 |
-
|
372 |
-
//Mage::log(print_r('####################### Data produc params #######################', true), null, 'tracer.log', true);
|
373 |
-
//Mage::log(print_r($_data, true), null, 'tracer.log', true);
|
374 |
-
// $this->_calculatePrice($_data);
|
375 |
-
try {
|
376 |
-
$this->_calculatePrice($_data);
|
377 |
-
} catch (\Exception $e) {
|
378 |
-
Mage::log($e->getMessage(), null, 'skyboxcheckout.log', false);
|
379 |
-
}
|
380 |
-
}
|
381 |
-
|
382 |
-
Mage::log("Product Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
383 |
-
Mage::log("Product Type: " . $type, null, 'skyboxcheckout.log', false);
|
384 |
-
Mage::log(print_r($_data, true), null, 'skyboxcheckout.log', false);
|
385 |
-
|
386 |
-
$this->_product_data = $_data;
|
387 |
-
$this->_product_id = $productId;
|
388 |
-
return $this;
|
389 |
-
}
|
390 |
-
|
391 |
-
private function _calculatePrice($data)
|
392 |
-
{
|
393 |
-
$msg = sprintf("CalculatePrice: [%s] - [%s] - [%s] - [Category_id: %s] - [Price: %s] - [weight: %s] - [typeProduct: %s]",
|
394 |
-
$data['object_id'],
|
395 |
-
$data['sku'],
|
396 |
-
$data['name'],
|
397 |
-
$data['category_id'],
|
398 |
-
$data['final_price'],
|
399 |
-
$data['weight'],
|
400 |
-
$data['typeProduct']
|
401 |
-
);
|
402 |
-
|
403 |
-
Mage::log($msg, null, 'skyboxcheckout.log', false);
|
404 |
-
|
405 |
-
$params = array(
|
406 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
|
407 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
|
408 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi(),
|
409 |
-
'htmlobjectid' => $data['object_id'],
|
410 |
-
'storeproductcode' => $data['sku'],
|
411 |
-
'storeproductname' => $data['name'],
|
412 |
-
'storeproductcategory' => $data['category_id'],
|
413 |
-
'storeproductprice' => $data['final_price'],
|
414 |
-
//'storeproductprice' => $product->getFinalPrice(),
|
415 |
-
'weight' => ($data['weight']) ? $data['weight'] : 1,
|
416 |
-
'weightunit' => $this->getWeightUnit(),
|
417 |
-
'storeproductimgurl' => $data['image_url'],
|
418 |
-
'merchantproductid' => $data['merchantproductid']
|
419 |
-
);
|
420 |
-
$this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_CALCULATE, $params);
|
421 |
-
}
|
422 |
-
|
423 |
-
public function HtmlTemplateButton()
|
424 |
-
{
|
425 |
-
if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow()) {
|
426 |
-
$params = array(
|
427 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
|
428 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
|
429 |
-
Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi()
|
430 |
-
);
|
431 |
-
|
432 |
-
$this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_GET_TEMPLATE_BUTTON, $params);
|
433 |
-
}
|
434 |
-
|
435 |
-
return $this;
|
436 |
-
}
|
437 |
-
|
438 |
-
public function GetTemplateProduct()
|
439 |
-
{
|
440 |
-
Mage::log("ApiProduct ", null, 'orden.log', true);
|
441 |
-
if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorServiceNotController()) {
|
442 |
-
//if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorService()) {
|
443 |
-
$_productResult = $this->getResponse();
|
444 |
-
$template = $_productResult->TooltipButtonTemplate;
|
445 |
-
return $template;
|
446 |
-
// $templateButton = $this->getHtmlTemplateButton();
|
447 |
-
// if (empty($templateButton))
|
448 |
-
// $this->HtmlTemplateButton();
|
449 |
-
//
|
450 |
-
// /*if($_productResult->{Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_BUTTONERROR})
|
451 |
-
// {*/
|
452 |
-
// //Mage::log("_productResult--->" . json_decode($_productResult));
|
453 |
-
// $templateButton = $this->getHtmlTemplateButton();
|
454 |
-
// if (!empty($templateButton)) {
|
455 |
-
// $template = $this->getHtmlTemplateButton();
|
456 |
-
//// Mage::log(print_r('response template buttom', true), null, 'tracer.log', true);
|
457 |
-
//// Mage::log(print_r($_productResult, true), null, 'tracer.log', true);
|
458 |
-
// foreach ($_productResult as $key => $value) {
|
459 |
-
// $template = str_replace('{' . $key . '}', $value, $template);
|
460 |
-
// }
|
461 |
-
//
|
462 |
-
// // Just for {Block} crap
|
463 |
-
// $template = str_replace('{Block}', '', $template);
|
464 |
-
//
|
465 |
-
// return $template;
|
466 |
-
// }
|
467 |
-
//
|
468 |
-
// $displayUSD = "''"; //CartCountryIso
|
469 |
-
// /*}else{
|
470 |
-
// return "Plantilla de error";
|
471 |
-
// }*/
|
472 |
-
// //Mage::log(get_class($this) . " GetTemplateProduct() ", null, 'cart.log', true);
|
473 |
-
} else {
|
474 |
-
$template = '<div class="skx_content_button"></div>';
|
475 |
-
return $template;
|
476 |
-
}
|
477 |
-
return "";
|
478 |
-
}
|
479 |
-
|
480 |
-
protected $_isUSD = null;
|
481 |
-
|
482 |
-
public function IsUSD()
|
483 |
-
{
|
484 |
-
if (null == $this->_isUSD) {
|
485 |
-
$this->_isUSD = ($this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_CART_CURRENCY_ISO,
|
486 |
-
"") == Skybox_Core_Model_Config::SKYBOX_CURRENCY_USD);
|
487 |
-
}
|
488 |
-
return $this->_isUSD;
|
489 |
-
}
|
490 |
-
|
491 |
-
public function getCustoms()
|
492 |
-
{
|
493 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS, "0");
|
494 |
-
}
|
495 |
-
|
496 |
-
public function getShipping()
|
497 |
-
{
|
498 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING, "0");
|
499 |
-
}
|
500 |
-
|
501 |
-
public function getInsurance()
|
502 |
-
{
|
503 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE, "0");
|
504 |
-
}
|
505 |
-
|
506 |
-
public function getPrice()
|
507 |
-
{
|
508 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_PRICE, "0");
|
509 |
-
}
|
510 |
-
|
511 |
-
public function getTotalPrice()
|
512 |
-
{
|
513 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_TOTAL, "0");
|
514 |
-
}
|
515 |
-
|
516 |
-
public function getCustomsUSD()
|
517 |
-
{
|
518 |
-
return $this->IsUSD() ? $this->getCustoms() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS_USD,
|
519 |
-
"0");
|
520 |
-
}
|
521 |
-
|
522 |
-
public function getShippingUSD()
|
523 |
-
{
|
524 |
-
return $this->IsUSD() ? $this->getShipping() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING_USD,
|
525 |
-
"0");
|
526 |
-
}
|
527 |
-
|
528 |
-
public function getInsuranceUSD()
|
529 |
-
{
|
530 |
-
return $this->IsUSD() ? $this->getInsurance() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE_USD,
|
531 |
-
"0");
|
532 |
-
}
|
533 |
-
|
534 |
-
public function getPriceUSD()
|
535 |
-
{
|
536 |
-
return $this->IsUSD() ? $this->getPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_PRICE_USD,
|
537 |
-
"0");
|
538 |
-
}
|
539 |
-
|
540 |
-
public function getTotalPriceUSD()
|
541 |
-
{
|
542 |
-
return $this->IsUSD() ? $this->getTotalPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_TOTAL_USD,
|
543 |
-
"0");
|
544 |
-
}
|
545 |
-
|
546 |
-
public function getGuidSkybox()
|
547 |
-
{
|
548 |
-
return $this->_getApi()->getGuidApi();
|
549 |
-
}
|
550 |
-
|
551 |
-
public function getBasePrice()
|
552 |
-
{
|
553 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_BASE_PRICE, "0");
|
554 |
-
}
|
555 |
-
|
556 |
-
public function getBasePriceUSD()
|
557 |
-
{
|
558 |
-
return $this->IsUSD() ? $this->getBasePrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_BASE_PRICE_USD,
|
559 |
-
"0");
|
560 |
-
}
|
561 |
-
|
562 |
-
public function getAdjustPrice()
|
563 |
-
{
|
564 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_ADJUST_PRICE, "0");
|
565 |
-
}
|
566 |
-
|
567 |
-
public function getAdjustPriceUSD()
|
568 |
-
{
|
569 |
-
return $this->IsUSD() ? $this->getAdjustPrice() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_ADJUST_PRICE_USD,
|
570 |
-
"0");
|
571 |
-
}
|
572 |
-
|
573 |
-
public function getAdjustLabel()
|
574 |
-
{
|
575 |
-
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_LABEL_ADJUST, "");
|
576 |
-
}
|
577 |
-
|
578 |
-
/*Async Ini*/
|
579 |
-
|
580 |
-
public function getUrl($product, $request, $finalPrice = null, $type = null, $objectId = 1)
|
581 |
-
{
|
582 |
-
Mage::log("ApiProductCatalog ", null, 'orden.log', true);
|
583 |
-
|
584 |
-
//Mage::log(print_r('Product', true), null, 'tracer.log', true);
|
585 |
-
|
586 |
-
//if ($this->getErrorAuthenticate() && !$this->getLocationAllow()) {
|
587 |
-
if (!$this->getLocationAllow()) {
|
588 |
-
return $this;
|
589 |
-
}
|
590 |
-
|
591 |
-
if (!is_object($product)) {
|
592 |
-
$storeId = Mage::app()->getStore()->getStoreId();
|
593 |
-
$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product);
|
594 |
-
}
|
595 |
-
|
596 |
-
$productId = $product->getId();
|
597 |
-
$_data = null;
|
598 |
-
|
599 |
-
if ($type == null) {
|
600 |
-
$type = $product->getTypeId();
|
601 |
-
}
|
602 |
-
|
603 |
-
$defaultSwitch = true;
|
604 |
-
switch ($type) {
|
605 |
-
case 'simple':
|
606 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : $product->getFinalPrice();
|
607 |
-
$category_id = $product->getSkyboxCategoryId();
|
608 |
-
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
609 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
610 |
-
|
611 |
-
$_data = array(
|
612 |
-
'object_id' => $product->getId(),
|
613 |
-
'name' => $product->getName(),
|
614 |
-
'sku' => $product->getSku(),
|
615 |
-
'category_id' => $category_id,
|
616 |
-
'final_price' => $finalPrice,
|
617 |
-
'weight' => ($product->getWeight()) ? $product->getWeight() : 1,
|
618 |
-
'image_url' => $product->getImageUrl(),
|
619 |
-
'typeProduct' => $type,
|
620 |
-
'VolWeight' => $volWeight,
|
621 |
-
'merchantproductid' => $productId
|
622 |
-
);
|
623 |
-
// $this->_calculatePrice($_data);
|
624 |
-
break;
|
625 |
-
|
626 |
-
case 'configurable':
|
627 |
-
|
628 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
629 |
-
$weight = $product->getTypeInstance(true)->getWeight($product);
|
630 |
-
$sku = $product->getSku();
|
631 |
-
|
632 |
-
Mage::log("CalculatePrice configurable : " . $finalPrice, null, 'skyboxcheckout.log', false);
|
633 |
-
|
634 |
-
if ($request) {
|
635 |
-
$childProduct = Mage::getModel('catalog/product_type_configurable')
|
636 |
-
->getProductByAttributes($request->getData('super_attribute'), $product);
|
637 |
-
|
638 |
-
$productId = $childProduct->getId();
|
639 |
-
$sku = $childProduct->getSku();
|
640 |
-
|
641 |
-
}
|
642 |
-
|
643 |
-
$parentItem = null;
|
644 |
-
|
645 |
-
if (isset($request) && !$finalPrice) {
|
646 |
-
Mage::log("CalculatePrice candidate INI", null, 'skyboxcheckout.log', false);
|
647 |
-
$_finalPrice = 0;
|
648 |
-
|
649 |
-
$cartCandidates = $product->getTypeInstance(true)
|
650 |
-
->prepareForCartAdvanced($request, $product, 'full');
|
651 |
-
|
652 |
-
foreach ($cartCandidates as $candidate) {
|
653 |
-
// Child items can be sticked together only within their parent
|
654 |
-
$stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
|
655 |
-
$candidate->setStickWithinParent($stickWithinParent);
|
656 |
-
|
657 |
-
$candidate_getFinalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(),
|
658 |
-
$product);
|
659 |
-
Mage::log("CalculatePrice candidate getFinalPrice: " . $candidate_getFinalPrice, null,
|
660 |
-
'skyboxcheckout.log', false);
|
661 |
-
|
662 |
-
$_finalPrice = $_finalPrice + $candidate_getFinalPrice;
|
663 |
-
if ($_finalPrice) {
|
664 |
-
break;
|
665 |
-
}
|
666 |
-
}
|
667 |
-
$finalPrice = $_finalPrice;
|
668 |
-
Mage::log("CalculatePrice candidate FIN", null, 'skyboxcheckout.log', false);
|
669 |
-
}
|
670 |
-
|
671 |
-
$category_id = $product->getSkyboxCategoryId();
|
672 |
-
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
673 |
-
|
674 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
675 |
-
|
676 |
-
$_data = array(
|
677 |
-
'object_id' => $product->getId(),
|
678 |
-
'name' => $product->getName(),
|
679 |
-
//'sku' => $product->getSku(),
|
680 |
-
'sku' => $sku,
|
681 |
-
'category_id' => $category_id,
|
682 |
-
'final_price' => $finalPrice,
|
683 |
-
'weight' => $weight ? $weight : 1,
|
684 |
-
'image_url' => $product->getImageUrl(),
|
685 |
-
'typeProduct' => $type,
|
686 |
-
'VolWeight' => $volWeight,
|
687 |
-
'merchantproductid' => $productId
|
688 |
-
);
|
689 |
-
|
690 |
-
// $this->_calculatePrice($_data);
|
691 |
-
break;
|
692 |
-
|
693 |
-
case 'bundle':
|
694 |
-
//$_finalPrice = $product->getTotalBundleItemsPrice($product, $request->getQty());
|
695 |
-
//$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
696 |
-
|
697 |
-
//Mage::log(print_r($product, true), null, 'cart.log', true);
|
698 |
-
//Mage::log("Product: [" . $product->getId() . "] - Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
699 |
-
|
700 |
-
//Mage::log(print_r($request, true), null, 'cart.log', true);
|
701 |
-
|
702 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
703 |
-
$weight = $product->getTypeInstance(true)->getWeight($product);
|
704 |
-
$sku = $product->getSku();
|
705 |
-
|
706 |
-
//if (isset($request) && !$finalPrice) {
|
707 |
-
if (isset($request)) {
|
708 |
-
|
709 |
-
$parentItem = null;
|
710 |
-
$_finalPrice = null;
|
711 |
-
$_weight = 0;
|
712 |
-
|
713 |
-
$cartCandidates = $product->getTypeInstance(true)
|
714 |
-
->prepareForCartAdvanced($request, $product, 'full');
|
715 |
-
|
716 |
-
foreach ($cartCandidates as $candidate) {
|
717 |
-
// Child items can be sticked together only within their parent
|
718 |
-
$stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
|
719 |
-
$candidate->setStickWithinParent($stickWithinParent);
|
720 |
-
|
721 |
-
if (!$_finalPrice) {
|
722 |
-
$_finalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
|
723 |
-
//break;
|
724 |
-
}
|
725 |
-
//$_weight = $_weight + $candidate->getPriceModel()->getWeight();
|
726 |
-
$_weight = $_weight + $candidate->getWeight();
|
727 |
-
}
|
728 |
-
|
729 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
730 |
-
if ($_weight > 0) {
|
731 |
-
$weight = $_weight;
|
732 |
-
}
|
733 |
-
}
|
734 |
-
|
735 |
-
//Mage::log("weight: " . $weight, null, 'cart.log', true);
|
736 |
-
//Mage::log("sku: " . $sku, null, 'cart.log', true);
|
737 |
-
|
738 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
739 |
-
$_data = array(
|
740 |
-
'object_id' => $product->getId(),
|
741 |
-
'name' => $product->getName(),
|
742 |
-
'sku' => $sku,
|
743 |
-
'category_id' => $product->getSkyboxCategoryId(),
|
744 |
-
'final_price' => $finalPrice,
|
745 |
-
'weight' => ($weight) ? $weight : 1,
|
746 |
-
'image_url' => $product->getImageUrl(),
|
747 |
-
'typeProduct' => $type,
|
748 |
-
'VolWeight' => $volWeight,
|
749 |
-
'merchantproductid' => $productId
|
750 |
-
);
|
751 |
-
// $this->_calculatePrice($_data);
|
752 |
-
break;
|
753 |
-
|
754 |
-
case 'bundle_fixed':
|
755 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
756 |
-
$skyboxCategoryId = $product->getSkyboxCategoryId();
|
757 |
-
$weight = $product->getTypeInstance(true)->getWeight($product);
|
758 |
-
$sku = $product->getSku();
|
759 |
-
|
760 |
-
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
|
761 |
-
$product->getTypeInstance(true)->getOptionsIds($product), $product
|
762 |
-
);
|
763 |
-
|
764 |
-
$_finalPrice = null;
|
765 |
-
$_weight = 0;
|
766 |
-
$_skyboxCategoryId = null;
|
767 |
-
|
768 |
-
foreach ($selectionCollection as $option) {
|
769 |
-
//if ($option->getData('is_default') == 0) continue;
|
770 |
-
|
771 |
-
$product_simple = Mage::getModel('catalog/product')
|
772 |
-
->load($option->getId());
|
773 |
-
|
774 |
-
$_finalPrice = $_finalPrice + $product_simple->getFinalPrice();
|
775 |
-
$_weight = $_weight + $product_simple->getWeight();
|
776 |
-
|
777 |
-
if (!$_skyboxCategoryId) { // Set SkyboxCategory from the first Simple Product
|
778 |
-
$_skyboxCategoryId = $product_simple->getSkyboxCategoryId();
|
779 |
-
}
|
780 |
-
}
|
781 |
-
|
782 |
-
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
783 |
-
|
784 |
-
if (!$weight) {
|
785 |
-
$weight = $_weight;
|
786 |
-
}
|
787 |
-
|
788 |
-
if (!$skyboxCategoryId) {
|
789 |
-
$skyboxCategoryId = $_skyboxCategoryId;
|
790 |
-
}
|
791 |
-
|
792 |
-
/*Mage::log("-------------------------", null, 'cart.log', true);
|
793 |
-
Mage::log("Product: " . $product->getName(), null, 'cart.log', true);
|
794 |
-
Mage::log("Price: " . $finalPrice, null, 'cart.log', true);
|
795 |
-
Mage::log("weight: " . $weight, null, 'cart.log', true);
|
796 |
-
Mage::log("sku: " . $sku, null, 'cart.log', true);*/
|
797 |
-
|
798 |
-
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
799 |
-
$_data = array(
|
800 |
-
'object_id' => $product->getId(),
|
801 |
-
'name' => $product->getName(),
|
802 |
-
'sku' => $sku,
|
803 |
-
'category_id' => $skyboxCategoryId,
|
804 |
-
'final_price' => $finalPrice,
|
805 |
-
'weight' => ($weight) ? $weight : 1,
|
806 |
-
'image_url' => $product->getImageUrl(),
|
807 |
-
'typeProduct' => $type,
|
808 |
-
'VolWeight' => $volWeight,
|
809 |
-
'merchantproductid' => $productId
|
810 |
-
);
|
811 |
-
|
812 |
-
// $this->_calculatePrice($_data);
|
813 |
-
break;
|
814 |
-
|
815 |
-
default:
|
816 |
-
Mage::log("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice",
|
817 |
-
null, 'skyboxcheckout.log', false);
|
818 |
-
trigger_error("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice");
|
819 |
-
$defaultSwitch = true;
|
820 |
-
break;
|
821 |
-
}
|
822 |
-
|
823 |
-
if (!$defaultSwitch) {
|
824 |
-
//Mage::log(print_r('EnableTax: ', true), null, 'tracer.log', true);
|
825 |
-
//Mage::log(print_r($this->getEnabledAddSumTaxToPrice(), true), null, 'tracer.log', true);
|
826 |
-
if ($this->getEnabledAddSumTaxToPrice()) {
|
827 |
-
$store = Mage::app()->getStore('default');
|
828 |
-
$taxCalculation = Mage::getModel('tax/calculation');
|
829 |
-
$request = $taxCalculation->getRateRequest(null, null, null, $store);
|
830 |
-
// $product = Mage::registry('current_product');
|
831 |
-
$taxClassId = $product->getTaxClassId();
|
832 |
-
$percentTax = $taxCalculation->getRate($request->setProductClassId($taxClassId));
|
833 |
-
|
834 |
-
$taxPrice = $_data['final_price'] * ($percentTax / 100);
|
835 |
-
|
836 |
-
//Mage::log(print_r('Id product: ' . $product->getId(), true), null, 'tracer.log', true);
|
837 |
-
//Mage::log(print_r('$taxPrice: ' . $taxPrice, true), null, 'tracer.log', true);
|
838 |
-
//Mage::log(print_r('price: ' . $_data['final_price'], true), null, 'tracer.log', true);
|
839 |
-
//Mage::log(print_r('$taxPrice+price: ' . ($taxPrice + $_data['final_price']), true), null, 'tracer.log', true);
|
840 |
-
$comissionSkybox = $_data['final_price'] * (10 / 100);
|
841 |
-
//Mage::log(print_r('comision skybox: ' . ($comissionSkybox), true), null, 'tracer.log', true);
|
842 |
-
//Mage::log(print_r('price+comision skybox: ' . ($_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
843 |
-
//Mage::log(print_r('$taxPrice+price+comision: ' . ($taxPrice + $_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
844 |
-
//Mage::log(print_r('comision true: ' . (($taxPrice + $_data['final_price']) * (10 / 100)), true), null, 'tracer.log', true);
|
845 |
-
$priceReally = ($taxPrice + $_data['final_price']) + ($taxPrice + $_data['final_price']) * (10 / 100);
|
846 |
-
//Mage::log(print_r('$taxPrice+price+comision true: ' . ($priceReally), true), null, 'tracer.log', true);
|
847 |
-
$_data['final_price'] = $_data['final_price'] + $taxPrice;
|
848 |
-
}
|
849 |
-
|
850 |
-
//Mage::log(print_r('####################### Data produc params #######################', true), null, 'tracer.log', true);
|
851 |
-
//Mage::log(print_r($_data, true), null, 'tracer.log', true);
|
852 |
-
try {
|
853 |
-
$this->_calculatePrice($_data);
|
854 |
-
} catch (\Exception $e) {
|
855 |
-
Mage::log($e->getMessage(), null, 'skyboxcheckout.log', false);
|
856 |
-
}
|
857 |
-
|
858 |
-
}
|
859 |
-
|
860 |
-
Mage::log("Product Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
861 |
-
Mage::log("Product Type: " . $type, null, 'skyboxcheckout.log', false);
|
862 |
-
Mage::log(print_r($_data, true), null, 'skyboxcheckout.log', false);
|
863 |
-
|
864 |
-
$data = $this->_callServiceSky($_data);
|
865 |
-
/*var_dump($this); exit;
|
866 |
-
$this->_product_data = $_data;
|
867 |
-
$this->_product_id = $productId;
|
868 |
-
$apiData = $this->_api;
|
869 |
-
var_dump($apiData); exit;*/
|
870 |
-
return $data;
|
871 |
-
}
|
872 |
-
|
873 |
-
/**
|
874 |
-
* Return the Commodity from Category or Root
|
875 |
-
*
|
876 |
-
* @param $product
|
877 |
-
* @return int
|
878 |
-
*/
|
879 |
-
public function getCommodityFromCategory($product)
|
880 |
-
{
|
881 |
-
$result = 0;
|
882 |
-
|
883 |
-
try {
|
884 |
-
$categoryIds = $product->getCategoryIds();
|
885 |
-
|
886 |
-
if (count($categoryIds)) {
|
887 |
-
$categoryId = $categoryIds[0];
|
888 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
889 |
-
$result = $category->getSkyboxCategoryIdSelect();
|
890 |
-
}
|
891 |
-
|
892 |
-
if (empty($result)) {
|
893 |
-
$categoryId = Mage::app()->getStore()->getRootCategoryId();
|
894 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
895 |
-
$result = $category->getSkyboxCategoryIdSelect();
|
896 |
-
}
|
897 |
-
|
898 |
-
$result = isset($result) ? $result : 0;
|
899 |
-
|
900 |
-
} catch (\Exception $e) {
|
901 |
-
\error_log("catch exception product_: " . $product . PHP_EOL, 3, BP . '/var/log/magento19.trace.log');
|
902 |
-
}
|
903 |
-
|
904 |
-
return $result;
|
905 |
-
}
|
906 |
-
|
907 |
-
private function _callServiceSky($data)
|
908 |
-
{
|
909 |
-
$msg = sprintf("CalculatePrice: [%s] - [%s] - [%s] - [Category_id: %s] - [Price: %s] - [weight: %s] - [typeProduct: %s]",
|
910 |
-
$data['object_id'],
|
911 |
-
$data['sku'],
|
912 |
-
$data['name'],
|
913 |
-
$data['category_id'],
|
914 |
-
$data['final_price'],
|
915 |
-
$data['weight'],
|
916 |
-
$data['typeProduct']
|
917 |
-
);
|
918 |
-
|
919 |
-
$params = array(
|
920 |
-
'htmlobjectid' => $data['object_id'],
|
921 |
-
'code' => $data['sku'],
|
922 |
-
'name' => $data['name'],
|
923 |
-
'category' => $data['category_id'],
|
924 |
-
'price' => $data['final_price'],
|
925 |
-
//'storeproductprice' => $product->getFinalPrice(),
|
926 |
-
'weight' => ($data['weight']) ? $data['weight'] : 1,
|
927 |
-
'weightunit' => $this->getWeightUnit(),
|
928 |
-
'imgurl' => $data['image_url'],
|
929 |
-
/*'volweight' => $data['VolWeight'],
|
930 |
-
'merchantproductid' => $data['merchantproductid']*/
|
931 |
-
);
|
932 |
-
//var_dump($params); exit;
|
933 |
-
return $params;
|
934 |
-
}
|
935 |
-
|
936 |
-
/*Async End*/
|
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) ? $category_id : $this->getCommodityFromCategory($product);
|
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(),
|
145 |
+
$product);
|
146 |
+
Mage::log("CalculatePrice candidate getFinalPrice: " . $candidate_getFinalPrice, null,
|
147 |
+
'skyboxcheckout.log', false);
|
148 |
+
|
149 |
+
$_finalPrice = $_finalPrice + $candidate_getFinalPrice;
|
150 |
+
if ($_finalPrice) {
|
151 |
+
break;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
$finalPrice = $_finalPrice;
|
155 |
+
Mage::log("CalculatePrice candidate FIN", null, 'skyboxcheckout.log', false);
|
156 |
+
}
|
157 |
+
|
158 |
+
/* Weight start*/
|
159 |
+
/*
|
160 |
+
$options = array();
|
161 |
+
// Get any super_attribute settings we need
|
162 |
+
$productAttributesOptions = $product->getTypeInstance(true)->getConfigurableOptions($product);
|
163 |
+
foreach ($productAttributesOptions as $productAttributeOption) {
|
164 |
+
$options[$product->getId()] = array();
|
165 |
+
foreach ($productAttributeOption as $optionValues) {
|
166 |
+
$val = ($optionValues['option_title']);
|
167 |
+
$options[$product->getId()][] = array (
|
168 |
+
$optionValues['sku'] => $optionValues['attribute_code']."=".$val
|
169 |
+
|
170 |
+
) ;
|
171 |
+
}
|
172 |
+
|
173 |
+
}
|
174 |
+
$prod_weight = 1;
|
175 |
+
if(!empty($optionValues)) {
|
176 |
+
$a = Mage::getModel('catalog/product')->loadByAttribute('sku',$optionValues['sku']);
|
177 |
+
//$product->load($product->getIdBySku($optionValues['sku']));
|
178 |
+
$prod_weight = $a->getWeight();
|
179 |
+
echo ":::".$prod_weight."::";
|
180 |
+
}
|
181 |
+
*/
|
182 |
+
/* Weight end*/
|
183 |
+
|
184 |
+
$category_id = $product->getSkyboxCategoryId();
|
185 |
+
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
186 |
+
|
187 |
+
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
188 |
+
$_data = array(
|
189 |
+
'object_id' => 1,
|
190 |
+
'name' => $product->getName(),
|
191 |
+
//'sku' => $product->getSku(),
|
192 |
+
'sku' => $sku,
|
193 |
+
'category_id' => $category_id,
|
194 |
+
'final_price' => $finalPrice,
|
195 |
+
'weight' => $weight ? $weight : 1,
|
196 |
+
'image_url' => $product->getImageUrl(),
|
197 |
+
'typeProduct' => $type,
|
198 |
+
'VolWeight' => $volWeight,
|
199 |
+
'merchantproductid' => $productId
|
200 |
+
);
|
201 |
+
|
202 |
+
// $this->_calculatePrice($_data);
|
203 |
+
break;
|
204 |
+
|
205 |
+
case 'bundle':
|
206 |
+
//$_finalPrice = $product->getTotalBundleItemsPrice($product, $request->getQty());
|
207 |
+
//$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
208 |
+
|
209 |
+
//Mage::log(print_r($product, true), null, 'cart.log', true);
|
210 |
+
//Mage::log("Product: [" . $product->getId() . "] - Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
211 |
+
|
212 |
+
//Mage::log(print_r($request, true), null, 'cart.log', true);
|
213 |
+
|
214 |
+
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
215 |
+
$weight = $product->getTypeInstance(true)->getWeight($product);
|
216 |
+
$sku = $product->getSku();
|
217 |
+
|
218 |
+
//if (isset($request) && !$finalPrice) {
|
219 |
+
if (isset($request)) {
|
220 |
+
|
221 |
+
$parentItem = null;
|
222 |
+
$_finalPrice = null;
|
223 |
+
$_weight = 0;
|
224 |
+
|
225 |
+
$cartCandidates = $product->getTypeInstance(true)
|
226 |
+
->prepareForCartAdvanced($request, $product, 'full');
|
227 |
+
|
228 |
+
foreach ($cartCandidates as $candidate) {
|
229 |
+
// Child items can be sticked together only within their parent
|
230 |
+
$stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
|
231 |
+
$candidate->setStickWithinParent($stickWithinParent);
|
232 |
+
|
233 |
+
if (!$_finalPrice) {
|
234 |
+
$_finalPrice = $candidate->getPriceModel()->getFinalPrice($request->getQty(), $product);
|
235 |
+
//break;
|
236 |
+
}
|
237 |
+
//$_weight = $_weight + $candidate->getPriceModel()->getWeight();
|
238 |
+
$_weight = $_weight + $candidate->getWeight();
|
239 |
+
}
|
240 |
+
|
241 |
+
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
242 |
+
if ($_weight > 0) {
|
243 |
+
$weight = $_weight;
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
//Mage::log("weight: " . $weight, null, 'cart.log', true);
|
248 |
+
//Mage::log("sku: " . $sku, null, 'cart.log', true);
|
249 |
+
|
250 |
+
$category_id = $product->getSkyboxCategoryId();
|
251 |
+
$category_id = isset($category_id) ? $category_id : $this->getCommodityFromCategory($product);
|
252 |
+
|
253 |
+
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
254 |
+
$_data = array(
|
255 |
+
'object_id' => 1,
|
256 |
+
'name' => $product->getName(),
|
257 |
+
'sku' => $sku,
|
258 |
+
'category_id' => $category_id,
|
259 |
+
'final_price' => $finalPrice,
|
260 |
+
'weight' => ($weight) ? $weight : 1,
|
261 |
+
'image_url' => $product->getImageUrl(),
|
262 |
+
'typeProduct' => $type,
|
263 |
+
'VolWeight' => $volWeight,
|
264 |
+
'merchantproductid' => $productId
|
265 |
+
);
|
266 |
+
// $this->_calculatePrice($_data);
|
267 |
+
break;
|
268 |
+
|
269 |
+
case 'bundle_fixed':
|
270 |
+
|
271 |
+
// @Note: It should be rewrite!!
|
272 |
+
$finalPrice = isset($finalPrice) ? $finalPrice : null;
|
273 |
+
$skyboxCategoryId = $product->getSkyboxCategoryId();
|
274 |
+
$weight = $product->getTypeInstance(true)->getWeight($product);
|
275 |
+
$sku = $product->getSku();
|
276 |
+
|
277 |
+
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
|
278 |
+
$product->getTypeInstance(true)->getOptionsIds($product), $product
|
279 |
+
);
|
280 |
+
|
281 |
+
$_finalPrice = null;
|
282 |
+
$_weight = 0;
|
283 |
+
$_skyboxCategoryId = null;
|
284 |
+
|
285 |
+
foreach ($selectionCollection as $option) {
|
286 |
+
//if ($option->getData('is_default') == 0) continue;
|
287 |
+
|
288 |
+
$product_simple = Mage::getModel('catalog/product')
|
289 |
+
->load($option->getId());
|
290 |
+
|
291 |
+
$_finalPrice = $_finalPrice + $product_simple->getFinalPrice();
|
292 |
+
$_weight = $_weight + $product_simple->getWeight();
|
293 |
+
|
294 |
+
if (!$_skyboxCategoryId) { // Set SkyboxCategory from the first Simple Product
|
295 |
+
// $_skyboxCategoryId = $product_simple->getSkyboxCategoryId();
|
296 |
+
$_skyboxCategoryId = $product->getSkyboxCategoryId();
|
297 |
+
$_skyboxCategoryId = isset($_skyboxCategoryId) ? $_skyboxCategoryId : $this->getCommodityFromCategory($product);
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
$finalPrice = isset($finalPrice) ? $finalPrice : $_finalPrice;
|
302 |
+
|
303 |
+
if (!$weight) {
|
304 |
+
$weight = $_weight;
|
305 |
+
}
|
306 |
+
|
307 |
+
if (!$skyboxCategoryId) {
|
308 |
+
$skyboxCategoryId = $_skyboxCategoryId;
|
309 |
+
}
|
310 |
+
|
311 |
+
/*Mage::log("-------------------------", null, 'cart.log', true);
|
312 |
+
Mage::log("Product: " . $product->getName(), null, 'cart.log', true);
|
313 |
+
Mage::log("Price: " . $finalPrice, null, 'cart.log', true);
|
314 |
+
Mage::log("weight: " . $weight, null, 'cart.log', true);
|
315 |
+
Mage::log("sku: " . $sku, null, 'cart.log', true);*/
|
316 |
+
|
317 |
+
|
318 |
+
$volWeight = !empty(trim($product->getDimensionalWeight())) ? $product->getDimensionalWeight() : 0;
|
319 |
+
$_data = array(
|
320 |
+
'object_id' => 1,
|
321 |
+
'name' => $product->getName(),
|
322 |
+
'sku' => $sku,
|
323 |
+
'category_id' => $skyboxCategoryId,
|
324 |
+
'final_price' => $finalPrice,
|
325 |
+
'weight' => ($weight) ? $weight : 1,
|
326 |
+
'image_url' => $product->getImageUrl(),
|
327 |
+
'typeProduct' => $type,
|
328 |
+
'VolWeight' => $volWeight,
|
329 |
+
'merchantproductid' => $productId
|
330 |
+
);
|
331 |
+
|
332 |
+
// $this->_calculatePrice($_data);
|
333 |
+
break;
|
334 |
+
|
335 |
+
default:
|
336 |
+
Mage::log("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice",
|
337 |
+
null, 'skyboxcheckout.log', false);
|
338 |
+
trigger_error("CalculatePrice:: Product Type (" . $type . ") is invalid or not supported at SkyboxCheckout CalculatePrice");
|
339 |
+
$defaultSwitch = true;
|
340 |
+
break;
|
341 |
+
}
|
342 |
+
|
343 |
+
if (!$defaultSwitch) {
|
344 |
+
//Mage::log(print_r('EnableTax: ', true), null, 'tracer.log', true);
|
345 |
+
//Mage::log(print_r($this->getEnabledAddSumTaxToPrice(), true), null, 'tracer.log', true);
|
346 |
+
if ($this->getEnabledAddSumTaxToPrice()) {
|
347 |
+
$store = Mage::app()->getStore('default');
|
348 |
+
$taxCalculation = Mage::getModel('tax/calculation');
|
349 |
+
$request = $taxCalculation->getRateRequest(null, null, null, $store);
|
350 |
+
// $product = Mage::registry('current_product');
|
351 |
+
$taxClassId = $product->getTaxClassId();
|
352 |
+
$percentTax = $taxCalculation->getRate($request->setProductClassId($taxClassId));
|
353 |
+
|
354 |
+
$taxPrice = $_data['final_price'] * ($percentTax / 100);
|
355 |
+
|
356 |
+
//Mage::log(print_r('Id product: ' . $product->getId(), true), null, 'tracer.log', true);
|
357 |
+
//Mage::log(print_r('$taxPrice: ' . $taxPrice, true), null, 'tracer.log', true);
|
358 |
+
//Mage::log(print_r('price: ' . $_data['final_price'], true), null, 'tracer.log', true);
|
359 |
+
//Mage::log(print_r('$taxPrice+price: ' . ($taxPrice + $_data['final_price']), true), null, 'tracer.log', true);
|
360 |
+
$comissionSkybox = $_data['final_price'] * (10 / 100);
|
361 |
+
//Mage::log(print_r('comision skybox: ' . ($comissionSkybox), true), null, 'tracer.log', true);
|
362 |
+
//Mage::log(print_r('price+comision skybox: ' . ($_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
363 |
+
//Mage::log(print_r('$taxPrice+price+comision: ' . ($taxPrice + $_data['final_price'] + $comissionSkybox), true), null, 'tracer.log', true);
|
364 |
+
//Mage::log(print_r('comision true: ' . (($taxPrice + $_data['final_price']) * (10 / 100)), true), null, 'tracer.log', true);
|
365 |
+
$priceReally = ($taxPrice + $_data['final_price']) + ($taxPrice + $_data['final_price']) * (10 / 100);
|
366 |
+
//Mage::log(print_r('$taxPrice+price+comision true: ' . ($priceReally), true), null, 'tracer.log', true);
|
367 |
+
|
368 |
+
|
369 |
+
$_data['final_price'] = $_data['final_price'] + $taxPrice;
|
370 |
+
}
|
371 |
+
|
372 |
+
//Mage::log(print_r('####################### Data produc params #######################', true), null, 'tracer.log', true);
|
373 |
+
//Mage::log(print_r($_data, true), null, 'tracer.log', true);
|
374 |
+
// $this->_calculatePrice($_data);
|
375 |
+
try {
|
376 |
+
$this->_calculatePrice($_data);
|
377 |
+
} catch (\Exception $e) {
|
378 |
+
Mage::log($e->getMessage(), null, 'skyboxcheckout.log', false);
|
379 |
+
}
|
380 |
+
}
|
381 |
+
|
382 |
+
Mage::log("Product Class: " . get_class($product), null, 'skyboxcheckout.log', false);
|
383 |
+
Mage::log("Product Type: " . $type, null, 'skyboxcheckout.log', false);
|
384 |
+
Mage::log(print_r($_data, true), null, 'skyboxcheckout.log', false);
|
385 |
+
|
386 |
+
$this->_product_data = $_data;
|
387 |
+
$this->_product_id = $productId;
|
388 |
+
return $this;
|
389 |
+
}
|
390 |
+
|
391 |
+
private function _calculatePrice($data)
|
392 |
+
{
|
393 |
+
$msg = sprintf("CalculatePrice: [%s] - [%s] - [%s] - [Category_id: %s] - [Price: %s] - [weight: %s] - [typeProduct: %s]",
|
394 |
+
$data['object_id'],
|
395 |
+
$data['sku'],
|
396 |
+
$data['name'],
|
397 |
+
$data['category_id'],
|
398 |
+
$data['final_price'],
|
399 |
+
$data['weight'],
|
400 |
+
$data['typeProduct']
|
401 |
+
);
|
402 |
+
|
403 |
+
Mage::log($msg, null, 'skyboxcheckout.log', false);
|
404 |
+
|
405 |
+
$params = array(
|
406 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
|
407 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
|
408 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi(),
|
409 |
+
'htmlobjectid' => $data['object_id'],
|
410 |
+
'storeproductcode' => $data['sku'],
|
411 |
+
'storeproductname' => $data['name'],
|
412 |
+
'storeproductcategory' => $data['category_id'],
|
413 |
+
'storeproductprice' => $data['final_price'],
|
414 |
+
//'storeproductprice' => $product->getFinalPrice(),
|
415 |
+
'weight' => ($data['weight']) ? $data['weight'] : 1,
|
416 |
+
'weightunit' => $this->getWeightUnit(),
|
417 |
+
'storeproductimgurl' => $data['image_url'],
|
418 |
+
'merchantproductid' => $data['merchantproductid']
|
419 |
+
);
|
420 |
+
$this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_CALCULATE, $params);
|
421 |
+
}
|
422 |
+
|
423 |
+
public function HtmlTemplateButton()
|
424 |
+
{
|
425 |
+
if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow()) {
|
426 |
+
$params = array(
|
427 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_MERCHANT => $this->getMerchant(),
|
428 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_TOKEN => $this->getAuthorizedToken(),
|
429 |
+
Skybox_Core_Model_Config::SKYBOX_PARAMETER_GUID => $this->getGuidApi()
|
430 |
+
);
|
431 |
+
|
432 |
+
$this->CallApiRest(Skybox_Core_Model_Config::SKYBOX_ACTION_GET_TEMPLATE_BUTTON, $params);
|
433 |
+
}
|
434 |
+
|
435 |
+
return $this;
|
436 |
+
}
|
437 |
+
|
438 |
+
public function GetTemplateProduct()
|
439 |
+
{
|
440 |
+
Mage::log("ApiProduct ", null, 'orden.log', true);
|
441 |
+
if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorServiceNotController()) {
|
442 |
+
//if (!$this->getErrorAuthenticate() && $this->_getApi()->getLocationAllow() && !$this->_getApi()->ErrorService()) {
|
443 |
+
$_productResult = $this->getResponse();
|
444 |
+
$template = $_productResult->TooltipButtonTemplate;
|
445 |
+
return $template;
|
446 |
+
// $templateButton = $this->getHtmlTemplateButton();
|
447 |
+
// if (empty($templateButton))
|
448 |
+
// $this->HtmlTemplateButton();
|
449 |
+
//
|
450 |
+
// /*if($_productResult->{Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_BUTTONERROR})
|
451 |
+
// {*/
|
452 |
+
// //Mage::log("_productResult--->" . json_decode($_productResult));
|
453 |
+
// $templateButton = $this->getHtmlTemplateButton();
|
454 |
+
// if (!empty($templateButton)) {
|
455 |
+
// $template = $this->getHtmlTemplateButton();
|
456 |
+
//// Mage::log(print_r('response template buttom', true), null, 'tracer.log', true);
|
457 |
+
//// Mage::log(print_r($_productResult, true), null, 'tracer.log', true);
|
458 |
+
// foreach ($_productResult as $key => $value) {
|
459 |
+
// $template = str_replace('{' . $key . '}', $value, $template);
|
460 |
+
// }
|
461 |
+
//
|
462 |
+
// // Just for {Block} crap
|
463 |
+
// $template = str_replace('{Block}', '', $template);
|
464 |
+
//
|
465 |
+
// return $template;
|
466 |
+
// }
|
467 |
+
//
|
468 |
+
// $displayUSD = "''"; //CartCountryIso
|
469 |
+
// /*}else{
|
470 |
+
// return "Plantilla de error";
|
471 |
+
// }*/
|
472 |
+
// //Mage::log(get_class($this) . " GetTemplateProduct() ", null, 'cart.log', true);
|
473 |
+
} else {
|
474 |
+
$template = '<div class="skx_content_button"></div>';
|
475 |
+
return $template;
|
476 |
+
}
|
477 |
+
return "";
|
478 |
+
}
|
479 |
+
|
480 |
+
protected $_isUSD = null;
|
481 |
+
|
482 |
+
public function IsUSD()
|
483 |
+
{
|
484 |
+
if (null == $this->_isUSD) {
|
485 |
+
$this->_isUSD = ($this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_CART_CURRENCY_ISO,
|
486 |
+
"") == Skybox_Core_Model_Config::SKYBOX_CURRENCY_USD);
|
487 |
+
}
|
488 |
+
return $this->_isUSD;
|
489 |
+
}
|
490 |
+
|
491 |
+
public function getCustoms()
|
492 |
+
{
|
493 |
+
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS, "0");
|
494 |
+
}
|
495 |
+
|
496 |
+
public function getShipping()
|
497 |
+
{
|
498 |
+
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING, "0");
|
499 |
+
}
|
500 |
+
|
501 |
+
public function getInsurance()
|
502 |
+
{
|
503 |
+
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE, "0");
|
504 |
+
}
|
505 |
+
|
506 |
+
public function getPrice()
|
507 |
+
{
|
508 |
+
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_PRICE, "0");
|
509 |
+
}
|
510 |
+
|
511 |
+
public function getTotalPrice()
|
512 |
+
{
|
513 |
+
return $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_TOTAL, "0");
|
514 |
+
}
|
515 |
+
|
516 |
+
public function getCustomsUSD()
|
517 |
+
{
|
518 |
+
return $this->IsUSD() ? $this->getCustoms() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_CUSTOMS_USD,
|
519 |
+
"0");
|
520 |
+
}
|
521 |
+
|
522 |
+
public function getShippingUSD()
|
523 |
+
{
|
524 |
+
return $this->IsUSD() ? $this->getShipping() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_SHIPPING_USD,
|
525 |
+
"0");
|
526 |
+
}
|
527 |
+
|
528 |
+
public function getInsuranceUSD()
|
529 |
+
{
|
530 |
+
return $this->IsUSD() ? $this->getInsurance() : $this->getParameter(Skybox_Core_Model_Config::SKYBOX_PARAMETER_RESPONSE_PRODUCT_INSURANCE_USD,
|
531 |
+
"0");
|