Skip to content

Instantly share code, notes, and snippets.

@avoelkl
Last active September 7, 2016 14:51
Show Gist options
  • Save avoelkl/0cacdb354c7c45c6157be44676e825aa to your computer and use it in GitHub Desktop.
Save avoelkl/0cacdb354c7c45c6157be44676e825aa to your computer and use it in GitHub Desktop.
addGroupPriceData() is missing in Mage_Catalog_Model_Resource_Product_Collection
<?php
/**
* Created by PhpStorm.
* User: Anna Völkl <[email protected]>
* Date: 07.09.2016
* Time: 16:01
add this to config.xml
<models>
<catalog_resource>
<rewrite>
<product_collection>Avoe_Catalog_Model_Resource_Catalog_Product_Collection</product_collection>
</rewrite>
</catalog_resource>
</models>
*/
class Avoe_Catalog_Model_Resource_Catalog_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection {
/**
* Add group price data to loaded items
*
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
public function addGroupPriceData()
{
if ($this->getFlag('group_price_added')) {
return $this;
}
$groupPrices = array();
$productIds = array();
foreach ($this->getItems() as $item) {
$productIds[] = $item->getId();
$groupPrices[$item->getId()] = array();
}
if (!$productIds) {
return $this;
}
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
$attribute = $this->getAttribute('group_price');
if ($attribute->isScopeGlobal()) {
$websiteId = 0;
} else if ($this->getStoreId()) {
$websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId();
}
$adapter = $this->getConnection();
$columns = array(
'price_id' => 'value_id',
'website_id' => 'website_id',
'all_groups' => 'all_groups',
'cust_group' => 'customer_group_id',
'price' => 'value',
'product_id' => 'entity_id'
);
$select = $adapter->select()
->from($this->getTable('catalog/product_attribute_group_price'), $columns)
->where('entity_id IN(?)', $productIds)
->order(array('entity_id'));
if ($websiteId == '0') {
$select->where('website_id = ?', $websiteId);
} else {
$select->where('website_id IN(?)', array('0', $websiteId));
}
foreach ($adapter->fetchAll($select) as $row) {
$groupPrices[$row['product_id']][] = array(
'website_id' => $row['website_id'],
'cust_group' => $row['all_groups'] ? Mage_Customer_Model_Group::CUST_GROUP_ALL : $row['cust_group'],
'price' => $row['price'],
'website_price' => $row['price'],
);
}
/* @var $backend Mage_Catalog_Model_Product_Attribute_Backend_Tierprice */
$backend = $attribute->getBackend();
foreach ($this->getItems() as $item) {
$data = $groupPrices[$item->getId()];
if (!empty($data) && $websiteId) {
$data = $backend->preparePriceData($data, $item->getTypeId(), $websiteId);
}
$item->setData('group_price', $data);
}
$this->setFlag('group_price_added', true);
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment