0

I am trying to change product price daily according to date

for this I create & fill 31 price type custom attribute like custom_price1 = 100, custom_price2 = 145, custom_price3 = 156

and trying to get custom_price attribute according to date & set respective price
like if date is 2 get custom_price2, if date is 3 get custom_price3

my code is

$currentdate =  Mage::getModel('core/date')->date('d'); 
$newprice = $_product->getCustomPrice . $currentdate();

but getting error

Fatal error: Call to undefined function 21() in ....\default\template\catalog\product\view.phtml on line 64

can anyone help me regarding this
Thanks in advance for help

1 Answer 1

2

It is not valid PHP syntax to type part of a function name then attempt to concat a variable. There are a couple of different solutions, the simplest is probably:

$_product->getData('custom_price'.$currentdate);

I recommend this approach as using getData is more obvious to another dev than using magic methods. You can do it the other way but the syntax needs to be more like:

$_product->{'getCustomPrice' . $currentdate}();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.