Browse Source

[Administration] Gestion des accessoires

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
1ecdb52521
25 changed files with 493 additions and 17 deletions
  1. +31
    -11
      backend/controllers/AccessoryController.php
  2. +15
    -0
      backend/views/accessory/_form.php
  3. +1
    -0
      backend/views/accessory/create.php
  4. +13
    -1
      backend/views/accessory/index.php
  5. +1
    -0
      backend/views/accessory/update.php
  6. +0
    -2
      backend/views/product/_form.php
  7. +6
    -0
      backend/web/css/screen.css
  8. +11
    -0
      backend/web/sass/accessory/_form.scss
  9. +1
    -0
      backend/web/sass/screen.scss
  10. +1
    -0
      common/components/BusinessLogic.php
  11. +6
    -0
      common/components/BusinessLogicTrait.php
  12. +31
    -0
      console/migrations/m240620_074924_create_table_product_accessory.php
  13. +26
    -0
      domain/Product/Accessory/Accessory.php
  14. +18
    -0
      domain/Product/Accessory/AccessoryBuilder.php
  15. +20
    -0
      domain/Product/Accessory/AccessoryManager.php
  16. +7
    -0
      domain/Product/Accessory/AccessoryRepository.php
  17. +22
    -0
      domain/Product/Product/ProductManager.php
  18. +9
    -3
      domain/Product/Product/ProductModule.php
  19. +86
    -0
      domain/Product/ProductAccessory/ProductAccessory.php
  20. +15
    -0
      domain/Product/ProductAccessory/ProductAccessoryBuilder.php
  21. +13
    -0
      domain/Product/ProductAccessory/ProductAccessoryDefinition.php
  22. +51
    -0
      domain/Product/ProductAccessory/ProductAccessoryManager.php
  23. +38
    -0
      domain/Product/ProductAccessory/ProductAccessoryModule.php
  24. +42
    -0
      domain/Product/ProductAccessory/ProductAccessoryRepository.php
  25. +29
    -0
      domain/Product/ProductAccessory/ProductAccessoryRepositoryQuery.php

+ 31
- 11
backend/controllers/AccessoryController.php View File



public function actionIndex() public function actionIndex()
{ {
$accessoryModule = $this->getAccessoryModule();

return $this->render('index', [ return $this->render('index', [
'searchModel' => $accessoryModule->getBuilder()->instanciateAccessory($this->getProducerCurrent()),
'dataProvider' => $accessoryModule->getRepository()->queryAll()->getDataProvider(20),
'dataProvider' => $this->getAccessoryModule()->getRepository()
->queryAccessories()->getDataProvider(20),
]); ]);
} }


public function actionCreate() public function actionCreate()
{ {
$accessoryModule = $this->getAccessoryModule(); $accessoryModule = $this->getAccessoryModule();
$accessory = $accessoryModule->getBuilder()->instanciateAccessory($this->getProducerCurrent());
$accessoryModel = $accessoryModule->getBuilder()->instanciateAccessory($this->getProducerCurrent());


if ($accessory->load(\Yii::$app->request->post()) && $accessory->validate()) {
if ($accessoryModel->load(\Yii::$app->request->post()) && $accessoryModel->validate()) {
$accessory = $accessoryModule->getManager()->createAccessory( $accessory = $accessoryModule->getManager()->createAccessory(
$this->getProducerCurrent(), $this->getProducerCurrent(),
$accessory->getName(),
$accessory->getQuantity()
$accessoryModel->getName(),
$accessoryModel->getQuantity()
); );
$this->afterSave($accessory, $accessoryModel->getSelectedProductsIds());
$this->setFlash('success', "Accessoire ajouté"); $this->setFlash('success', "Accessoire ajouté");
return $this->redirectAfterSave('accessory', $accessory->getId()); return $this->redirectAfterSave('accessory', $accessory->getId());
} }


return $this->render('create', [ return $this->render('create', [
'accessory' => $accessory,
'accessory' => $this->initFormModel($accessoryModel),
'productsArray' => $this->findProducts()
]); ]);
} }


$accessory = $this->findAccessory($id); $accessory = $this->findAccessory($id);


if ($accessory->load(\Yii::$app->request->post()) && $accessory->validate() && $accessory->save()) { if ($accessory->load(\Yii::$app->request->post()) && $accessory->validate() && $accessory->save()) {
$this->setFlash('success', "Accessoire modifié");
$this->afterSave($accessory, $accessory->getSelectedProductsIds());
return $this->redirectAfterSave('accessory', $accessory->getId()); return $this->redirectAfterSave('accessory', $accessory->getId());
} }


return $this->render('update', [ return $this->render('update', [
'accessory' => $accessory,
'accessory' => $this->initFormModel($accessory),
'productsArray' => $this->findProducts()
]); ]);
} }


return $this->redirect('index'); return $this->redirect('index');
} }


public function afterSave(Accessory $accessory, $selectedProductsIdsArray): void
{
if(!is_array($selectedProductsIdsArray)) {
$selectedProductsIdsArray = [];
}
$this->getAccessoryModule()->getManager()->manageProducts($accessory, $selectedProductsIdsArray);
}

public function findProducts(): array
{
return $this->getProductModule()->getRepository()->findProducts(true);
}

/** /**
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
throw new NotFoundHttpException("L'accessoire n'a pas été trouvé."); throw new NotFoundHttpException("L'accessoire n'a pas été trouvé.");
} }
} }

public function initFormModel(Accessory $accessoryModel)
{
$this->getAccessoryModule()->getBuilder()->initSelectedProductsIds($accessoryModel);
return $accessoryModel;
}
} }

+ 15
- 0
backend/views/accessory/_form.php View File

* termes. * termes.
*/ */


use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;


?> ?>
<?= $form->field($accessory, 'quantity')->textInput() ?> <?= $form->field($accessory, 'quantity')->textInput() ?>
</div> </div>
</div> </div>
<div class="panel panel-default" id="panel-products">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-clone"></i>
Produits
</h3>
</div>
<div class="panel-body">
<?= Html::activeCheckboxList($accessory, 'selected_products_ids', ArrayHelper::map($productsArray, 'id', function ($product, $defaultValue) {
return Html::encode($product->name);
}), ['encode' => false, 'class' => '']) ?>
</div>
</div>
</div> </div>
<?= $this->render('@backend/views/_include/form_actions.php',[ <?= $this->render('@backend/views/_include/form_actions.php',[
'model' => $accessory, 'model' => $accessory,

+ 1
- 0
backend/views/accessory/create.php View File

<div class="accessory-create"> <div class="accessory-create">
<?= $this->render('_form', [ <?= $this->render('_form', [
'accessory' => $accessory, 'accessory' => $accessory,
'productsArray' => $productsArray
]) ?> ]) ?>
</div> </div>

+ 13
- 1
backend/views/accessory/index.php View File



<div class="accessory-index"> <div class="accessory-index">
<?= GridView::widget([ <?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => [ 'columns' => [
'name', 'name',
'quantity',
[
'label' => 'Produits',
'format' => 'raw',
'value' => function($accessory) {
$html = '';
foreach($accessory->getProductAccessories() as $productAccessory) {
$html .= '<span class="label label-default">'.Html::encode($productAccessory->getProduct()->name).'</span>&nbsp;';
}

return $html;
}
],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}', 'template' => '{update} {delete}',

+ 1
- 0
backend/views/accessory/update.php View File

<div class="accessory-update"> <div class="accessory-update">
<?= $this->render('_form', [ <?= $this->render('_form', [
'accessory' => $accessory, 'accessory' => $accessory,
'productsArray' => $productsArray
]) ?> ]) ?>
</div> </div>

+ 0
- 2
backend/views/product/_form.php View File

</div> </div>
</div> </div>
</div> </div>

</div> </div>
<div class="clr"></div> <div class="clr"></div>
</div> </div>
]); ?> ]); ?>


<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

</div> </div>

+ 6
- 0
backend/web/css/screen.css View File

font-weight: normal; font-weight: normal;
} }


/* line 5, ../sass/accessory/_form.scss */
.accessory-form #panel-products .panel-body label {
display: block;
font-weight: normal;
}

/** /**
Copyright Souke (2018) Copyright Souke (2018)



+ 11
- 0
backend/web/sass/accessory/_form.scss View File


.accessory-form {
#panel-products {
.panel-body {
label {
display: block;
font-weight: normal;
}
}
}
}

+ 1
- 0
backend/web/sass/screen.scss View File

@import "subscription/_form.scss" ; @import "subscription/_form.scss" ;
@import "product/_index.scss" ; @import "product/_index.scss" ;
@import "product/_form.scss" ; @import "product/_form.scss" ;
@import "accessory/_form.scss" ;
@import "stats/_products.scss" ; @import "stats/_products.scss" ;
@import "distribution/_index.scss" ; @import "distribution/_index.scss" ;
@import "user/_emails.scss" ; @import "user/_emails.scss" ;

+ 1
- 0
common/components/BusinessLogic.php View File

$this->getUserModule(), $this->getUserModule(),
$this->getUserMessageModule(), $this->getUserMessageModule(),
$this->getPointSaleDistributionModule(), $this->getPointSaleDistributionModule(),
$this->getProductAccessoryModule(),
$this->getAccessoryModule(), $this->getAccessoryModule(),
$this->getProductDistributionModule(), $this->getProductDistributionModule(),
$this->getProductCategoryModule(), $this->getProductCategoryModule(),

+ 6
- 0
common/components/BusinessLogicTrait.php View File

use domain\Producer\ProducerPriceRange\ProducerPriceRangeModule; use domain\Producer\ProducerPriceRange\ProducerPriceRangeModule;
use domain\Product\Accessory\AccessoryModule; use domain\Product\Accessory\AccessoryModule;
use domain\Product\Product\ProductModule; use domain\Product\Product\ProductModule;
use domain\Product\ProductAccessory\ProductAccessoryModule;
use domain\Product\ProductCategory\ProductCategoryModule; use domain\Product\ProductCategory\ProductCategoryModule;
use domain\Product\ProductPointSale\ProductPointSaleModule; use domain\Product\ProductPointSale\ProductPointSaleModule;
use domain\Product\ProductPrice\Module\ProductPriceModule; use domain\Product\ProductPrice\Module\ProductPriceModule;


trait BusinessLogicTrait trait BusinessLogicTrait
{ {
public function getProductAccessoryModule(): ProductAccessoryModule
{
return ProductAccessoryModule::getInstance();
}

public function getAccessoryModule(): AccessoryModule public function getAccessoryModule(): AccessoryModule
{ {
return AccessoryModule::getInstance(); return AccessoryModule::getInstance();

+ 31
- 0
console/migrations/m240620_074924_create_table_product_accessory.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240620_074924_create_table_product_accessory
*/
class m240620_074924_create_table_product_accessory extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('product_accessory', [
'id' => 'pk',
'id_product' => Schema::TYPE_INTEGER.' NOT NULl',
'id_accessory' => Schema::TYPE_INTEGER.' NOT NULl',
'quantity' => Schema::TYPE_INTEGER.' NOT NULL'
]);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('product_accessory');
}
}

+ 26
- 0
domain/Product/Accessory/Accessory.php View File



use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\Product\ProductAccessory\ProductAccessory;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;


class Accessory extends ActiveRecordCommon class Accessory extends ActiveRecordCommon
{ {
// Produits sélectionnés dans le formulaire d'édition
public $selected_products_ids;

public static function tableName() public static function tableName()
{ {
return 'accessory'; return 'accessory';
[['name', 'id_producer'], 'required'], [['name', 'id_producer'], 'required'],
[['name'], 'string', 'max' => 255], [['name'], 'string', 'max' => 255],
[['quantity', 'id_producer'], 'integer'], [['quantity', 'id_producer'], 'integer'],
[['selected_products_ids'], 'safe'],
]; ];
} }


return $this; return $this;
} }


public function getProductAccessories(): array
{
return $this->productAccessoriesRelation;
}

public function getSelectedProductsIds()
{
return $this->selected_products_ids;
}

public function setSelectedProductsIds(array $selectedProductsIdsArray): self
{
$this->selected_products_ids = $selectedProductsIdsArray;
return $this;
}

/* Relations */ /* Relations */


public function getProducerRelation(): ActiveQuery public function getProducerRelation(): ActiveQuery
{ {
return $this->hasOne(Producer::class, ['id' => 'id_producer']); return $this->hasOne(Producer::class, ['id' => 'id_producer']);
} }

public function getProductAccessoriesRelation(): ActiveQuery
{
return $this->hasMany(ProductAccessory::class, ['id_accessory' => 'id']);
}
} }

+ 18
- 0
domain/Product/Accessory/AccessoryBuilder.php View File



use domain\_\AbstractBuilder; use domain\_\AbstractBuilder;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\Product\ProductAccessory\ProductAccessoryRepository;


class AccessoryBuilder extends AbstractBuilder class AccessoryBuilder extends AbstractBuilder
{ {
protected ProductAccessoryRepository $productAccessoryRepository;

public function loadDependencies(): void
{
$this->productAccessoryRepository = $this->loadService(ProductAccessoryRepository::class);
}

public function instanciateAccessory(Producer $producer): Accessory public function instanciateAccessory(Producer $producer): Accessory
{ {
$accessory = new Accessory(); $accessory = new Accessory();


return $accessory; return $accessory;
} }

public function initSelectedProductsIds(Accessory $accessory): void
{
$selectedProductsIdsArray = [];
$productAccessoriesArray = $this->productAccessoryRepository->findProductAccessoriesByAccessory($accessory);
foreach($productAccessoriesArray as $productAccessory) {
$selectedProductsIdsArray[] = $productAccessory->getProduct()->id;
}
$accessory->setSelectedProductsIds($selectedProductsIdsArray);
}
} }

+ 20
- 0
domain/Product/Accessory/AccessoryManager.php View File



use domain\_\AbstractManager; use domain\_\AbstractManager;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\Product\Product\ProductRepository;
use domain\Product\ProductAccessory\ProductAccessoryManager;
use domain\Product\ProductAccessory\ProductAccessoryRepository;
use yii\base\ErrorException;


class AccessoryManager extends AbstractManager class AccessoryManager extends AbstractManager
{ {
protected AccessoryBuilder $accessoryBuilder; protected AccessoryBuilder $accessoryBuilder;
protected ProductAccessoryManager $productAccessoryManager;
protected ProductRepository $productRepository;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->accessoryBuilder = $this->loadService(AccessoryBuilder::class); $this->accessoryBuilder = $this->loadService(AccessoryBuilder::class);
$this->productAccessoryManager = $this->loadService(ProductAccessoryManager::class);
$this->productRepository = $this->loadService(ProductRepository::class);
} }


public function createAccessory(Producer $producer, string $name, ?int $quantity): Accessory public function createAccessory(Producer $producer, string $name, ?int $quantity): Accessory
$accessory->save(); $accessory->save();
return $accessory; return $accessory;
} }

public function manageProducts(Accessory $accessory, array $selectedProductsIds = []): void
{
$this->productAccessoryManager->deleteAllProductAccessoriesByAccessory($accessory);

foreach($selectedProductsIds as $selectedProductId) {
$product = $this->productRepository->findOneProductById($selectedProductId);
if($product) {
$this->productAccessoryManager->createProductAccessory($product, $accessory, 1);
}
}
}
} }

+ 7
- 0
domain/Product/Accessory/AccessoryRepository.php View File

namespace domain\Product\Accessory; namespace domain\Product\Accessory;


use domain\_\AbstractRepository; use domain\_\AbstractRepository;
use domain\_\RepositoryQueryInterface;
use yii\db\ActiveQuery;


class AccessoryRepository extends AbstractRepository class AccessoryRepository extends AbstractRepository
{ {
]; ];
} }


public function queryAccessories(): RepositoryQueryInterface
{
return $this->createDefaultQuery();
}

public function findOneAccessoryById(int $id): ?Accessory public function findOneAccessoryById(int $id): ?Accessory
{ {
return $this->createDefaultQuery() return $this->createDefaultQuery()

+ 22
- 0
domain/Product/Product/ProductManager.php View File

<?php

namespace domain\Product\Product;

use domain\_\AbstractManager;
use domain\Product\Accessory\Accessory;
use domain\Product\ProductAccessory\ProductAccessoryManager;

class ProductManager extends AbstractManager
{
protected ProductAccessoryManager $productAccessoryManager;

public function loadDependencies(): void
{
$this->productAccessoryManager = $this->loadService(ProductAccessoryManager::class);
}

public function needAccessory(Product $product, Accessory $accessory, int $quantity): void
{
$this->productAccessoryManager->createProductAccessoryIfNotExist($product, $accessory, $quantity);
}
}

+ 9
- 3
domain/Product/Product/ProductModule.php View File

return [ return [
ProductDefinition::class, ProductDefinition::class,
ProductSolver::class, ProductSolver::class,
ProductRepository::class,
ProductBuilder::class, ProductBuilder::class,
ProductRepository::class,
ProductManager::class
]; ];
} }


return ProductSolver::getInstance(); return ProductSolver::getInstance();
} }


public function getBuilder(): ProductBuilder
{
return ProductBuilder::getInstance();
}

public function getRepository(): ProductRepository public function getRepository(): ProductRepository
{ {
return ProductRepository::getInstance(); return ProductRepository::getInstance();
} }


public function getBuilder(): ProductBuilder
public function getManager(): ProductManager
{ {
return ProductBuilder::getInstance();
return ProductManager::getInstance();
} }
} }

+ 86
- 0
domain/Product/ProductAccessory/ProductAccessory.php View File

<?php

namespace domain\Product\ProductAccessory;

use common\components\ActiveRecordCommon;
use domain\Product\Accessory\Accessory;
use domain\Product\Product\Product;
use yii\db\ActiveQuery;

class ProductAccessory extends ActiveRecordCommon
{
public static function tableName()
{
return 'product_accessory';
}

public function rules()
{
return [
[['id_product', 'id_accessory', 'quantity'], 'required'],
[['id_product', 'id_accessory', 'quantity'], 'integer'],
];
}

public function attributeLabels()
{
return [
'id' => 'ID',
'id_product' => 'Produit',
'id_accessory' => 'Accessoire',
'quantity' => 'Quantité',
];
}

/* Getters / Setters */

public function getId(): ?int
{
return $this->id;
}

public function getProduct(): Product
{
return $this->productRelation;
}

public function setProduct(Product $product): self
{
$this->populateFieldObject('id_product', 'productRelation', $product);
return $this;
}

public function getAccessory(): Accessory
{
return $this->accessoryRelation;
}

public function setAccessory(Accessory $accessory): self
{
$this->populateFieldObject('id_accessory', 'accessoryRelation', $accessory);
return $this;
}

public function getQuantity(): ?int
{
return $this->quantity;
}

public function setQuantity(?int $quantity): self
{
$this->quantity = $quantity;
return $this;
}

/* Relations */

public function getProductRelation(): ActiveQuery
{
return $this->hasOne(Product::class, ['id' => 'id_product']);
}

public function getAccessoryRelation(): ActiveQuery
{
return $this->hasOne(Accessory::class, ['id' => 'id_accessory']);
}
}

+ 15
- 0
domain/Product/ProductAccessory/ProductAccessoryBuilder.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractBuilder;
use domain\Product\Product\Product;

class ProductAccessoryBuilder extends AbstractBuilder
{
public function instanciateProductAccessory(): ProductAccessory
{
$productAccessory = new ProductAccessory();
return $productAccessory;
}
}

+ 13
- 0
domain/Product/ProductAccessory/ProductAccessoryDefinition.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractDefinition;

class ProductAccessoryDefinition extends AbstractDefinition
{
public function getEntityFqcn(): string
{
return ProductAccessory::class;
}
}

+ 51
- 0
domain/Product/ProductAccessory/ProductAccessoryManager.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractManager;
use domain\Product\Accessory\Accessory;
use domain\Product\Product\Product;

class ProductAccessoryManager extends AbstractManager
{
protected ProductAccessoryBuilder $productAccessoryBuilder;
protected ProductAccessoryRepository $productAccessoryRepository;

public function loadDependencies(): void
{
$this->productAccessoryBuilder = $this->loadService(ProductAccessoryBuilder::class);
$this->productAccessoryRepository = $this->loadService(ProductAccessoryRepository::class);
}

public function createProductAccessory(Product $product, Accessory $accessory, int $quantity): ProductAccessory
{
$productAccessory = $this->productAccessoryBuilder->instanciateProductAccessory();
$productAccessory->setProduct($product);
$productAccessory->setAccessory($accessory);
$productAccessory->setQuantity($quantity);
$productAccessory->save();
return $productAccessory;
}

public function createProductAccessoryIfNotExist(Product $product, Accessory $accessory, int $quantity): ProductAccessory
{
$productAccessory = $this->productAccessoryRepository->findOneProductAccessory($product, $accessory);
if($productAccessory) {
$productAccessory->setQuantity($quantity);
$productAccessory->save();
}
else {
$productAccessory = $this->createProductAccessory($product, $accessory, $quantity);
}

return $productAccessory;
}

public function deleteAllProductAccessoriesByAccessory(Accessory $accessory): void
{
$productAccessoriesArray = $this->productAccessoryRepository->findProductAccessoriesByAccessory($accessory);
foreach($productAccessoriesArray as $productAccessory) {
$productAccessory->delete();
}
}
}

+ 38
- 0
domain/Product/ProductAccessory/ProductAccessoryModule.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractModule;

class ProductAccessoryModule extends AbstractModule
{
public function getServices(): array
{
return [
ProductAccessoryDefinition::class,
ProductAccessoryBuilder::class,
ProductAccessoryRepository::class,
ProductAccessoryManager::class,
];
}

public function getDefinition(): ProductAccessoryDefinition
{
return ProductAccessoryDefinition::getInstance();
}

public function getBuilder(): ProductAccessoryBuilder
{
return ProductAccessoryBuilder::getInstance();
}

public function getRepository(): ProductAccessoryRepository
{
return ProductAccessoryRepository::getInstance();
}

public function getManager(): ProductAccessoryManager
{
return ProductAccessoryManager::getInstance();
}
}

+ 42
- 0
domain/Product/ProductAccessory/ProductAccessoryRepository.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractRepository;
use domain\Product\Accessory\Accessory;
use domain\Product\Product\Product;

class ProductAccessoryRepository extends AbstractRepository
{
protected ProductAccessoryRepositoryQuery $query;

public function loadDependencies(): void
{
$this->loadQuery(ProductAccessoryRepositoryQuery::class);
}

public function getDefaultOptionsSearch(): array
{
return [
self::WITH => [],
self::JOIN_WITH => ['accessoryRelation'],
self::ORDER_BY => 'accessory.name ASC',
self::ATTRIBUTE_ID_PRODUCER => ''
];
}

public function findOneProductAccessory(Product $product, Accessory $accessory): ?ProductAccessory
{
return $this->createDefaultQuery()
->filterByProduct($product)
->filterByAccessory($accessory)
->findOne();
}

public function findProductAccessoriesByAccessory(Accessory $accessory): array
{
return $this->createDefaultQuery()
->filterByAccessory($accessory)
->find();
}
}

+ 29
- 0
domain/Product/ProductAccessory/ProductAccessoryRepositoryQuery.php View File

<?php

namespace domain\Product\ProductAccessory;

use domain\_\AbstractRepositoryQuery;
use domain\Product\Accessory\Accessory;
use domain\Product\Product\Product;

class ProductAccessoryRepositoryQuery extends AbstractRepositoryQuery
{
protected ProductAccessoryDefinition $definition;

public function loadDependencies(): void
{
$this->loadDefinition(ProductAccessoryDefinition::class);
}

public function filterByProduct(Product $product): self
{
$this->andWhere(['product_accessory.id_product' => $product->id]);
return $this;
}

public function filterByAccessory(Accessory $accessory): self
{
$this->andWhere(['product_accessory.id_accessory' => $accessory->id]);
return $this;
}
}

Loading…
Cancel
Save