Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

mail_open
Use Magento opConfig.reloadPrice() with jQuery and Custom options
COM TOKEY

New
March 12, 2015 - 10:52 am
Member Since: February 6, 2015
Forum Posts: 3
sp_UserOfflineSmall Offline

I am trying to use the Magento reloadPrice() with jQuery to refresh the price. I have a configurable product with custom options. In the Magento Admin the price of custom options is 0, but I have calculated price to add because each custom option has special tierprices (tierprices are saved in a special table DECORATION in MySQL). Without jQuery, the SELECT code for the option is :

<select id="select_281" class=" required-entry product-custom-option" title="" name="options[281]" onchange="opConfig.reloadPrice()">
<option value="0"></option>
<option rel="1" price="0" value="275"></option>
<option rel="2" price="0" value="276"></option>
</select>

With jQuery I remove the Prototype onchange code and try to calculate the price for my option (say $50) :

jQuery(‘#select_281’).removeAttr(‘onchange’).chang e(function(){
//Price of the option (calculated based on custom tierprices
//in MySQL DECORATION table) to add to a basic price of the conf product

price = 50;
optionsPrice.changePrice(‘opConfig’, price);
optionsPrice.reload();
});

Price of the configurable product: $150.
Add an option (SELECT): we add $50.

The new price $200 is displayed in the product page, But not in the cart page : the cart page displays just $150 which is not correct.

Someone can help?

Best regards, COM.

Avatar
Dave Furness

Founder
March 15, 2015 - 12:00 am
Member Since: July 19, 2013
Forum Posts: 4606
sp_UserOfflineSmall Offline

Hey Com,

Wow this is a tricky one, and a little too codey for me. I will Skype Matt now and ask him to take a look at this for you.

Dave

Every expert was once a beginner

COM TOKEY

New
March 19, 2015 - 4:40 pm
Member Since: February 6, 2015
Forum Posts: 3
sp_UserOfflineSmall Offline

Hi,

The reloadPrice() cant change any price serverside.
So we solved this issue by using 2 observers : checkout_cart_product_add_after observer to change the price the first time the product is added to the cart, and checkout_cart_update_items_after observer to change the price for each item in the cart (when user click the “Modify cart” button on cart page).

The code here. Code tested for configurable products with 2 custom options numberOfColors and engravingType. For each couple numberOfColors/engravingType we have tierprices stored in special MySQL table, we may change price with a custom price. Each simple product has its tierPrices.

//checkout_cart_product_add_after observer
public function modifyPrice(Varien_Event_Observer $observer)
{
$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$productType = $product->getTypeID();
$price = 100;//Unit price of product without engraving, 100 for example

//Unit price with engraving, depending of 2 custom options of configurable product
if($productType == ‘configurable’){
//get custom options of config here
.
.
$engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
$finalUnitPrice = $price + $engravingPrice;//Final custom price

//Modify the price
$item->setCustomPrice($finalUnitPrice);
$item->setOriginalCustomPrice($finalUnitPrice);
$item->getProduct()->setIsSuperMode(true);
}
}

//checkout_cart_update_items_after observer
public function modifyCartItems(Varien_Event_Observer $observer)
{
foreach ($observer->getCart()->getQuote()->getAllVisibleItems() as $item ) {
if ($item->getParentItem()) {$item = $item->getParentItem();}
$productType = $product->getTypeID();
$productType = $product->getTypeID();
$price = 100;//Unit price of product without engraving

//Unit price with engraving, depending of 2 custom options of configurable product
if($productType == ‘configurable’){
.
.
$engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
$finalUnitPrice = $price + $engravingPrice;//Final custom price

//Modify the price for the item
$item->setCustomPrice($finalUnitPrice);
$item->setOriginalCustomPrice($finalUnitPrice);
$item->getProduct()->setIsSuperMode(true);
}
}
}

But…..one problem remains : on the cart page, when user clicks the link “Edit” to edit the product in product page so he can change quantity, …and click the “Update cart” button, this update button does not read the checkout_cart_product_add_after to refresh price.

Dont’t know how to force this “Update cart” action to process the code in checkout_cart_product_add_after observer? Is this code executed just the first time the product is added to the cart?

Thanks.

Tokey

 

Why Should You Join UnderstandingE?

 
  • Access to over 500 step-by-step video tutorials
  • +20 video courses available
  • Magento, M2E Pro, Magmi, eBay, Amazon & Design all covered
  • Everything is in 100% Plain English
  • Learn how to build your own multi-channel software for eBay & Amazon
  • Access to the community forums, meet fellow business owners like yourself

Join Now with 2 Clicks

 

Join now for less that £1 per day you can gain access to over 400 step-by-step video tutorials & learn how to build your very own multi-channel software.

 

Forum Timezone: Europe/London

Most Users Ever Online: 1012

Currently Online:
25 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Jim @ Moogento: 688

Steve Froggatt: 514

Badeth - UE: 513

Jimbob: 453

Paul Cartwright: 414

Forum Stats:

Groups: 6

Forums: 37

Topics: 5221

Posts: 27486

Administrators: Matthew Ogborne: 4565, Dave Furness: 4606