1

I’m kind of stuck with a module I’m currently writing.

The client wants to use a third party pricing supply (web service) for existing customers (when they’re logged in). Currently I’ve got the pricing for the product page overloaded and for general collections but the one I’m struggling to get to work is the layered navigation pricing.

The minimal price and final price are calculated in the query itself which means I can’t simply modify it.

I’ve tracked it all back to the prepareProductCollection() method in the Mage_Catalog_Model_Layer model and ideally, if I could simply loop through the collection, get the correct pricing for each product and then write them back to the collection it ‘should’ do what I need it to. However, If I do this in the way that you’d normally do it in an observer (there are no events dispatched around this method from what I can tell) then it doesn’t update the collection how I’d expect.

Original Method:

 public function prepareProductCollection($collection)
{
    $collection
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addUrlRewrite($this->getCurrentCategory()->getId());

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    return $this;
} 

Modified Method that currently isn’t working quite right (explicitly setting the prices for now):

 public function prepareProductCollection($collection)
{
    $collection
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addUrlRewrite($this->getCurrentCategory()->getId());

   foreach($collection as $product) {
        $product->setMinimalPrice("13.5");
        $product->setFinalPrice("13.5");
        $product->setMinPrice("13.5");        
    }  

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    return $this;
} 

Any ideas or alternative solutions to carry out the pricing change globally in one place would be greatly appreciated.

2 Answers 2

1

I actually figured out a workaround for this. As there was a requirement for the pricing to be done on a live basis (calling a 3rd party server for the price every time the product was shown on screen) I figured this would actually be a huge overhead and wasn't happy with it. It meant asking the third party to provide an additional import file with the current sale pricing for each account code against each SKU.

What I did was the following:

  1. Create a custom module for a CRON job to work against.
  2. In the observer loop through the records in the file and create a customer group for each account code.
  3. Once you have a customer group you can then create a catalog pricing rule for each SKU based on the sale pricing from the file.

For completeness I wiped all pricing rules based on the name I was giving them so they're identifiable. This prevents rules acting on customer groups that have been removed from the import file.

Obviously this doesn't create true live pricing but a once or twice a day upload of pricing (which runs in a matter of seconds) isn't out of the question. And is a very unobtrusive way of handling it.

I'm happy for people to offer suggestions on how this could be made better etc.

2
  • if you are happy with this as an answer the feel free to accept it Commented May 20, 2014 at 18:41
  • You have Advanced Pricing by Innoexts - although heard there are stability problems with it due to changing core - and Magento Dynamic Pricing which is a realtime pricing solution based on supplier price and calculates cogs, margins, etc. but is enterprise grade ie. expensive. The only other solution is the one you have done - data uploads.
    – user2935
    Commented Jul 30, 2014 at 10:02
0

My advice is to write a script or import module which runs through all products and update prices, save products in database, and then runs re index. This should fix all your problems. The disadvantage is that you will lose your old prices. But you can save them somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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