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; | |||||
} | |||||
} | } |
* 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, |
<div class="accessory-create"> | <div class="accessory-create"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'accessory' => $accessory, | 'accessory' => $accessory, | ||||
'productsArray' => $productsArray | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
<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> '; | |||||
} | |||||
return $html; | |||||
} | |||||
], | |||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update} {delete}', | 'template' => '{update} {delete}', |
<div class="accessory-update"> | <div class="accessory-update"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'accessory' => $accessory, | 'accessory' => $accessory, | ||||
'productsArray' => $productsArray | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
</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> |
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) | ||||
.accessory-form { | |||||
#panel-products { | |||||
.panel-body { | |||||
label { | |||||
display: block; | |||||
font-weight: normal; | |||||
} | |||||
} | |||||
} | |||||
} |
@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" ; |
$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(), |
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(); |
<?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'); | |||||
} | |||||
} |
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']); | |||||
} | |||||
} | } |
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); | |||||
} | |||||
} | } |
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); | |||||
} | |||||
} | |||||
} | |||||
} | } |
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() |
<?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); | |||||
} | |||||
} |
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(); | |||||
} | } | ||||
} | } |
<?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']); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?php | |||||
namespace domain\Product\ProductAccessory; | |||||
use domain\_\AbstractDefinition; | |||||
class ProductAccessoryDefinition extends AbstractDefinition | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return ProductAccessory::class; | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |