ProductRepository::getBySlug PHP Method

getBySlug() public method

public getBySlug ( $slug, array $with = ['producer', 'type.typeAttributes', 'images', 'category', 'variants', 'attributesValues'] ) : mixed
$slug
$with array
return mixed
    public function getBySlug($slug, array $with = ['producer', 'type.typeAttributes', 'images', 'category', 'variants', 'attributesValues'])
    {
        return Product::model()->published()->with($with)->find('t.slug = :slug', [':slug' => $slug]);
    }

Usage Example

Example #1
0
 /**
  * @param $name
  * @throws CHttpException
  */
 public function actionView($name)
 {
     $product = $this->productRepository->getBySlug($name);
     if (null === $product) {
         throw new CHttpException(404, Yii::t('StoreModule.catalog', 'Product was not found!'));
     }
     $this->render('view', ['product' => $product]);
 }
All Usage Examples Of ProductRepository::getBySlug