2011-01-04 11 views
7

हम किसी अन्य सिस्टम में Magento-API के माध्यम से कॉन्फ़िगर करने योग्य उत्पादों को निर्यात/आयात करना चाहते हैं। हमारे लिए महत्वपूर्ण क्या है, टी-शर्ट जैसे विन्यास योग्य उत्पादों के मूल्य हैं जिनमें 3 रंग (लाल, हरा और नीला) है।Magento में कॉन्फ़िगर करने योग्य विशेषता के विकल्प कैसे प्राप्त करें?

हम निम्नलिखित समारोह के साथ विन्यास गुण प्राप्त करते हैं:

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

लेकिन कैसे यह विकल्प है कि उत्पाद में इस्तेमाल किया पाने के लिए संभव है (ईए नीले, हरे, लाल, यदि कॉन्फ़िगर करने योग्य विशेषता "रंग" है) कॉन्फ़िगर करने योग्य विशेषता से अब उपलब्ध लेबल/आईडी के साथ जो हमें उपरोक्त फ़ंक्शन के माध्यम से मिला है?

उत्तर की बहुत सराहना की जाती है!

टिम

+0

प्रश्न स्पष्ट नहीं है। इसका मतलब क्या है "अब उपलब्ध लेबल/आईडी के साथ उस उत्पाद में प्रयुक्त मूल्य प्राप्त करें? –

+0

हम लाल, नीले और हरे रंग के विकल्प प्राप्त करना चाहते हैं (यदि कॉन्फ़िगर करने योग्य विशेषता" रंग "है) और उपर्युक्त के साथ मज़बूत हमें प्रयुक्त कॉन्फ़िगर करने योग्य विशेषताओं के बारे में जानकारी प्राप्त होती है। – Tim

+0

तो क्या आप किसी दिए गए उत्पाद [लाल, हरे, नीले] के लिए "रंग विकल्प" चाहते हैं? –

उत्तर

7

जब से हम एक बेहतर समाधान नहीं मिल सकता है, यह है कि क्या मैं के साथ आया है।

+3

इस समारोह में पहला foreach पाश थोड़ा अनावश्यक लगता है ... –

1

मुझे लगता है मैं यह काम (संस्करण 1.4 पर परीक्षण किया जाएगा कल्पना नहीं 100% यकीन है कि मैं सवाल समझ में ... यह सोचते हैं आप विशेष उत्पाद के लिए विन्यास विकल्प के लिए मूल्यों और लेबल चाहते हैं रहा हूँ। 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() समारोह मुझे उपलब्ध विकल्पों में लेबल और मूल्य दे दी है।

उम्मीद है कि इससे मदद मिलती है। यदि नहीं, तो मुझे कहां गलत समझा। धन्यवाद!

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

आशा इस किसी को भी मदद करता है:

+0

धन्यवाद। मैं इसे आज़मा दूंगा और आपके उत्तर पर वापस आऊंगा! – Tim

संबंधित मुद्दे