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();

For doing this I have store code as below

$storeCode = "abc";

I have to use dynamic as below


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



$storeCode = ucfirst("abc");

$function = "getDeliveryCutoffTime".$storeCode;

  • Sorry to say that I tried this and its not working – Butterfly Oct 28 '15 at 11:25
  • ok try print_r($customer->getData()); and see if you are getting value for DeliveryCutoffTime or not – Akhilesh Patel Oct 28 '15 at 11:26
  • yes I am getting it and if use $customer->getDeliveryCutoffTimeAbc(); I am getting the value too – Butterfly Oct 28 '15 at 11:27
  • strange,it should work. can you post here your complete code file? – Akhilesh Patel Oct 28 '15 at 11:30
  • really sorry to say its working, I formed function name as $functionName = 'getDeliveryLeadTime'.$storeCode.'()'; and called like $cutOffTime = $customer->$functionName – Butterfly Oct 28 '15 at 11:39

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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