Magento:如何加载产品及其在管理中使用的所有数据

2022-11-06php开发问题
1

本文介绍了Magento:如何加载产品及其在管理中使用的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试获取捆绑选项数据.使用它: $product->getBundleOptionsData 我需要使用它,因为我试图以编程方式更改数据,并且我希望以与 admin 中使用的方式一样接近的方式进行.

I'm trying to get bundle options data. using this : $product->getBundleOptionsData I need to use this, as I'm trying to change data programmatically and I would like to do it in a way that's as close as used in admin .

但是,当我对上述函数的结果进行 var_dump 时,我得到 NULL 而在捆绑模型产品类型的管理端,我得到了正确的数据.

However, when I var_dump the result of the above function I get NULL while in admin side in bundle model product type I get correctly the data.

当我在自己的文件中 var_dump $product 时,我得到的数据比在捆绑模型产品类型保存功能中 var_dump 时短得多.

When I var_dump $product in my own file I get much shorter data than when I var_dump in bundle model product type save function.

我需要做什么来加载产品的所有数据,以便我可以使用getBundleOptionsData.我查看了几个文件并用谷歌搜索,但找不到答案.

what do I need to do to load all data of the product, so I can use getBundleOptionsData. I looked in several files and googled, but can't find an answer.

推荐答案

最后,我成功地获取了捆绑选项数据,以便我可以对其进行操作.我在magento的模型包观察者类duplicateProduct函数中找到了主要代码:但是我需要添加option_id(小心不要忘记)

Finally I made it work to get bundle options data so I can manipulate it. I found the main code in magento's model bundle observer class duplicateProduct function: I needed however to add option_id (careful not to forget that)

这是最后阶段的代码.

$product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
    $product->getTypeInstance(true)->getOptionsIds($product),
    $product
);
$optionCollection->appendSelections($selectionCollection);

$optionRawData = array();
$selectionRawData = array();

$i = 0;
foreach ($optionCollection as $option) {
    $optionRawData[$i] = array(
            'option_id' => $option->getOptionId(), //my addition. important otherwise, options going to be duplicated
            'required' => $option->getData('required'),
            'position' => $option->getData('position'),
            'type' => $option->getData('type'),
            'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
            'delete' => ''
        );
    foreach ($option->getSelections() as $selection) {
        $selectionRawData[$i][] = array(
            'product_id' => $selection->getProductId(),
            'position' => $selection->getPosition(),
            'is_default' => $selection->getIsDefault(),
            'selection_price_type' => $selection->getSelectionPriceType(),
            'selection_price_value' => $selection->getSelectionPriceValue(),
            'selection_qty' => $selection->getSelectionQty(),
            'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
            'delete' => ''
        );
    }
    $i++;
}

$product->setBundleOptionsData($optionRawData);   //changed it to $product
$product->setBundleSelectionsData($selectionRawData);  //changed it to $product

您现在可以更改 optionsrawdata 中的原始数据.或 getBundleOptionsData.另一个也一样.

you can either now change on the raw data in optionsrawdata. or getBundleOptionsData. and same for the other one.

这篇关于Magento:如何加载产品及其在管理中使用的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17