Exemplo n.º 1
0
 /**
  * Retrieve the dynamic parameters from discount.
  * Customer group, Site, Date from and Date to
  * If false is returned - discount can't be applied
  *
  * @param array $discount
  * @return array
  */
 protected function _getDiscountRules(array $discount)
 {
     $rules = array();
     $rulesMapping = array('group' => 'customer_group_id', 'site' => 'site_id', 'from_date' => 'time_from', 'to_date' => 'time_to');
     foreach ($rulesMapping as $discountKey => $ruleKey) {
         if (!isset($discount[$discountKey])) {
             switch ($ruleKey) {
                 case 'customer_group_id':
                     $rules[$ruleKey] = $this->getProductData('customer_group_ids');
                     break;
                 case 'site_id':
                     $rules[$ruleKey] = $this->getProductData('site_ids');
                     break;
                 case 'time_from':
                     $rules[$ruleKey] = array(Axis_Date::now()->getDate()->getTimestamp());
                     break;
                 case 'time_to':
                     $rules[$ruleKey] = array(Axis_Date::now()->getDate()->addYear(5)->getTimestamp());
                     break;
             }
             continue;
         }
         if (!is_array($discount[$discountKey])) {
             // time_from and time_to filters
             $date = new Axis_Date($discount[$discountKey], 'yyyy-MM-dd');
             if ('time_to' === $ruleKey) {
                 $date->set('23:59:59', Zend_Date::TIMES);
             }
             $discount[$discountKey] = array($date->getTimestamp());
         }
         if ('customer_group_id' === $ruleKey) {
             if (in_array(0, $discount[$discountKey])) {
                 // All groups value support
                 $customerGroupIds = $this->getProductData('customer_group_ids');
             } else {
                 $customerGroupIds = array_intersect($discount[$discountKey], $this->getProductData('customer_group_ids'));
             }
             $rules[$ruleKey] = $customerGroupIds;
         } else {
             $rules[$ruleKey] = $discount[$discountKey];
         }
     }
     return $rules;
 }