我有一个Magento网站,有四家商店。对于每个客户,每个商店将分配不同的截止时间。

用户一次只能从一个商店添加产品。当用户来签出页面时,我必须得到他添加产品的商店的截止时间。

我设法得到商店代码。

商店截止时间的客户属性如下

`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

根据添加到购物车的产品,我得到了商店代码是否是它的abcdef 或者是这样。

现在我必须从customer对象中获取值,如下所示

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

为此,我有存储代码如下

$storeCode = "abc";

我必须使用动态如下

$customer->getDeliveryCutoffTime.$storeCode();

它没有得到价值。我怎样才能使它充满活力?

有帮助吗?

解决方案

尝试

$storeCode = ucfirst("abc");

$function = "getDeliveryCutoffTime".$storeCode;

$customer->$function();
.

其他提示

在PHP中,这也可以这样做:

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

这些Magento"魔术"getter方法调用该方法 getData() 最终。所以 getDeliveryCutoffTimeAbc() 将导致调用 getData("delivery_cutoff_time_abc").

所以你也可以马上打电话:

$storeCode = "abc";
$customer->getData("delivery_cutoff_time_" . $storeCode);
许可以下: CC-BY-SA归因
scroll top