/** * Get a page by its slug. * * @param string $slug The slug to check for * @param boolean $checkHistory True to check through historical slug data * * @return Page|false Prepared `Page` instance, or false if not found */ public function getBySlug($slug, $checkHistory = true) { if ($slug == '/') { return $this->getHomepage(); } // Clean up the slug $path = trim($slug, '/'); // Turn it into an array and reverse it. $parts = array_reverse(explode('/', $path)); $base = array_shift($parts); $this->_buildQuery(); // Loop thorough the parts of the url and build joins in order to get // all the parent slugs so we can build the full slug because we do not // store the full slug in the db for ($i = 2; $i <= count($parts) + 1; $i++) { $level = 'level' . $i; $upperLevel = $i === 2 ? 'page' : 'level' . ($i - 1); $this->_queryBuilder->join($level, $level . '.position_left < ' . $upperLevel . '.position_left AND ' . $level . '.position_right > ' . $upperLevel . '.position_right', 'page')->where($level . '.slug = ?s', [$parts[$i - 2]]); if ($this->_loadDeleted) { $this->_queryBuilder->where($level . '.deleted_at IS NULL'); } } $this->_queryBuilder->where('page.slug = ?s', [$base])->where('page.position_depth = ?i', [count($parts)]); $pages = $this->_loadPages(); if ($pages) { return $pages; } if ($checkHistory && ($page = $this->checkSlugHistory($slug))) { return $this->_returnAsArray ? [$page] : $page; } return false; }
/** * {@inheritDoc} */ protected function _applyFilter(QueryBuilderInterface $queryBuilder) { if (empty($this->_value)) { return; } $units = $this->_unitLoader->getSaleUnits(); array_walk($units, function (&$unit) { $unit = $unit->id; }); $queryBuilder->join('product_page_unit_record', 'product_page_unit_record.page_id = page.page_id')->where('product_page_unit_record.unit_id IN (?ji)', [$units]); }