7

別のシステムのMagento-APIを介して構成可能な製品をエクスポート/インポートしたいと考えています。私たちにとって重要なのは、3色(赤、緑、青)のTシャツのような構成可能な製品の価値です。

次の関数で構成可能な属性を受け取ります。

public function options($productId, $store = null, $identifierType = null)
{
    $product = $this->_getProduct($productId, $store, $identifierType);

    if (!$product->getId()) {
        $this->_fault('not_exists');
    }

    $configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();

    $result = array();
    foreach($configurableAttributeCollection as $attribute){
        $result[$attribute->getProductAttribute()->getAttributeCode()] = $attribute->getProductAttribute()->getFrontend()->getLabel();
        //Attr-Code:    $attribute->getProductAttribute()->getAttributeCode()
        //Attr-Label:   $attribute->getProductAttribute()->getFrontend()->getLabel()
        //Attr-Id:      $attribute->getProductAttribute()->getId()
    }


    return $result;
}

しかし、上記の関数で取得した構成可能属性から、現在使用可能なラベル/ IDを使用して、その製品で使用されているオプション(構成可能属性が「色」の場合は青、緑、赤)を取得するにはどうすればよいでしょうか。

答えは大歓迎です!

ティム

4

2 に答える 2

7

より良い解決策を見つけることができなかったので、これは私が思いついたものです:

public function options($productId, $store = null, $identifierType = null)
{
    $_product = $this->_getProduct($productId, $store, $identifierType);

    if (!$_product->getId()) {
        $this->_fault('not_exists');
    }

    //Load all simple products
    $products = array();
    $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
    foreach ($allProducts as $product) {
        if ($product->isSaleable()) {
            $products[] = $product;
        } else {
            $products[] = $product;
        }
    }

    //Load all used configurable attributes
    $configurableAttributeCollection = $_product->getTypeInstance()->getConfigurableAttributes();

    $result = array();
    //Get combinations
    foreach ($products as $product) {
        $items = array();
        foreach($configurableAttributeCollection as $attribute) {
            $attrValue = $product->getResource()->getAttribute($attribute->getProductAttribute()->getAttributeCode())->getFrontend();
            $attrCode = $attribute->getProductAttribute()->getAttributeCode();
            $value = $attrValue->getValue($product);
            $items[$attrCode] = $value[0];
        }
        $result[] = $items;
    }

    return $result;
}

これが誰かに役立つことを願っています。

于 2011-07-05T06:55:13.003 に答える
1

質問を理解していると100%確信していません...特定の製品の構成可能なオプションの値とラベルが必要であると仮定すると、これは機能すると思います(バージョン1.4.0.1でテスト済み)

public function options($productId, $store = null, $identifierType = null)
{
    $product = $this->_getProduct($productId, $store, $identifierType);

    if (!$product->getId()) {
        $this->_fault('not_exists');
    }

    $configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();

    $result = array();
    foreach($configurableAttributeCollection as $attribute){
        $result[$attribute->getProductAttribute()->getAttributeCode()] = array(
                $attribute->getProductAttribute()->getFrontend()->getLabel() => $attribute->getProductAttribute()->getSource()->getAllOptions()
        );
        //Attr-Code:    $attribute->getProductAttribute()->getAttributeCode()
        //Attr-Label:   $attribute->getProductAttribute()->getFrontend()->getLabel()
        //Attr-Id:      $attribute->getProductAttribute()->getId()
    }


    return $result;
}

ここでも、探しているものが正確にはわかり$attribute->getProductAttribute()->getSource()->getAllOptions()ませんが、関数によって、使用可能なオプションのラベルと値がわかりました。

お役に立てれば。そうでなければ、私が誤解したところを教えてください。ありがとう!

于 2011-06-30T00:27:04.187 に答える