سؤال

أحاول تحميل منتجات افتراضية محددة بخياراتها المخصصة ، ولكن بدلا من ذلك أستمر في الحصول على مصفوفة فارغة.

السمة الخاصة بي هي 'جزء _ معرف' في مجموعة السمات 'جزء القارب' إنها سمة من النوع المنسدل مع عدة خيارات.الخيار الذي أحاول سحبه هو 'نظرة'.

هنا هو رمز بلدي:

$attribute = 'msh_boat_part_identifier';

$boatLookProducts = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter($attribute, array('like'=>'Look'))
    ->load()
    ->getItems();

foreach($boatLookProducts as $boatLookProduct)
{
    $return[] = array(
        "id" => (int)$boatLookProduct->getEntityId(),
        "name" => $boatLookProduct->getName(),
        "type" => "profile",
        "shortDesc" => $boatLookProduct->getShortDescription(),
        "desc" => $boatLookProduct->getDescription(),
        "active" => ($boatLookProduct->getStatus() === "2" ? false : true)
    );
}
echo Mage::helper('pb')->ConvertToJson($return);

في الاستعلام الخاص بي للمجموعة ، إذا قمت بتغيير المصفوفة إلى

->addAttributeToFilter($attribute, array('like'=>'%%'))

وسوف يعود بنجاح جميع بروروكتس ، ولكن لا أستطيع الحصول على واحد محدد أريد!

هل كانت مفيدة؟

المحلول

كما part_identifier هي سمة قائمة منسدلة ، لا يمكنك تصفية المجموعة حسب تسمية الخيار.

لتصفية مجموعة بواسطة خيار، تحتاج إلى الحصول على معرف تسمية الخيار (قيمة الخيار الفعلية).

ثم يمكنك تصفية المجموعة حسب معرف الخيار هذا:

// use your own attribute code here 
$attributeCode = 'your_attribute_here';
$attributeOption = 'Look';

$attributeDetails = Mage::getSingleton('eav/config')
    ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$options = $attributeDetails->getSource()->getAllOptions(false); 
$selectedOptionId = false;
foreach ($options as $option){ 
    // print_r($option) and find all the elements 
    echo $option['value']; 
    echo $option['label'];
    if ($option['label'] == $attributeOption) {
        $selectedOptionId = $option['value'];   
    }
}

if ($selectedOptionId) {
    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter($attributeCode, array('eq' => $selectedOptionId))
}

نصائح أخرى

هذا متأخرا وربما غير صالحة في وقت السؤال، على الرغم من أنني وجدت طريقة أكثر إيجازا عن طريق القيام:

giveacodicetagpre.

ثم تستخدمه في مرشح التجميع كالمعتاد

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top