/** * * @param \Claremontdesign\Ecommerce\Model\Category $category * @param type $columns * @param type $filters * @param type $sort * @param type $joins * @param type $paginate * @param type $options * @param type $debug * @return Collection of Model */ public function byNestedSet(ModelCategory $node, $columns = ['*'], $filters = [], $sort = [], $joins = [], $paginate = [], $options = [], $debug = false, $notIn = false) { if (!empty($filters[$this->_categoryPrimaryKey()])) { unset($filters[$this->_categoryPrimaryKey()]); } if ($notIn) { return $this->getAll($columns, $filters, $sort, $joins, $paginate, $options, $debug); } $nodeIds = $node->getDescendantsAndSelf()->lists(cd_config('database.e.productCategory.table.primary')); $columns = [$this->_table() . '.*', $this->_pivotTable() . '.position', $this->_pivotTable() . '.' . cd_config('database.e.product.table.primary') . ' as pivot_item_id', $this->_pivotTable() . '.' . cd_config('database.e.productCategory.table.primary') . ' as pivot_category_id']; //if($this->repo->getModel() instanceof \Claremontdesign\Cdbase\Repository\Contracts\PositionableInterface) //{ // $sort = [$this->_pivotTable() . '.position' => 'ASC']; //} $joins = []; $joins[] = ['model' => $this->_pivotTable() . ' as ' . $this->_pivotTable(), 'foreign_key' => $this->_pivotTable() . '.' . $this->_primaryKey(), 'local_key' => $this->_table() . '.' . $this->_primaryKey()]; $joins[] = ['model' => $this->_categoryTable() . ' as ' . $this->_categoryTable(), 'foreign_key' => $this->_categoryTable() . '.' . $this->_categoryPrimaryKey(), 'local_key' => $this->_pivotTable() . '.' . $this->_categoryPrimaryKey()]; $filters[$this->_pivotTable() . '.' . $this->_categoryPrimaryKey()] = ['in' => ['field' => $this->_pivotTable() . '.' . $this->_categoryPrimaryKey(), 'values' => collect($nodeIds)->all()]]; return $this->_casts($this->repo->setDebug($debug)->getAll($columns, $filters, $sort, $joins, $paginate, $options)); }