protected function beforeCreate() { if (empty($this->ordering)) { $this->ordering = $this->nextOrdering(); } return parent::beforeCreate(); }
protected function beforeValidate() { if (empty($this->slug)) { $this->slug = \Web::instance()->slug($this->namespace); } return parent::beforeValidate(); }
protected function beforeValidate() { if (empty($this->slug)) { $this->slug = \Web::instance()->slug($this->namespace); } // TODO Put this in beforeSave, to ensure that the slug is clean //$this->slug = \Web::instance()->slug( $this->slug ); return parent::beforeValidate(); }
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(); }
protected function beforeUpdate() { // TODO if this item has changed its title, update products afterUpdate() /* $old = $this->load(array('_id' => $this->_id )); if ($old->parent != $this->parent || $old->title != $this->title) { // update children after save $this->__options['update_children'] = true; } */ return parent::beforeUpdate(); }
public function createIndexes($indexes = null) { $this->publishableCreateIndexes(); parent::createIndexes(); }
/** * * @param unknown $query */ public static function distinctTags($query = array()) { $query = $query + array('type' => (new static())->type()); return parent::distinctTags($query); }
protected function afterSave() { parent::afterSave(); if (!empty($this->__update_products_ordering)) { // $to_update = find all products in this collection that dont have an ordering value for this collection // if there are some, // get a count of all products in this collection, set $start = count to push them to the end // loop though $to_update and set their ordering value = $start + $key $conditions = \Shop\Models\Collections::getProductQueryConditions($this->id); $conditions['collections.' . $this->id . '.ordering'] = null; $to_update = \Shop\Models\Products::collection()->distinct('_id', $conditions); if (!empty($to_update)) { $collection_id = (string) $this->id; unset($conditions['collections.' . $this->id . '.ordering']); $count = \Shop\Models\Products::collection()->count($conditions); foreach ($to_update as $key => $product_id) { $ordering = $count + $key; $product = (new \Shop\Models\Products())->setState('filter.id', (string) $product_id)->getItem(); if (!empty($product->id)) { $product->update(array('collections.' . $collection_id . '.ordering' => (int) $ordering), array('overwrite' => false)); } } } } }
protected function afterUpdate() { $this->ancestorsAfterUpdate(); return parent::afterUpdate(); }
protected function afterDelete() { try { if ($this->storage == 'gridfs') { $collChunkName = $this->collectionNameGridFS() . ".chunks"; $collChunks = $this->getDb()->{$collChunkName}; $collChunks->remove(['files_id' => $this->_id]); } $doc = (new \Dsc\Mongo\Collections\Trash())->setCondition('document._id', $this->_id)->getItem(); $doc->remove(); } catch (\Exception $e) { //restore item from trash $doc = (new \Dsc\Mongo\Collections\Trash())->setCondition('document._id', $this->_id)->getItem(); if (!empty($doc)) { $doc->restore(); } } parent::afterDelete(); }
protected function beforeSave() { $this->{'stripe.amount'} = (double) $this->{'stripe.amount'}; return parent::beforeSave(); }
protected function fetchConditions() { parent::fetchConditions(); return $this; }