Добавление групповых цен в коллекции товаров


Существует ли способ добавления групповых цен (для одной или нескольких групп клиентов) в коллекции товаров?

На самом деле у меня есть это...

/** @var Mage_Catalog_Model_Resource_Product_Collection $products */
$products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeTo ...

if ($groupId) {
    $products->joinTable(
        array('group_price_'.$groupId => 'catalog/product_attribute_group_price'),
        'entity_id = entity_id',
        array('group_price_'.$groupId => 'group_price_'.$groupId.'.value'),
        array('customer_group_id' => $groupId)
    );
}

Это работает, и я могу получить групповую цену с помощью $product->getData('group_price_X'), но есть ли что-то встроенное?

Author: sv3n, 2018-07-05

2 answers

Более дешевые цены (как это может быть концептуально групповая цена, за пользовательскую группу) должны быть объединены при вызове addMinimalPrice()

public function addMinimalPrice()
{
    return $this->addPriceData();
}

И так...

public function addPriceData($customerGroupId = null, $websiteId = null)
{
    $this->_productLimitationFilters['use_price_index'] = true;

    if (!isset($this->_productLimitationFilters['customer_group_id']) && is_null($customerGroupId)) {
        $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    }
    if (!isset($this->_productLimitationFilters['website_id']) && is_null($websiteId)) {
        $websiteId       = Mage::app()->getStore($this->getStoreId())->getWebsiteId();
    }

    if (!is_null($customerGroupId)) {
        $this->_productLimitationFilters['customer_group_id'] = $customerGroupId;
    }
    if (!is_null($websiteId)) {
        $this->_productLimitationFilters['website_id'] = $websiteId;
    }

    $this->_applyProductLimitations();

    return $this;
}

Однако, если вам нужно получить все возможные групповые цены (не заботясь о том, являются ли они наилучшей возможной ценой), то я думаю, что нет встроенного метода лучше, чем ваш подход

 1
Author: Raul Sanchez, 2018-07-05 18:43:05

Не добавлено в коллекцию, но тоже работает...:)

Вы можете получить определенную групповую цену с помощью этого:

/** @var Mage_Catalog_Model_Product $product */
foreach ($products as $product) {
    var_dump($product->setCustomerGroupId($groupId)->getGroupPrice());
}

Чтобы получить все групповые цены:

/** @var Mage_Catalog_Model_Product $product */
foreach ($products as $product) {
    $product->getGroupPrice();
    var_dump($product->getData('group_price'));
}

Или:

/** @var Mage_Catalog_Model_Product $product */
foreach ($products as $product) {
    $product->getResource()->getAttribute('group_price')->getBackend()->afterLoad($product);
    var_dump($product->getData('group_price'));
}
 0
Author: sv3n, 2018-07-07 12:51:54