Beispiel #1
0
 protected function beforeSave()
 {
     $this->publishableBeforeSave();
     $this->ancestorsBeforeSave();
     $this->rule_min_spent = (double) $this->rule_min_spent;
     return parent::beforeSave();
 }
 protected function beforeSave()
 {
     //$this->amount = (float) $this->amount;
     foreach ($this->items as $key => $item) {
         if (empty($item['description']) && empty($item['quantity']) && empty($item['rate'])) {
             unset($this->items[$key]);
         }
     }
     $this->items = array_values($this->items);
     return parent::beforeSave();
 }
Beispiel #3
0
 protected function beforeSave()
 {
     $this->publishableBeforeSave();
     return parent::beforeSave();
 }
Beispiel #4
0
 protected function beforeSave()
 {
     if (!empty($this->products) && !is_array($this->products)) {
         $this->products = trim($this->products);
         if (!empty($this->products)) {
             $this->products = \Base::instance()->split((string) $this->products);
         }
     } elseif (empty($this->products) && !is_array($this->products)) {
         $this->products = array();
     }
     $this->__update_products_ordering = false;
     if ($this->sort_by == 'ordering-asc') {
         if (!empty($this->id)) {
             // check what it was before
             $this->__old = (new static())->load(array('_id' => new \MongoId((string) $this->id)));
             if ($this->__old->sort_by != $this->sort_by) {
                 $this->__update_products_ordering = true;
             }
         } else {
             $this->__update_products_ordering = true;
         }
     }
     $this->publishableBeforeSave();
     return parent::beforeSave();
 }
Beispiel #5
0
 protected function beforeSave()
 {
     if (empty($this->type)) {
         $this->type = $this->__type;
     }
     if (empty($this->md5)) {
         if (!empty($this->{'s3.ETag'})) {
             $this->md5 = str_replace('"', '', $this->{'s3.ETag'});
         } elseif (!empty($this->filename) && file_exists($this->filename)) {
             $this->md5 = md5_file($this->filename);
         } else {
             $this->md5 = md5($this->slug);
         }
     }
     return parent::beforeSave();
 }
Beispiel #6
0
 protected function beforeSave()
 {
     // convert the code to lowercase
     $this->code = strtolower($this->code);
     $this->discount_value = (double) $this->discount_value;
     if (!empty($this->discount_target_products) && !is_array($this->discount_target_products)) {
         $this->discount_target_products = trim($this->discount_target_products);
         if (!empty($this->discount_target_products)) {
             $this->discount_target_products = \Base::instance()->split((string) $this->discount_target_products);
         }
     } elseif (empty($this->discount_target_products) && !is_array($this->discount_target_products)) {
         $this->discount_target_products = array();
     }
     if (!empty($this->discount_target_shipping_methods) && !is_array($this->discount_target_shipping_methods)) {
         $this->discount_target_shipping_methods = trim($this->discount_target_shipping_methods);
         if (!empty($this->discount_target_shipping_methods)) {
             $this->discount_target_shipping_methods = \Base::instance()->split((string) $this->discount_target_shipping_methods);
         }
     } elseif (empty($this->discount_target_shipping_methods) && !is_array($this->discount_target_shipping_methods)) {
         $this->discount_target_shipping_methods = array();
     }
     if (!empty($this->required_products) && !is_array($this->required_products)) {
         $this->required_products = trim($this->required_products);
         if (!empty($this->required_products)) {
             $this->required_products = \Base::instance()->split((string) $this->required_products);
         }
     } elseif (empty($this->required_products) && !is_array($this->required_products)) {
         $this->required_products = array();
     }
     if (!empty($this->required_coupons) && !is_array($this->required_coupons)) {
         $this->required_coupons = trim($this->required_coupons);
         if (!empty($this->required_coupons)) {
             $this->required_coupons = \Base::instance()->split((string) $this->required_coupons);
         }
     } elseif (empty($this->required_coupons) && !is_array($this->required_coupons)) {
         $this->required_coupons = array();
     }
     if (!empty($this->geo_countries) && !is_array($this->geo_countries)) {
         $this->geo_countries = trim($this->geo_countries);
         if (!empty($this->geo_countries)) {
             $this->geo_countries = \Base::instance()->split((string) $this->geo_countries);
         }
     } elseif (empty($this->geo_countries) && !is_array($this->geo_countries)) {
         $this->geo_countries = array();
     }
     if (!empty($this->geo_regions) && !is_array($this->geo_regions)) {
         $this->geo_regions = trim($this->geo_regions);
         if (!empty($this->geo_regions)) {
             $this->geo_regions = explode(",", (string) $this->geo_regions);
         }
     } elseif (empty($this->geo_regions) && !is_array($this->geo_regions)) {
         $this->geo_regions = array();
     }
     if (!empty($this->groups) && is_array($this->groups)) {
         $groups = array();
         $this->groups = array_values($this->groups);
         foreach ($this->groups as $group) {
             if (!empty($group)) {
                 $groups[] = $group;
             }
         }
         $this->set('groups', $groups);
     }
     $this->publishableBeforeSave();
     $this->forSelectionBeforeValidate('required_collections');
     $this->forSelectionBeforeValidate('excluded_products');
     $this->forSelectionBeforeValidate('excluded_collections');
     $this->forSelectionBeforeValidate('discount_target_collections');
     return parent::beforeSave();
 }
Beispiel #7
0
 protected function beforeSave()
 {
     $this->{'stripe.amount'} = (double) $this->{'stripe.amount'};
     return parent::beforeSave();
 }