Beispiel #1
0
 protected function beforeCreate()
 {
     if (empty($this->ordering)) {
         $this->ordering = $this->nextOrdering();
     }
     return parent::beforeCreate();
 }
Beispiel #2
0
 protected function beforeValidate()
 {
     if (empty($this->slug)) {
         $this->slug = \Web::instance()->slug($this->namespace);
     }
     return parent::beforeValidate();
 }
Beispiel #3
0
 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();
 }
Beispiel #5
0
 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();
 }
Beispiel #6
0
 public function createIndexes($indexes = null)
 {
     $this->publishableCreateIndexes();
     parent::createIndexes();
 }
Beispiel #7
0
 /**
  * 
  * @param unknown $query
  */
 public static function distinctTags($query = array())
 {
     $query = $query + array('type' => (new static())->type());
     return parent::distinctTags($query);
 }
Beispiel #8
0
 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));
                 }
             }
         }
     }
 }
Beispiel #9
0
 protected function afterUpdate()
 {
     $this->ancestorsAfterUpdate();
     return parent::afterUpdate();
 }
Beispiel #10
0
 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();
 }
Beispiel #11
0
 protected function beforeSave()
 {
     $this->{'stripe.amount'} = (double) $this->{'stripe.amount'};
     return parent::beforeSave();
 }
Beispiel #12
0
 protected function fetchConditions()
 {
     parent::fetchConditions();
     return $this;
 }