Question

I have a Magento website with four stores. For each customer different cut off time will be assigned for each store.

User is restricted to add product from only one store at a time. When user come to check out page I have to get the cut off time for the store from which he added the product.

I managed to get the store code.

Customer attributes for store cut off time are as below

`delivery_cutoff_time_abc` // here abc is the store code
`delivery_cutoff_time_def` // here def is the store code
`delivery_cutoff_time_ghi` // here ghi is the store code
`delivery_cutoff_time_jkl` // here jkl is the store code

Based on products added to cart I got the Store code whether it itsabc or def or so.

Now I have to get the value from customer object as below

$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getDeliveryCutoffTimeAbc();

For doing this I have store code as below

$storeCode = "abc";

I have to use dynamic as below

$customer->getDeliveryCutoffTime.$storeCode();

It doesn't get the value. How may I make it dynamic?

Was it helpful?

Solution

Try

$storeCode = ucfirst("abc");

$function = "getDeliveryCutoffTime".$storeCode;

$customer->$function();

OTHER TIPS

In PHP, this can also be done like this:

$storeCode = "abc";
$customer->{"getDeliveryCutoffTime" . ucfirst($storeCode)}();

These Magento "magic" getter methods call the method getData() eventually. So getDeliveryCutoffTimeAbc() will result in a call to getData("delivery_cutoff_time_abc").

So you could also call this right away:

$storeCode = "abc";
$customer->getData("delivery_cutoff_time_" . $storeCode);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top