タグ付けされた質問 「collection-filtering」

4
同じID「xxx」がすでに存在する「Item(Mage_Catalog_Model_Product)」を修正するにはどうすればよいですか?
製品コレクションをフィルタリングしようとすると、このエラーが発生しました Item (Mage_Catalog_Model_Product) with the same id "6058" already exist Magento内に同じIDを持つ(表示される)製品は1つしか存在しないため、エラーの原因を尋ねる必要がありました。 この重複を削除するためにクリアする必要があるテーブルはありますか?

3
LIKEを使用した結果のフィルタリング
次の3つの「haystack」文字列を考えてください。 a) foo bar b) welcome to foo bar industries c) foo barer そして今、私の「針」: foo bar (ヘー) フィルターを、干し草の山の文字列aとbに一致させますが、cは一致させません。私が試してみました: $collection->addAttributeToFilter('name', array('like' => '%'.$needle.'%')); しかし、上記はcと一致します。 私も試しました: $collection->addAttributeToFilter('name', array('like' => '% '.$needle.' %')); // Note the spaces 上記はbとのみ一致します。 どんな助けも大歓迎です。

2
コレクションでグループ句を使用するとグリッドのページネーションが機能しない
私は製品グリッドで作業していますが、ページ付けまたは製品数が機能していません(間違った数が表示されているため)。私のブロックの_preparecollection関数は次のとおりです。コレクションにカテゴリフィルターコードを追加したので、同じidが既に存在する場合のエラーを防ぐためにグループ句を使用する必要があります。 protected function _prepareCollection() { $store = $this->_getStore(); $collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('sku') ->addAttributeToSelect('name') ->addAttributeToSelect('attribute_set_id') ->addAttributeToSelect('type_id') ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left'); $collection->addAttributeToFilter('category_id', array('in' => array(4,10))) ->distinct(true); $collection->getSelect()->group('e.entity_id'); if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); } $collection->joinField('position', 'catalog/category_product', 'position', 'product_id=entity_id', null, 'left'); $collection->joinField('websites', 'catalog/product_website', 'website_id', 'product_id=entity_id', null, 'left'); if …

2
発送可能な注文の集まりを取得するにはどうすればよいですか?
まだ発送されていない、または一部発送されている注文が必要です。以下のコードを使用して、出荷可能な注文を取得しています。 foreach ($orderIds as $orderId) { $order = Mage::getModel('sales/order')->load($orderId); if ($order->canShip()) { echo "Shipping Pending"; } } しかし、私はforeachを使いたくありません。以下のようなものが必要です。 Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('status','can_ship');

1
フラットカタログを有効にすると、カテゴリコレクションをフィルタリングすると不正な動作が発生する
カテゴリの基本的な検索を実行するためのコードがあります。カテゴリ名と説明を検索することで機能します-両方がコアである属性。 私が持っているコードは次のとおりです: $_categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('description') ->addAttributeToSelect('associated_brand') ->addAttributeToSelect('image') ->setPageSize(12) ->setCurPage(1) ->addAttributeToFilter('level',['gt' => 2]) ->addAttributeToFilter('is_active',['eq'=>true]) ->addAttributeToFilter( [ ['attribute' => 'name', 'like' => '%'.$searchterm.'%'], ['attribute' => 'description', 'like' => '%'.$searchterm.'%'] ] )->load(); カテゴリに対してフラットカタログを有効にする前に、期待される結果(名前または説明が検索語と一致するカテゴリ)が返されました。 フラットカタログを有効にすると、名前または説明の検索が機能しません。基になるコレクションクエリを出力すると、次のようになります。 SELECT `main_table`.`entity_id`, `main_table`.`level`, `main_table`.`path`, `main_table`.`position`, `main_table`.`is_active`, `main_table`.`is_anchor`, `main_table`.`name`, `main_table`.`description`, `main_table`.`associated_brand`, `main_table`.`image` FROM `catalog_category_flat_store_1` AS `main_table` WHERE (level …

3
在庫のある製品のみを含む製品コレクションを取得する
これには簡単な答えがあるかもしれませんが、私はそれを見つけることができません。有効になっているが在庫がない商品を除いて、商品コレクションを取得しようとしています。 次の方法を試しましたが、これによりエラーが発生します。 $productIds = array('3','4','9'); $productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect( array('name', 'image', 'price') ) ->addIdFilter($productIds) ; $this->_productCollection = Mage::getSingleton('cataloginventory/stock') ->addInStockFilterToCollection( $productCollection ) ; 次のエラーが発生します。 PHP Fatal error: Call to a member function getTypeInstance() on a non-object in app/code/core/Mage/Catalog/Block/Product/Abstract.php on line 117 app / code / core / Mage / Catalog / …

2
製品コレクション内の別の属性で製品コレクションをフィルタリング(例: 'attribX'、array( 'gt' => 'attrib-Y')
このような製品コレクションを使用する場合: $_productCollection= Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('special_price', array('neq'=>'')); 別の属性に関連する属性でaddAttributeToFilterを使用することは可能ですか?例:価格よりも高いspecial_priceを次のようにフィルタリングできますか $_productCollection= Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('special_price', array('gt'=>'price'));
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.