質問

目標:特定の属性を持つ製品のコレクションを取得する

これが試みているものです:

public function Hydrate($attribute)
{
    $this->id = Mage::helper('myHelper')->CamelCase($attribute->getFrontendLabel());
    $this->name = $attribute->getFrontendLabel();

    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->addFieldToFilter($attribute->getAttributeCode(),array('like' => '%%'))
        ->load();

    foreach ($products as $product)
    {
        array_push($this->collection,Mage::getModel('myModels/Json_Product')->Hydrate($product));
    }



    return Mage::helper('myHelper')->ConvertToJson($this);
}
.

仕事が働いています。しかし、私は、AddFieldToFilter()が私が現在見ていないどんな再灌流も持っているのか疑問に思っていましたか?

Magento 1.9.x

役に立ちましたか?

解決

LIKEは最も優しい選択ではありません。%%%と同等)は、文字列、さらには空の文字列でも、フィールドがNOT NULLであるかどうかを確認したいと思っています。

この場合の右側のフィルタパラメータは次のとおりです。

    ->addFieldToFilter($attribute->getAttributeCode(),array('notnull' => true))
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top