2

I've created two product custom attribute to let admin se a starting and ending date for all group price, to let magento calculate correctly the group price only inside the date rage I've override the function getGroupPrice($product) inside the class Mage_Catalog_Model_Product_Type_Price like follow:

public function getGroupPrice($product)
    {

        $groupPrices = $product->getData('group_price');

        if (is_null($groupPrices)) {
            $attribute = $product->getResource()->getAttribute('group_price');
            if ($attribute) {
                $attribute->getBackend()->afterLoad($product);
                $groupPrices = $product->getData('group_price');
            }
        }

        if (is_null($groupPrices) || !is_array($groupPrices)) {
            return $product->getPrice();
        }

        $customerGroup = $this->_getCustomerGroupId($product);

        $matchedPrice = $product->getPrice();

        // retrive group price data range 
        $group_price_from = $product->getData('group_price_from');
        $group_price_to = $product->getData('group_price_to');
        $paymentDate = date('Y-m-d');
        $paymentDate=date('Y-m-d', strtotime($paymentDate));


        foreach ($groupPrices as $groupPrice) {
            if ($groupPrice['cust_group'] == $customerGroup && $groupPrice['website_price'] < $matchedPrice) {
                if (($paymentDate > $group_price_from) && (($paymentDate < $group_price_to)||($group_price_to == null)))
            {
                $matchedPrice = $groupPrice['website_price'];
            };
                break;
            }
        }

        return $matchedPrice;
    }

Now it work greatly inside the product page so that group price is applied ONLY inside the date range... but it doesn't work in all other position: in cart, inside category page and listing product new... they are displayng the gruop price independently of the data range...

Probably I've missed something ore changed the wrong function.

0

The best solution is to get the product collection whenever retrieved and modify the data. To do so you have to use an observer.

etc/config.xml

...
<global>
....
 <events>
  ....
   <catalog_product_collection_load_after>
      <observers>
        <[your_module]>
           <class>[your_module]/observer</class>
           <method>collectionLoadAfter</method>
        </[your_module]>
     </observers>
  </catalog_product_collection_load_after>
 ...
 </events>
....
</global>

and then in your Model/observer.php add

public function collectionLoadAfter($observer)
{
  foreach($observer->getCollection() as $_item) {
     // $original_price = $_item->getData('price');//to get the original price

     //do your logic here
     $price = 100;//set your custom price 

     $_item->setPrice($price);//this will update the collection

     return $this;
}

Note: dont forget to replace [your_module] by your module name.

Now go to the front end and check the price.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.