Exemplo n.º 1
0
 /**
  * Add a "promotion" filter:
  *
  * 	array('promotion' => 'promocode_giftcard')
  *
  * This will return only items that are "promotion_promocode_giftcard" models.
  * Can be an array too.
  *
  * @param  Model_Brand_Purchase $brand_purchase
  * @param  Jam_Event_Data       $data
  * @param  array                $items
  * @param  array                $filter
  */
 public function filter_promotion_items(Model_Brand_Purchase $brand_purchase, Jam_Event_Data $data, array $items, array $filter)
 {
     $items = is_array($data->return) ? $data->return : $items;
     $filtered = array();
     foreach ($items as $item) {
         if (array_key_exists('promotion', $filter)) {
             if (!Jam_Behavior_Promotable_Brand_Purchase::purchase_item_is_promotion($item, $filter['promotion'])) {
                 continue;
             }
         }
         if (array_key_exists('not_promotion', $filter)) {
             if (Jam_Behavior_Promotable_Brand_Purchase::purchase_item_is_promotion($item, $filter['not_promotion'])) {
                 continue;
             }
         }
         $filtered[] = $item;
     }
     $data->return = $filtered;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider data_purchase_item_is_promotion
  * @covers Jam_Behavior_Promotable_Brand_Purchase::purchase_item_is_promotion
  */
 public function test_purchase_item_is_promotion($reference_model, $promotion, $expected)
 {
     $item = Jam::build('purchase_item_promotion', array('reference_model' => $reference_model));
     $this->assertEquals($expected, Jam_Behavior_Promotable_Brand_Purchase::purchase_item_is_promotion($item, $promotion));
 }