更改PHP函数的顺序

发布于 2024-11-17 00:57:50 字数 1276 浏览 0 评论 0原文

我希望更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛起拖把扫天下 2024-11-24 00:57:50

交换它们,然后在下半部分使用 array_merge 。当您交换它们时,第二部分只是分配选项并清除属性部分。这将两者放在一起而不是覆盖:

if (Mage::getStoreConfig('SCP_options/cart/show_custom_options')) {
    $options = array_merge($options, parent::getOptionList();
}

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:

if (Mage::getStoreConfig('SCP_options/cart/show_custom_options')) {
    $options = array_merge($options, parent::getOptionList();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文