1

All our prices are managed through an external integration so price increases have to be scheduled.

Example: In January you have an original price of £30 and receive a price increase request that has to start from February (£40). All logic must be build in advance.

How would you approach it?

A possible solution would be to create 2 attributes: increased_price and increased_price_date could be an option but this will require a process to run every day and check if there are product like this with that particular date and then update the current price.

Any other options?

Thanks

Claudiu Creanga
  • 6,247
  • 2
  • 49
  • 88

1 Answers1

1

It depends a lot on how your getting the pricing from your integration supplier and the number of products which you have.

However I recently completed a project which under some circimstances had a price change going on every other minute so it was quite resource intensive. The approach I took there, and which might be sutible for you is to extend the Product Model's getPrice() and connect to redis where you will cache pricing in an simple key value approach.

Example:

    [100 => [
              '01' => 30.00, // January
              '02' => 40.00 // February
            ] 
    ]

Now you can make a connection to this, and return the month for the current price that month.

Extending upon this logic, you can directly query the API provider of your service and return the current price in run time this gives the benefit that your code always returns the price in the suppliers database without ever needing to worry about updating your local price.

public function getPrice()
    {
        if ($this->_redisHelper->isRedisPriceReady($this->getId())) {
            return $this->_redisHelper->getPrice($this->getId());
        }

        $parentPrice = parent::getPrice();

        return $parentPrice;
    }

Above is an example of what I'm doing - checking to see if I have a redis price available (in my case we generate this at run time rather than externally hence the getPrice on the helper - this simply connects and retrieves the relevant price from the structure in redis.) That section you would replace with either an API call to the supplier, or a middle man query depending on your needs.

John Cuthbert
  • 2,366
  • 13
  • 28
  • yes, thanks for that, a direct query seems to be the best option although it slows the loading page – Claudiu Creanga Jan 14 '16 at 10:21
  • @Claudiu if it is a slow network or computationally complex query it will do. That is essentially why we stored it in Redis - pretty fast. You can of course query externally from the page and update Redis and query as described above. – John Cuthbert Jan 14 '16 at 10:22