2

group_price製品レベルでセットがあり、特定の顧客グループに割り当てられている製品で製品リストをフィルタリングしようとしています。

私はそれが次のようなものになると考えていました:

$products->addFieldToFilter('group_price', array(
        array(
            'cust_group' => 2
        )
    ));

しかし、それgroup_priceは属性ではないようです。さらに、$_product->getGroupPrice()商品にグループ価格が設定されているかどうかに関係なく、常に商品の価格を返します。

理想的には、グループ ID ではなく、顧客グループ コード (つまり、卸売、小売など) でこれらをフィルター処理することをお勧めします (単純に、誰かが顧客グループを削除して後で再作成し、ID が変更される可能性がある場合)。

何かご意見は?

4

2 に答える 2

1

同様の要件がありますが、問題は、大規模な製品コレクションを反復処理するのが遅すぎることです。

テーブルにはグループ情報が含まれているため、次のcatalog_product_index_priceようなものを試すことができます。

$productCollection = Mage::getModel('catalog/product')->getCollection();
...
$productCollection->addFinalPrice();
$productCollection->getSelect()->where(
    'price_index.customer_group_id = ? AND price_index.group_price IS NOT NULL',
    $customer_group_id
);
于 2015-11-29T14:10:34.163 に答える
0

私はこれを使用することになりました:

    $products = Mage::getModel('catalog/product')->getResourceCollection();
    $products
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('visibility', array('neq' => 1));

    foreach ($products as $product => $value) {

        //still not sure how to get 'group_price' without running load() =(
        $productModel = Mage::getModel('catalog/product')->load($value->getId());
        $groupPrices = $productModel->getData('group_price');

        // A helper of mine
        // store the customer's groupId to compare against available group prices array below.
        $currentGroupId = Mage::helper('user')->getCustomerGroup()->getId();

        // remove products w/o configured group prices
        if (!count($groupPrices)) {
            $products->removeItemByKey($product);
        }
        foreach ($groupPrices as $key) {
            foreach ($key as $subkey => $value) {
                if ($subkey == "cust_group") {
                    $customerGroup = $subkey;
                    if ($value != $currentGroupId) {
                        $products->removeItemByKey($product);
                    }
                }
            }
        }
    };


    $this->_productCollection = $products;
    return $this->_productCollection;
于 2013-01-12T05:34:06.250 に答える