更改PHP函数的顺序
我希望更改 Magento 购物车中列表的排列顺序。
我们有以下编码:
public function getOptionList()
{
$options = false;
if (Mage::getStoreConfig('SCP_options/cart/show_custom_options')) {
$options = parent::getOptionList();
}
if (Mage::getStoreConfig('SCP_options/cart/show_config_product_options')) {
if ($this->getConfigurableProductParentId()) {
$attributes = $this->getConfigurableProductParent()
->getTypeInstance()
->getUsedProductAttributes();
foreach($attributes as $attribute) {
$options[] = array(
'label' => $attribute->getFrontendLabel(),
'value' => $this->getProduct()->getAttributeText($attribute->getAttributeCode()),
'option_id' => $attribute->getId(),
);
}
}
}
return $options;
}
显示以下内容: http://awesomescreenshot.com/053ffeie9
我们正在寻找交换属性和选项结束,以便属性显示在项目的顶部。
在编码中,我们已经确定顶部 if 语句用于选项,底部 if 语句用于属性,因此理论上它应该只是交换它们的情况......不幸的是,它看起来并不那么简单那。
如果我们交换它们,属性不会显示,但选项会显示。
有人能够推荐任何可以尝试的东西吗,因为我们在尝试对此进行排序时感到非常沮丧。
I am looking to change the order in which a list is being brought together in our Magento cart.
We have the following coding:
public function getOptionList()
{
$options = false;
if (Mage::getStoreConfig('SCP_options/cart/show_custom_options')) {
$options = parent::getOptionList();
}
if (Mage::getStoreConfig('SCP_options/cart/show_config_product_options')) {
if ($this->getConfigurableProductParentId()) {
$attributes = $this->getConfigurableProductParent()
->getTypeInstance()
->getUsedProductAttributes();
foreach($attributes as $attribute) {
$options[] = array(
'label' => $attribute->getFrontendLabel(),
'value' => $this->getProduct()->getAttributeText($attribute->getAttributeCode()),
'option_id' => $attribute->getId(),
);
}
}
}
return $options;
}
Which displays the following: http://awesomescreenshot.com/053ffeie9
We are looking to swap the Attributes and Options over so the Attributes display at the top of the item.
In the coding we've established that the top if statement is for options and the bottom if statement is for the attributes, so theory being it should just be a case of swapping them over... unfortunately it doesn't seem as simple as that.
If we swap them the attributes don't show but the options do.
Would someone be able to recommend anything to try as we're getting very frustrated trying to sort this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
交换它们,然后在下半部分使用 array_merge 。当您交换它们时,第二部分只是分配选项并清除属性部分。这将两者放在一起而不是覆盖:
swap them and then use array_merge on the bottom half. When you swap them, the second part was just assigning options and wiping out the attributes part. This puts the two together instead of overwriting: