Thursday, 22 August 2013

Calculate price based on magento session variable

Calculate price based on magento session variable

I am trying to use Magento as a store for our rental business. Similar to
how price is adjusted with tier pricing, I want to show the price based on
the length of time the customer wants to rent it (the longer you rent it,
the lower the price per month is). Here is how I have tried to make it
work:
Create 'price' attributes to hold price for each 'rental tier'. My
attributes are 'price_1month, price_2months, price_3months', etc. Add to
default attribute set, and update product so that these attributes have
values. DONE
In the header, create a dropdown so customer can choose rental length.
This runs javascript that sets cookie and reloads the page. DONE
Set a magento session variable based off cookie when the page reloads. DONE:
Mage::getSingleton('core/session')->setRentalTier($_COOKIE["rentaltier"]);
In /core/mage/catalog/model/product/type/price.php I have updated
getPrice($product) with the following:
public function getPrice($product) {
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
$rentalPeriod = $session->getRentalTier();
if ($rentalTier == 1) {
$price = $product->getData('price_1month');
}
else if ($rentalTier == 2) {
$price = $product->getData('price_2month');
}
else if ($rentalTier == 3) {
$price = $product->getData('price_3month');
}
return $price;
}
DONE
So, this is working fine on the product page (changing the dropdown WILL
change the price). However, on the catalog it is still showing the system
price attribute. Also, when an item is added to the cart, it shows 0.00.
I thought that getPrice was the root of where price is calculated, but
this is Magento after all.. Anyone have any tips or another angle I can
take at this? Thank you

No comments:

Post a Comment