Hello !!

I am asking a question on sfShop project, but I also post a message here
because I think that my question is also general and can apply to any
symfony application (or other frameworks)

I use a great symfony application called sfShop to make an e-commerce site
... But I want to use a feature that is not available in sfShop : I want to
be able to change the price of a product according to "price campaigns".
The principle is :  The price of the product is the "normal" price unless a
price campaign is active, That is to say the current date is between the
beginning date and the end date of the price campaign in that case the price
is determine by the campaign itself.

My problem/Question is to handle this in the front application :

The different front views :  "product list", "product detail", "shopping
cart" must show the product price of the current active campaign (if any)
for a given product and not the "normal" product price ... am I clear ?

I have implement this using symfony events ...I have register an event
called 'ama.filter_product_campagne'

$this->dispatcher->connect('ama.filter_product_campagne',
array('amaEventsListener', 'filterProductForCampagne'));

And I added a method to Product class:

    public function applyCampagneFilter(){
     sfContext::getInstance()->getEventDispatcher()->notify(new
sfEvent($this, 'ama.filter_product_campagne', array()));
    }

I don't know if this is the "best way" to do this (the advantage I see by
doing this is that that I can easily unregister the event listener to ignore
campaign) but my problem is not exactly here ....

The real problem is that, as I said, the products must be filter wherever
they appear on the front :

Product list,
Product details,
Shopping cart,
...

To do this I have override the corresponding methods of the Peer object :

  public static function doSelectWithTranslation(Criteria $c, $culture =
null, $con = null)
  {
   $results = parent::doSelectWithTranslation($c, $culture, $con);
   foreach ($results as $result){
   $result->applyCampagneFilter();
   }
   return $results;
  }
  public static function doSelect(Criteria $criteria, PropelPDO $con = null)
  {
   $results = parent::doSelect($criteria, $con);
   foreach ($results as $result){
   $result->applyCampagneFilter();
   }
   return $results;
  }
  public static function retrieveById($id, $criteria = null, $withI18n =
false)
  {
   $object = parent::retrieveById($id, $criteria, $withI18n);
   $object->applyCampagneFilter();
   return $object;
  }



It works but I feel something wrong about that ... So I wonder if their is
not a proper way to do all this ...
It feel unnatural to me to override multiple methods as shown above (but I
don't kown how to to that in a proper way (more object oriented ?? /
decoupled way ??)) and Do I have to use event notification, event filter ,
other someting else that events ... ???

Thanks for your help, suggestion, ideas ... :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to