Created
October 6, 2010 16:57
-
-
Save lemonskip/613679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extend Mage_Catalog_Block_Product_View and override getJsonConfig as | |
public function getJsonConfig($_product = null, $configurable_id = null) | |
{ | |
$_product = $_product? Mage::getModel('catalog/product')->load($_product->getId()) : $this->getProduct(); | |
$config = array(); | |
if (!$this->hasOptions()) { | |
return Mage::helper('core')->jsonEncode($config); | |
} | |
$_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false); | |
$_request->setProductClassId($_product->getTaxClassId()); | |
$defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request); | |
$_request = Mage::getSingleton('tax/calculation')->getRateRequest(); | |
$_request->setProductClassId($_product->getTaxClassId()); | |
$currentTax = Mage::getSingleton('tax/calculation')->getRate($_request); | |
$_regularPrice = $_product->getPrice(); | |
$_finalPrice = $_product->getFinalPrice(); | |
$_priceInclTax = Mage::helper('tax')->getPrice($_product, $_finalPrice, true); | |
$_priceExclTax = Mage::helper('tax')->getPrice($_product, $_finalPrice); | |
$config = array( | |
'productId' => $configurable_id? $configurable_id : $_product->getId(), | |
'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(), | |
'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false', | |
'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(), | |
'showBothPrices' => Mage::helper('tax')->displayBothPrices(), | |
'productPrice' => Mage::helper('core')->currency($_finalPrice, false, false), | |
'productOldPrice' => Mage::helper('core')->currency($_regularPrice, false, false), | |
'skipCalculate' => ($_priceExclTax != $_priceInclTax ? 0 : 1), | |
'defaultTax' => $defaultTax, | |
'currentTax' => $currentTax, | |
'idSuffix' => '_clone', | |
'oldPlusDisposition' => 0, | |
'plusDisposition' => 0, | |
'oldMinusDisposition' => 0, | |
'minusDisposition' => 0, | |
); | |
$responseObject = new Varien_Object(); | |
Mage::dispatchEvent('catalog_product_view_config', array('response_object'=>$responseObject)); | |
if (is_array($responseObject->getAdditionalOptions())) { | |
foreach ($responseObject->getAdditionalOptions() as $option=>$value) { | |
$config[$option] = $value; | |
} | |
} | |
return Mage::helper('core')->jsonEncode($config); | |
} | |
# At the top of the Product view.phtml add | |
<script type="text/javascript"> | |
var selectedAssociatedOptionPrice = optionsPrice; | |
<?php if($_product->isConfigurable()): ?> | |
var associactedOptionsPrice = {}; | |
<?php | |
$_childProducts = $_product->getTypeInstance()->getUsedProducts(null, $_product); | |
foreach($_childProducts as $_childProduct): | |
?>associactedOptionsPrice.aPId<?php echo $_childProduct->getId(); ?> = new Product.OptionsPrice(<?php echo $this->getJsonConfig($_childProduct) ?>); | |
<?php endforeach; ?> | |
<?php endif; ?> | |
</script> | |
# rewrite your js function 'Product.Config.prototype.reloadPrice' in scp_product_extension.js to: | |
Product.Config.prototype.reloadPrice = function() { | |
var childProductId = this.getMatchingSimpleProduct(); | |
var childProducts = this.config.childProducts; | |
var usingZoomer = false; | |
if(this.config.imageZoomer){ | |
usingZoomer = true; | |
} | |
// LemonSkip Changes START: | |
selectedAssociatedOptionPrice = optionsPrice; | |
if (childProductId){ | |
// replace optionsPrice for an associated product | |
if(associactedOptionsPrice.hasOwnProperty('aPId'+childProductId)){ | |
selectedAssociatedOptionPrice = associactedOptionsPrice['aPId'+childProductId]; | |
} | |
var price = childProducts[childProductId]["price"]; | |
var finalPrice = childProducts[childProductId]["finalPrice"]; | |
selectedAssociatedOptionPrice.productPrice = finalPrice; | |
selectedAssociatedOptionPrice.productOldPrice = price; | |
selectedAssociatedOptionPrice.reload(); | |
selectedAssociatedOptionPrice.reloadPriceLabels(true); | |
selectedAssociatedOptionPrice.updateSpecialPriceDisplay(price, finalPrice); | |
// LemonSkip Changes END: | |
this.updateProductShortDescription(childProductId); | |
this.updateProductDescription(childProductId); | |
this.updateProductName(childProductId); | |
this.updateProductAttributes(childProductId); | |
this.updateFormProductId(childProductId); | |
this.addParentProductIdToCartForm(this.config.productId); | |
this.showCustomOptionsBlock(childProductId, this.config.productId); | |
if (usingZoomer) { | |
this.showFullImageDiv(childProductId, this.config.productId); | |
}else{ | |
this.updateProductImage(childProductId); | |
} | |
} else { | |
var cheapestPid = this.getProductIdOfCheapestProductInScope("finalPrice"); | |
//var mostExpensivePid = this.getProductIdOfMostExpensiveProductInScope("finalPrice"); | |
var price = childProducts[cheapestPid]["price"]; | |
var finalPrice = childProducts[cheapestPid]["finalPrice"]; | |
optionsPrice.productPrice = finalPrice; | |
optionsPrice.productOldPrice = price; | |
optionsPrice.reload(); | |
optionsPrice.reloadPriceLabels(false); | |
optionsPrice.updateSpecialPriceDisplay(price, finalPrice); | |
this.updateProductShortDescription(false); | |
this.updateProductDescription(false); | |
this.updateProductName(false); | |
this.updateProductAttributes(false); | |
this.showCustomOptionsBlock(false, false); | |
if (usingZoomer) { | |
this.showFullImageDiv(false, false); | |
}else{ | |
this.updateProductImage(false); | |
} | |
} | |
}; | |
# I did not change anything in scpajaxoptions.phtml as it always sent back an empty object!?! | |
# In scpoptions.phtml on line 130 ish I replaced it with | |
selectedAssociatedOptionPrice.changePrice('options', price); | |
selectedAssociatedOptionPrice.reload(); | |
# Now the tax of a the selected child product is applied to the view! Nauice | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment