magento 获取产品变型

xurqigkl  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(146)

我创建了一个模块,使用json结构将产品发送到另一个服务器,如下所示

{
name: "Black Nolita Cami",
code: "877",
sku: "wbk002c",
price: "150.0000",
sale_price: "wbk002c",
discount: "",
quantity: "0.0000",
weight: null,
url: "black-nolita-cami.html"}

但是我有另一个字段变量,我已经把所有的产品变量都放进去了。我该怎么做呢?

ippsafx7

ippsafx71#

这可能会让你朝着正确的方向开始...

$productSku = "ABCDE";
$product = Mage::getModel('catalog/product');
$productId = $product->getIdBySku( $productSku );
$product->load($productId);

/**
 * In Magento Models or database schema level, the product's Custom Options are
 * executed & maintained as only "options". So, when checking whether any product has
 * Custom Options or not, we should check by using this method "hasOptions()" only.
 */
if($product->hasOptions()) {
    echo '<pre>';

    foreach ($product->getOptions() as $o) {
        $optionType = $o->getType();
        echo 'Type = '.$optionType;

        if ($optionType == 'drop_down') {
            $values = $o->getValues();

            foreach ($values as $k => $v) {
                print_r($v);
            }
        }
        else {
            print_r($o);
        }
    }

    echo '</pre>';
}

相关问题