예제 #1
0
 protected function beforeSave()
 {
     if (empty($this->token)) {
         $mongo_id = (string) new \MongoId();
         $this->token = md5($mongo_id . time());
     }
     return parent::beforeSave();
 }
예제 #2
0
 /**
  * 
  */
 protected function beforeSave()
 {
     if (!is_a($this, '\\Shop\\Models\\CustomerAddresses')) {
         $this->setError('Addresses can only be saved as CustomerAddresses');
     }
     if (empty($this->user_id)) {
         $this->setError('Addresses must have an associated customer');
     }
     return parent::beforeSave();
 }
예제 #3
0
 protected function beforeSave()
 {
     $this->credit_issued_to_user = (bool) $this->credit_issued_to_user;
     $this->amount = (double) $this->amount;
     $this->balance_before = (double) $this->balance_before;
     $this->balance_after = (double) $this->balance_after;
     $this->user_id = new \MongoId((string) $this->user_id);
     if (!empty($this->order_id)) {
         $this->order_id = new \MongoId((string) $this->order_id);
     }
     return parent::beforeSave();
 }
예제 #4
0
 protected function beforeSave()
 {
     if (!empty($this->tags) && !is_array($this->tags)) {
         $this->tags = trim($this->tags);
         if (!empty($this->tags)) {
             $this->tags = array_map(function ($el) {
                 return strtolower($el);
             }, \Base::instance()->split((string) $this->tags));
         }
     } elseif (empty($this->tags) && !is_array($this->tags)) {
         $this->tags = array();
     }
     return parent::beforeSave();
 }
예제 #5
0
 protected function beforeSave()
 {
     // Loop through all the actions and calculate the amount of this commission
     $this->amount = 0;
     foreach ($this->actions as $action) {
         if (!empty($action['amount'])) {
             $this->amount += $action['amount'];
         }
     }
     $this->issued = (bool) $this->issued;
     $this->amount = (double) $this->amount;
     $this->balance_before = (double) $this->balance_before;
     $this->balance_after = (double) $this->balance_after;
     $this->affiliate_id = new \MongoId((string) $this->affiliate_id);
     if (!empty($this->referral_id)) {
         $this->referral_id = new \MongoId((string) $this->referral_id);
     }
     if (!empty($this->shop_order_id)) {
         $this->shop_order_id = new \MongoId((string) $this->shop_order_id);
     }
     return parent::beforeSave();
 }
예제 #6
0
 protected function beforeSave()
 {
     if (empty($this->type)) {
         $this->type = $this->__type;
     }
     if (empty($this->parent) || $this->parent == "null") {
         $this->parent = null;
     } else {
         $this->parent = new \MongoId((string) $this->parent);
     }
     $this->path = $this->generatePath($this->slug, $this->parent);
     if (empty($this->ancestors) && !empty($this->parent)) {
         $parent_title = null;
         $parent_slug = null;
         $parent_path = null;
         $parent_ancestors = array();
         $parent = $this->emptyState()->setState('filter.id', $this->parent)->getItem();
         if (!empty($parent->title)) {
             $parent_title = $parent->title;
         }
         if (!empty($parent->slug)) {
             $parent_slug = $parent->slug;
         }
         if (!empty($parent->path)) {
             $parent_path = $parent->path;
         }
         if (!empty($parent->ancestors)) {
             $parent_ancestors = $parent->ancestors;
         }
         $this->ancestors = $parent_ancestors;
         $this->ancestors[] = array('id' => $this->parent, 'slug' => $parent_slug, 'title' => $parent_title);
     }
     if (empty($this->parent) || $this->parent == "null") {
         $this->ancestors = array();
     }
     return parent::beforeSave();
 }
예제 #7
0
파일: Nested.php 프로젝트: dioscouri/f3-lib
 /**
  * beforeCreate is triggered before beforeSave,
  * and we ONLY want this to happen if all validations have passed
  */
 protected function beforeSave()
 {
     $this->tree = new \MongoId((string) $this->tree);
     if (empty($this->parent)) {
         $this->parent = new \MongoId((string) $this->tree);
     } elseif (!empty($this->parent)) {
         // is it a MongoId?
         $regex = '/^[0-9a-z]{24}$/';
         if (preg_match($regex, (string) $this->parent)) {
             $this->parent = new \MongoId((string) $this->parent);
         } else {
             $this->parent = null;
         }
     } else {
         $this->parent = null;
     }
     if (isset($this->published)) {
         $this->published = (bool) $this->published;
     }
     // this is an insert
     if (!empty($this->__isCreate)) {
         // allow plugin events to halt operation BEFORE making any changes to collection
         $return = parent::beforeSave();
         $parent = new static();
         if (empty($this->parent) && empty($this->is_root)) {
             $root = $this->getRoot($this->tree);
             $this->parent = $root->id;
             $parent->load(array('_id' => new \MongoId((string) $this->parent)));
         } elseif (!empty($this->parent)) {
             $parent->load(array('_id' => new \MongoId((string) $this->parent)));
         }
         if ($parent->hasDescendants()) {
             $rgt = $parent->rgt;
             // UPDATE nested_category SET rgt = rgt + 2 WHERE rgt >= @myRight;
             $result = $this->collection()->update(array('rgt' => array('$gte' => $rgt), 'tree' => $this->tree), array('$inc' => array('rgt' => 2)), array('multiple' => true));
             // UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;
             $result = $this->collection()->update(array('lft' => array('$gt' => $rgt), 'tree' => $this->tree), array('$inc' => array('lft' => 2)), array('multiple' => true));
             // INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES', @myRight, @myRight + 1);
             $this->lft = $rgt;
             $this->rgt = $rgt + 1;
         } elseif (!empty($parent->lft)) {
             // SELECT @myLeft := lft FROM nested_category
             $lft = $parent->lft;
             // UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myLeft;
             $result = $this->collection()->update(array('rgt' => array('$gt' => $lft), 'tree' => $this->tree), array('$inc' => array('rgt' => 2)), array('multiple' => true));
             // UPDATE nested_category SET lft = lft + 2 WHERE lft > @myLeft;
             $result = $this->collection()->update(array('lft' => array('$gt' => $lft), 'tree' => $this->tree), array('$inc' => array('lft' => 2)), array('multiple' => true));
             // INSERT INTO nested_category(name, lft, rgt) VALUES('FRS', @myLeft + 1, @myLeft + 2);
             $this->lft = $lft + 1;
             $this->rgt = $lft + 2;
         } else {
             $this->lft = 1;
             $this->rgt = 2;
         }
     } else {
         $return = parent::beforeSave();
     }
     return $return;
 }
예제 #8
0
 protected function beforeSave()
 {
     $this->items_count = count($this->items);
     return parent::beforeSave();
 }
예제 #9
0
파일: Carts.php 프로젝트: dioscouri/f3-shop
 /**
  * Compare the items and shipping from the previously-saved cart.  
  * If they've changed, clear the tax calculations. 
  */
 protected function beforeSave()
 {
     if (!empty($this->id)) {
         // If a cart is updated, recalculate coupon values and tax value
         $cart = (new static())->load(array('_id' => new \MongoId((string) $this->id)));
         // Compare items, coupons, shipping address, and shipping method.
         // If changed, empty the taxes
         // and update coupon & giftcard values
         if ($cart->items != $this->items || $cart->quantity() != $this->quantity() || $cart->coupons != $this->coupons || $cart->auto_coupons != $this->auto_coupons || $cart->giftcards != $this->giftcards || $cart->shippingMethod() != $this->shippingMethod() || $cart->{'checkout.shipping_address'} != $this->{'checkout.shipping_address'} || $cart->{'checkout.billing_address'} != $this->{'checkout.billing_address'}) {
             $this->taxes = array();
             foreach ((array) $this->coupons as $key => $item) {
                 if (!empty($item['usage_automatic'])) {
                     unset($this->coupons[$key]);
                     continue;
                 }
                 // ensure that the coupon is still valid, removing it if not
                 // and set its value to 0
                 try {
                     $coupon = (new \Shop\Models\Coupons())->bind($item)->reload();
                     $coupon->cartValid($this);
                     $this->{'coupons.' . $key . '.amount'} = 0;
                 } catch (\Exception $e) {
                     \Dsc\System::addMessage('Removing coupon: ' . $this->coupons[$key]['code'], 'error');
                     \Dsc\System::addMessage((string) $e->getMessage(), 'error');
                     unset($this->coupons[$key]);
                 }
             }
             $this->coupons = array_values(array_filter($this->coupons));
             // now get all the coupon values
             foreach ((array) $this->coupons as $key => $item) {
                 $this->{'coupons.' . $key . '.cart_totals_before_calculating_coupon_value'} = $this->totals();
                 $this->{'coupons.' . $key . '.amount'} = $this->calcCouponValue($item);
             }
             // now that user coupons have been validated, ensure the autoCoupons
             $this->ensureAutoCoupons();
             foreach ((array) $this->giftcards as $key => $item) {
                 $this->{'giftcards.' . $key . '.amount'} = $this->calcGiftCardValue($item);
             }
         }
     }
     // if there is a user_id, delete the session_id
     if (!empty($this->user_id)) {
         $this->session_id = null;
         $this->user_email = $this->user()->email;
     }
     $this->quantity = $this->quantity();
     $this->items_count = count($this->items);
     return parent::beforeSave();
 }
예제 #10
0
 protected function beforeSave()
 {
     return parent::beforeSave();
 }
예제 #11
0
 protected function beforeSave()
 {
     $this->orderingBeforeSave();
     return parent::beforeSave();
 }
예제 #12
0
 public function beforeSave()
 {
     if (isset($this->url) && is_array($this->url)) {
         $this->url['alias'] = $this->inputFilter()->clean($this->url['alias'], 'string');
         $this->url['redirect'] = $this->inputFilter()->clean($this->url['redirect'], 'string');
     } else {
         $this->setError('Missing information about redirection');
     }
     if (strpos($this->{'url.alias'}, '/') === 0) {
         $this->{'url.alias'} = substr($this->{'url.alias'}, 1);
     }
     if (strpos($this->{'url.redirect'}, '/') === 0) {
         $this->{'url.redirect'} = substr($this->{'url.redirect'}, 1);
     }
     return parent::beforeSave();
 }
예제 #13
0
 protected function beforeSave()
 {
     $this->publishableBeforeSave();
     $this->description = strip_tags(str_replace('\\n', '<br>', $this->description), '<br><p>');
     $this->images = array_values(array_filter($this->images));
     $this->rating = (double) $this->rating;
     return parent::beforeSave();
 }