Как получить параметры настраиваемого атрибута в Magento?

мы хотим экспортировать/импортировать настраиваемые продукты через Magento-API в другую систему. Для нас важны значения настраиваемых продуктов, таких как футболка, которая имеет 3 цвета (красный, зеленый и синий).

Мы получаем настраиваемые атрибуты со следующей функцией:

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;
}

Но как можно получить параметры, используемые в этом продукте (например, синий, зеленый, красный, если настраиваемым атрибутом является «цвет») с уже доступной меткой/идентификатором из настраиваемого атрибута, который мы получили с помощью вышеуказанной функции?

Ответы очень ценятся!

Тим


person Tim    schedule 04.01.2011    source источник
comment
Вопрос не ясен. Что вы подразумеваете под получением используемых значений в этом продукте с уже доступным ярлыком/идентификатором?   -  person Andrey Tserkus    schedule 04.01.2011
comment
Мы хотим получить такие параметры, как красный, синий и зеленый (если настраиваемым атрибутом является цвет). И с помощью указанной выше функции мы получаем информацию об используемых настраиваемых атрибутах.   -  person Tim    schedule 05.01.2011
comment
Итак, вам нужны варианты цвета для данного продукта [красный, зеленый, синий]?   -  person Jared Farrish    schedule 29.06.2011


Ответы (2)


Так как мы не смогли найти лучшего решения, вот что я придумал:

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;
}

Надеюсь, это поможет кому-нибудь.

person Tim    schedule 05.07.2011

Я не уверен на 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() дала мне метку и значение доступных опций.

Надеюсь это поможет. если нет, позвольте мне, где я неправильно понял. Спасибо!

person sbditto85    schedule 30.06.2011
comment
Спасибо. Я попробую и вернусь к вашему ответу! - person Tim; 01.07.2011