如何将产品选择的自定义选项 Sku 字段发送到 Magento 中的购物车页面

发布于 2024-10-31 15:44:34 字数 2027 浏览 0 评论 0原文

我正在处理一个场景,我想发送在购物车页面中选择的产品自定义选项 SKU 已创建在自定义选项的情况下发送到购物车的数组。

这是一个名为 getProductOptions() 的函数,其中创建产品选项数组并将其发送到购物车。此时,我想将选定的自定义选项 SKU 字段发送到购物车。

我有以下代码:

public function getProductOptions()
{
    $options = array();
    if ($optionIds = $this->getItem()->getOptionByCode('option_ids')) {
        $options = array();
        foreach (explode(',', $optionIds->getValue()) as $optionId) {
            if ($option = $this->getProduct()->getOptionById($optionId)) {

//echo $optionId;   
                echo "hhhhhhhhhhhhh";
//print_r( $option->getId());
//echo Mage::getModel('catalog/product')->getOptionSku($option);
//die();
//print_r( $option->getOptionSku());
//echo Mage_Catalog_Model_Product_Option_Type_Select::getOptionSku());

                $quoteItemOption = $this->getItem()->getOptionByCode('option_' . $option->getId());
//echo $option->getQuoteItemOption($quoteItemOption);
                $group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setQuoteItemOption($quoteItemOption);
                $options[] = array(
                    'label' => $option->getTitle(),
                    'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
                    'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
                    'option_id' => $option->getId(),
                    'option_type' => $option->getType(),
                    'custom_view' => $group->isCustomizedView(),
                    'option_sku'=>//What should i call here to send Selected option SKU to this Array
                );
            }
        }    
        if ($addOptions = $this->getItem()->getOptionByCode('additional_options')) {
            $options = array_merge($options, unserialize($addOptions->getValue()));
        }
    }
    return $options;
}

I am working in a scenario I want to send Product selected Custom Option SKU in cart page have founded the array which is sent to cart in case of custom options.

Here is a Function called getProductOptions() in which Product Option Array is created and sent to cart. At this point, I want to send selected Custom Option SKU field to cart.

I have the following code:

public function getProductOptions()
{
    $options = array();
    if ($optionIds = $this->getItem()->getOptionByCode('option_ids')) {
        $options = array();
        foreach (explode(',', $optionIds->getValue()) as $optionId) {
            if ($option = $this->getProduct()->getOptionById($optionId)) {

//echo $optionId;   
                echo "hhhhhhhhhhhhh";
//print_r( $option->getId());
//echo Mage::getModel('catalog/product')->getOptionSku($option);
//die();
//print_r( $option->getOptionSku());
//echo Mage_Catalog_Model_Product_Option_Type_Select::getOptionSku());

                $quoteItemOption = $this->getItem()->getOptionByCode('option_' . $option->getId());
//echo $option->getQuoteItemOption($quoteItemOption);
                $group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setQuoteItemOption($quoteItemOption);
                $options[] = array(
                    'label' => $option->getTitle(),
                    'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
                    'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
                    'option_id' => $option->getId(),
                    'option_type' => $option->getType(),
                    'custom_view' => $group->isCustomizedView(),
                    'option_sku'=>//What should i call here to send Selected option SKU to this Array
                );
            }
        }    
        if ($addOptions = $this->getItem()->getOptionByCode('additional_options')) {
            $options = array_merge($options, unserialize($addOptions->getValue()));
        }
    }
    return $options;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我偏爱纯白色 2024-11-07 15:44:34

看来你缺少的是

'option_sku' => $this->getItem()->getSku()

It looks like the bit you're missing is

'option_sku' => $this->getItem()->getSku()
预谋 2024-11-07 15:44:34

不要修改块本身,只需更改呈现的模板以添加此字段。从 $_item 变量中获取数据,并将其回显给用户。这应该不需要对块进行任何修改。

Don't modify the block itself, just change the rendered template to add a for this field. Grab the data from the $_item variable, and echo it out to the user. That should require no modifications of the block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文