Browse Source

Produits tournants

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
a4463de564
20 changed files with 222 additions and 79 deletions
  1. +12
    -4
      backend/controllers/SubscriptionController.php
  2. +6
    -4
      backend/views/subscription/index.php
  3. +2
    -2
      common/config/main.php
  4. +26
    -13
      common/forms/SubscriptionForm.php
  5. +26
    -0
      console/migrations/m240709_093857_alter_column_product_subscription_id_product.php
  6. +15
    -4
      domain/Order/Order/OrderBuilder.php
  7. +1
    -1
      domain/Product/Rotating/Rotating.php
  8. +13
    -11
      domain/Product/Rotating/RotatingManager.php
  9. +6
    -0
      domain/Product/Rotating/RotatingResolver.php
  10. +39
    -18
      domain/Subscription/ProductSubscription/ProductSubscription.php
  11. +3
    -9
      domain/Subscription/ProductSubscription/ProductSubscriptionBuilder.php
  12. +39
    -0
      domain/Subscription/ProductSubscription/ProductSubscriptionManager.php
  13. +8
    -2
      domain/Subscription/ProductSubscription/ProductSubscriptionModule.php
  14. +10
    -1
      domain/Subscription/ProductSubscription/ProductSubscriptionRepository.php
  15. +7
    -0
      domain/Subscription/ProductSubscription/ProductSubscriptionRepositoryQuery.php
  16. +2
    -2
      domain/Subscription/Subscription/Subscription.php
  17. +1
    -1
      domain/Subscription/Subscription/SubscriptionRepository.php
  18. +1
    -2
      domain/Subscription/Subscription/SubscriptionSearch.php
  19. +2
    -2
      domain/Subscription/Subscription/SubscriptionSolver.php
  20. +3
    -3
      producer/controllers/SubscriptionController.php

+ 12
- 4
backend/controllers/SubscriptionController.php View File

$producerModule = $this->getProducerModule(); $producerModule = $this->getProducerModule();
$productModule = $this->getProductModule(); $productModule = $this->getProductModule();
$subscriptionManger = $this->getSubscriptionModule(); $subscriptionManger = $this->getSubscriptionModule();
$distributionModule = $this-> getDistributionModule();
$distributionModule = $this->getDistributionModule();


$model = new SubscriptionForm(); $model = new SubscriptionForm();
$model->isAdmin = true; $model->isAdmin = true;


$arrayProductsSubscription = $productSubscriptionModule->findProductSubscriptionsBySubscription($subscription); $arrayProductsSubscription = $productSubscriptionModule->findProductSubscriptionsBySubscription($subscription);
foreach ($arrayProductsSubscription as $productSubscription) { foreach ($arrayProductsSubscription as $productSubscription) {
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity;
if($productSubscription->getProduct()) {
$model->products['product_' . $productSubscription->id_product] = $productSubscription->getQuantity();
}
elseif($productSubscription->getRotating()) {
$model->rotatings['rotating_' . $productSubscription->id_rotating] = $productSubscription->getQuantity();
}
} }
} else { } else {
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); throw new NotFoundHttpException('L\'abonnement est introuvable.', 404);
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;


$subscription = $idSubscription ? $this->getSubscriptionModule()->getRepository()->findOneSubscriptionById($idSubscription) : null;
$rotatingModule = $this->getRotatingModule(); $rotatingModule = $this->getRotatingModule();
$unitModule = $this->getUnitModule(); $unitModule = $this->getUnitModule();


}]); }]);
} }


// Produits
$productsArray = $productsQuery->asArray()->orderBy('order ASC')->all(); $productsArray = $productsQuery->asArray()->orderBy('order ASC')->all();

foreach ($productsArray as &$theProduct) { foreach ($productsArray as &$theProduct) {
$theProduct['wording_unit'] = $unitModule->getSolver()->strUnit($theProduct['unit']); $theProduct['wording_unit'] = $unitModule->getSolver()->strUnit($theProduct['unit']);


$rotatingsArrayReturn = []; $rotatingsArrayReturn = [];
$rotatingsArray = $rotatingModule->getRepository()->findRotatings(); $rotatingsArray = $rotatingModule->getRepository()->findRotatings();
foreach($rotatingsArray as $rotating) { foreach($rotatingsArray as $rotating) {
$productSubscription = $this->getProductSubscriptionModule()->getRepository()
->findOneProductSubscriptionBySubscriptionAndRotating($subscription, $rotating);
$rotatingsArrayReturn[] = array_merge($rotating->getAttributes(), [ $rotatingsArrayReturn[] = array_merge($rotating->getAttributes(), [
'quantity' => ''
'quantity' => $productSubscription ? $productSubscription->getQuantity() : ''
]); ]);
} }



+ 6
- 4
backend/views/subscription/index.php View File

use domain\Product\Product\ProductModule; use domain\Product\Product\ProductModule;
use domain\Subscription\Subscription\Subscription; use domain\Subscription\Subscription\Subscription;
use domain\Subscription\Subscription\SubscriptionModule; use domain\Subscription\Subscription\SubscriptionModule;
use domain\Subscription\Subscription\SubscriptionRepository;
use domain\User\User\UserModule; use domain\User\User\UserModule;
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
$this->addBreadcrumb($this->getTitle()) ; $this->addBreadcrumb($this->getTitle()) ;
$this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ;


$subscriptionsArray = Subscription::searchAll() ;

?> ?>
<div class="subscription-index"> <div class="subscription-index">
<?= GridView::widget([ <?= GridView::widget([
$html = '' ; $html = '' ;
foreach($model->productSubscription as $productSubscription) foreach($model->productSubscription as $productSubscription)
{ {
if(isset($productSubscription->product)) {
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).'&nbsp;'. $productModule->getSolver()->strUnit($productSubscription->product, 'wording_short').')<br />' ;
if($productSubscription->getProduct()) {
$html .= Html::encode($productSubscription->getProduct()->name).' ('.($productSubscription->getQuantity() * Product::$unitsArray[$productSubscription->getProduct()->unit]['coefficient']).'&nbsp;'. $productModule->getSolver()->strUnit($productSubscription->getProduct(), 'wording_short').')<br />' ;
}
elseif($productSubscription->getRotating()) {
$html .= Html::encode($productSubscription->getRotating()->getName()).' ('.($productSubscription->getQuantity()).'&nbsp;p.)<br />' ;
} }
else { else {
$html .= 'Produit non défini<br />' ; $html .= 'Produit non défini<br />' ;

+ 2
- 2
common/config/main.php View File

domain\User\UserProducer\Event\PaymentObserver::class domain\User\UserProducer\Event\PaymentObserver::class
], ],
Distribution::class => [ Distribution::class => [
// Initialisation de l'ensemble des produits tournants au moment de l'activation d'une distribution
domain\Product\Rotating\Event\DistributionObserver::class,
// Subscription : génération des commandes sur base des abonnements // Subscription : génération des commandes sur base des abonnements
domain\Subscription\Subscription\Event\DistributionObserver::class, domain\Subscription\Subscription\Event\DistributionObserver::class,
// Initialisation de l'ensemble des produits tournants au moment de l'activation d'une distribution
domain\Product\Rotating\Event\DistributionObserver::class
], ],
DeliveryNote::class => [ DeliveryNote::class => [
// Order : assignation du bon de livraison aux commandes // Order : assignation du bon de livraison aux commandes

+ 26
- 13
common/forms/SubscriptionForm.php View File



use domain\Product\Product\Product; use domain\Product\Product\Product;
use domain\Product\Product\ProductModule; use domain\Product\Product\ProductModule;
use domain\Product\Product\ProductRepository;
use domain\Product\Rotating\RotatingRepository;
use domain\Subscription\ProductSubscription\ProductSubscription; use domain\Subscription\ProductSubscription\ProductSubscription;
use domain\Subscription\ProductSubscription\ProductSubscriptionManager;
use domain\Subscription\Subscription\Subscription; use domain\Subscription\Subscription\Subscription;
use domain\Subscription\Subscription\SubscriptionModule; use domain\Subscription\Subscription\SubscriptionModule;
use domain\User\User\UserModule; use domain\User\User\UserModule;
$subscriptionModule = SubscriptionModule::getInstance(); $subscriptionModule = SubscriptionModule::getInstance();


if ($this->id) { if ($this->id) {
$subscription = Subscription::searchOne(['id' => $this->id]) ;
$subscription = Subscription::searchOne(['id' => $this->id]) ;
$subscription->populateUpdatedBy($userModule->getCurrent()); $subscription->populateUpdatedBy($userModule->getCurrent());
} }
else { else {


$subscription->save(); $subscription->save();


// produits
if ($this->id) { if ($this->id) {
$productsSubscriptionsArray = ProductSubscription::findAll(['id_subscription' => $this->id]) ;
ProductSubscription::deleteAll(['id_subscription' => $this->id]);
ProductSubscription::deleteAll(['id_subscription' => $this->id]);
} }


foreach ($this->products as $nameInput => $quantity) { foreach ($this->products as $nameInput => $quantity) {
if ($quantity) {
$idProduct = (int) str_replace('product_', '', $nameInput);
$product = Product::findOne($idProduct) ;

$newProductSubscription = new ProductSubscription;
$newProductSubscription->id_subscription = $subscription->id;
$newProductSubscription->id_product = $idProduct;
$newProductSubscription->quantity = $quantity / $productModule->getSolver()->getUnitCoefficient($product);
$idProduct = (int) str_replace('product_', '', $nameInput);
$product = ProductRepository::getInstance()->findOneProductById($idProduct) ;
if ($quantity && $product) {
ProductSubscriptionManager::getInstance()->createProductSubscription(
$subscription,
$product,
null,
$quantity / $productModule->getSolver()->getUnitCoefficient($product)
);
}
}


$newProductSubscription->save();
foreach ($this->rotatings as $nameInput => $quantity) {
$idRotating = (int) str_replace('rotating_', '', $nameInput);
$rotating = RotatingRepository::getInstance()->findOneRotatingById($idRotating) ;
if ($quantity && $rotating) {
ProductSubscriptionManager::getInstance()->createProductSubscription(
$subscription,
null,
$rotating,
$quantity
);
} }
} }

+ 26
- 0
console/migrations/m240709_093857_alter_column_product_subscription_id_product.php View File

<?php

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

/**
* Class m240709_093857_alter_column_product_subscription_id_product
*/
class m240709_093857_alter_column_product_subscription_id_product extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->alterColumn('product_subscription', 'id_product', Schema::TYPE_INTEGER);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->alterColumn('product_subscription', 'id_product', Schema::TYPE_INTEGER.' NOT NULL');
}
}

+ 15
- 4
domain/Order/Order/OrderBuilder.php View File

use domain\Product\Product\Product; use domain\Product\Product\Product;
use domain\Product\Product\ProductRepository; use domain\Product\Product\ProductRepository;
use domain\Product\Product\ProductSolver; use domain\Product\Product\ProductSolver;
use domain\Product\Rotating\RotatingResolver;
use domain\Subscription\Subscription\Subscription; use domain\Subscription\Subscription\Subscription;
use domain\Subscription\Subscription\SubscriptionBuilder; use domain\Subscription\Subscription\SubscriptionBuilder;
use domain\Subscription\Subscription\SubscriptionRepository; use domain\Subscription\Subscription\SubscriptionRepository;
$user = $subscription->user ?? null; $user = $subscription->user ?? null;
foreach ($subscription->productSubscription as $productSubscription) { foreach ($subscription->productSubscription as $productSubscription) {


if($productSubscription->getProduct()) {
$product = $productSubscription->getProduct();
}
elseif($productSubscription->getRotating()) {
$product = RotatingResolver::getInstance()->getProductOfRotatingInDistribution(
$productSubscription->getRotating(),
$order->distribution
);
}

$this->productOrderBuilder->createProductOrder( $this->productOrderBuilder->createProductOrder(
$order, $order,
$productSubscription->product,
$productSubscription->quantity,
(float) $this->productSolver->getPrice($productSubscription->product, [
$product,
$productSubscription->getQuantity(),
(float) $this->productSolver->getPrice($product, [
'user' => $user, 'user' => $user,
'point_sale' => $subscription->pointSale, 'point_sale' => $subscription->pointSale,
'quantity' => $productSubscription->quantity
'quantity' => $productSubscription->getQuantity()
]) ])
); );
$productsAdd = true; $productsAdd = true;

+ 1
- 1
domain/Product/Rotating/Rotating.php View File

public function rules() public function rules()
{ {
return [ return [
[['id_producer', 'name', 'day', 'selected_products_ids'], 'required'],
[['id_producer', 'name', 'day'], 'required'],
[['name'], 'string', 'max' => 255], [['name'], 'string', 'max' => 255],
[['id_producer', 'day', 'status'], 'integer'], [['id_producer', 'day', 'status'], 'integer'],
[['selected_products_ids'], 'verifySelectedProductsIds'], [['selected_products_ids'], 'verifySelectedProductsIds'],

+ 13
- 11
domain/Product/Rotating/RotatingManager.php View File

*/ */
public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution) public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution)
{ {
$rotatingProductOfDistribution = $this->rotatingResolver->deductRotatingProductOfDistribution($rotating, $distribution);
if($rotating->getDay() == $distribution->getDate()->format('N')) {
$rotatingProductOfDistribution = $this->rotatingResolver->deductRotatingProductOfDistribution($rotating, $distribution);


$this->distributionRotatingManager->createDistributionRotatingIfNotExist(
$distribution,
$rotatingProductOfDistribution
);
$this->distributionRotatingManager->createDistributionRotatingIfNotExist(
$distribution,
$rotatingProductOfDistribution
);


foreach($rotating->getRotatingProducts() as $rotatingProduct) {
if($rotatingProduct->getId() == $rotatingProductOfDistribution->getId()) {
$this->productManager->activateProductInDistribution($rotatingProductOfDistribution->getProduct(), $distribution);
}
else {
$this->productManager->deactivateProductInDistribution($rotatingProduct->getProduct(), $distribution);
foreach($rotating->getRotatingProducts() as $rotatingProduct) {
if($rotatingProduct->getId() == $rotatingProductOfDistribution->getId()) {
$this->productManager->activateProductInDistribution($rotatingProductOfDistribution->getProduct(), $distribution);
}
else {
$this->productManager->deactivateProductInDistribution($rotatingProduct->getProduct(), $distribution);
}
} }
} }
} }

+ 6
- 0
domain/Product/Rotating/RotatingResolver.php View File

return $this->getFirstRotatingProduct($rotating); return $this->getFirstRotatingProduct($rotating);
} }


public function getProductOfRotatingInDistribution(Rotating $rotating, Distribution $distribution): Product
{
$rotatingProduct = $this->distributionRotatingRepository->findOneDistributionRotating($distribution, $rotating);
return $rotatingProduct->getRotatingProduct()->getProduct();
}

/** /**
* @throws ErrorException * @throws ErrorException
*/ */

+ 39
- 18
domain/Subscription/ProductSubscription/ProductSubscription.php View File

use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;
use domain\Product\Product\Product; use domain\Product\Product\Product;
use domain\Product\Rotating\Rotating; use domain\Product\Rotating\Rotating;
use domain\Subscription\Subscription\Subscription;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;


/**
* This is the model class for table "commande_auto_produit".
*/
class ProductSubscription extends ActiveRecordCommon class ProductSubscription extends ActiveRecordCommon
{ {
/**
* @inheritdoc
*/
public static function tableName() public static function tableName()
{ {
return 'product_subscription'; return 'product_subscription';
} }


/**
* @inheritdoc
*/
public function rules() public function rules()
{ {
return [ return [
]; ];
} }


/**
* @inheritdoc
*/
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
]; ];
} }


/* Méthodes */



/* Getters / setters */ /* Getters / setters */


public function getRotating(): ?Rotating public function getRotating(): ?Rotating
return $this; return $this;
} }


/* Relations */
public function getSubscription(): Subscription
{
return $this->subscriptionRelation;
}


public function getRotatingRelation(): ActiveQuery
public function setSubscription(Subscription $subscription): self
{ {
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']);
$this->populateFieldObject('id_subscription', 'subscriptionRelation', $subscription);
return $this;
} }


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


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

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

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

/* Relations */

public function getRotatingRelation(): ActiveQuery
{
return $this->hasOne(Rotating::class, ['id' => 'id_rotating']);
}

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

+ 3
- 9
domain/Subscription/ProductSubscription/ProductSubscriptionBuilder.php View File

namespace domain\Subscription\ProductSubscription; namespace domain\Subscription\ProductSubscription;


use domain\_\AbstractBuilder; use domain\_\AbstractBuilder;
use domain\Subscription\Subscription\Subscription;


class ProductSubscriptionBuilder extends AbstractBuilder class ProductSubscriptionBuilder extends AbstractBuilder
{ {
public function instanciateProductSubscription(): ProductSubscription
public function instanciateProductSubscription(Subscription $subscription): ProductSubscription
{ {
$productSubscription = new ProductSubscription(); $productSubscription = new ProductSubscription();

return $productSubscription;
}

public function createProductSubscription(): ProductSubscription
{
$productSubscription = $this->instanciateProductSubscription();
$this->saveCreate($productSubscription);
$productSubscription->setSubscription($subscription);


return $productSubscription; return $productSubscription;
} }

+ 39
- 0
domain/Subscription/ProductSubscription/ProductSubscriptionManager.php View File

<?php

namespace domain\Subscription\ProductSubscription;

use domain\_\AbstractManager;
use domain\Product\Product\Product;
use domain\Product\Rotating\Rotating;
use domain\Subscription\Subscription\Subscription;
use yii\base\ErrorException;

class ProductSubscriptionManager extends AbstractManager
{
protected ProductSubscriptionBuilder $productSubscriptionBuilder;

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

public function createProductSubscription(Subscription $subscription, Product $product = null, Rotating $rotating = null, float $quantity = null): ProductSubscription
{
if(!$product && !$rotating) {
throw new ErrorException("Il faut au moins un produit ou un produit tournant pour créer un ProductSubscription");
}

$productSubscription = $this->productSubscriptionBuilder->instanciateProductSubscription($subscription);
if($product) {
$productSubscription->setProduct($product);
}
if($rotating) {
$productSubscription->setRotating($rotating);
}
$productSubscription->setQuantity($quantity);

$productSubscription->save();

return $productSubscription;
}
}

+ 8
- 2
domain/Subscription/ProductSubscription/ProductSubscriptionModule.php View File

return [ return [
ProductSubscriptionDefinition::class, ProductSubscriptionDefinition::class,
ProductSubscriptionRepository::class, ProductSubscriptionRepository::class,
ProductSubscriptionBuilder::class
ProductSubscriptionBuilder::class,
ProductSubscriptionManager::class,
]; ];
} }


return ProductSubscriptionRepository::getInstance(); return ProductSubscriptionRepository::getInstance();
} }


public function getFactory(): ProductSubscriptionBuilder
public function getBuilder(): ProductSubscriptionBuilder
{ {
return ProductSubscriptionBuilder::getInstance(); return ProductSubscriptionBuilder::getInstance();
} }

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

+ 10
- 1
domain/Subscription/ProductSubscription/ProductSubscriptionRepository.php View File



namespace domain\Subscription\ProductSubscription; namespace domain\Subscription\ProductSubscription;


use domain\Product\Rotating\Rotating;
use domain\Subscription\Subscription\Subscription; use domain\Subscription\Subscription\Subscription;
use domain\_\AbstractRepository; use domain\_\AbstractRepository;


public function getDefaultOptionsSearch(): array public function getDefaultOptionsSearch(): array
{ {
return [ return [
self::WITH => ['product'],
self::WITH => ['productRelation'],
self::JOIN_WITH => [], self::JOIN_WITH => [],
self::ORDER_BY => '', self::ORDER_BY => '',
self::ATTRIBUTE_ID_PRODUCER => '' self::ATTRIBUTE_ID_PRODUCER => ''
->filterBySubscription($subscription) ->filterBySubscription($subscription)
->find(); ->find();
} }

public function findOneProductSubscriptionBySubscriptionAndRotating(Subscription $subscription, Rotating $rotating): ?ProductSubscription
{
return $this->createDefaultQuery()
->filterBySubscription($subscription)
->filterByRotating($rotating)
->findOne();
}
} }

+ 7
- 0
domain/Subscription/ProductSubscription/ProductSubscriptionRepositoryQuery.php View File



namespace domain\Subscription\ProductSubscription; namespace domain\Subscription\ProductSubscription;


use domain\Product\Rotating\Rotating;
use domain\Subscription\Subscription\Subscription; use domain\Subscription\Subscription\Subscription;
use domain\_\AbstractRepositoryQuery; use domain\_\AbstractRepositoryQuery;


$this->andWhere(['id_subscription' => $subscription->id]); $this->andWhere(['id_subscription' => $subscription->id]);
return $this; return $this;
} }

public function filterByRotating(Rotating $rotating): self
{
$this->andWhere(['id_rotating' => $rotating->getId()]);
return $this;
}
} }

+ 2
- 2
domain/Subscription/Subscription/Subscription.php View File

return [ return [
'id' => 'ID', 'id' => 'ID',
'id_user' => 'Utilisateur', 'id_user' => 'Utilisateur',
'id_producer' => 'Etablissement',
'id_producer' => 'Producteur',
'id_point_sale' => 'Point de vente', 'id_point_sale' => 'Point de vente',
'date_begin' => 'Date de début', 'date_begin' => 'Date de début',
'date_end' => 'Date de fin', 'date_end' => 'Date de fin',
public function getProductSubscription() public function getProductSubscription()
{ {
return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id']) return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id'])
->with('product');
->with('productRelation');
} }


public function getCreatedBy() public function getCreatedBy()

+ 1
- 1
domain/Subscription/Subscription/SubscriptionRepository.php View File

{ {
return [ return [
self::WITH => ['producer'], self::WITH => ['producer'],
self::JOIN_WITH => ['user', 'productSubscription', 'productSubscription.product', 'pointSale'],
self::JOIN_WITH => ['user', 'productSubscription', 'productSubscription.productRelation', 'pointSale'],
self::ORDER_BY => 'user.name ASC', self::ORDER_BY => 'user.name ASC',
self::ATTRIBUTE_ID_PRODUCER => 'subscription.id_producer' self::ATTRIBUTE_ID_PRODUCER => 'subscription.id_producer'
]; ];

+ 1
- 2
domain/Subscription/Subscription/SubscriptionSearch.php View File

]); ]);
$query->andFilterWhere(['like', 'product.name', $this->product_name]) ; $query->andFilterWhere(['like', 'product.name', $this->product_name]) ;

return $dataProvider; return $dataProvider;
} }

+ 2
- 2
domain/Subscription/Subscription/SubscriptionSolver.php View File

$html = '' ; $html = '' ;
foreach($subscription->productSubscription as $productSubscription) foreach($subscription->productSubscription as $productSubscription)
{ {
if(isset($productSubscription->product) && $productSubscription->product) {
$html .= '<strong>'.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . '&nbsp'. $this->productSolver->strUnit($productSubscription->product, 'wording_short') . '</strong> ' . Html::encode($productSubscription->product->name). '<br />' ;
if($productSubscription->getProduct()) {
$html .= '<strong>'.($productSubscription->getQuantity() * Product::$unitsArray[$productSubscription->getProduct()->unit]['coefficient']) . '&nbsp'. $this->productSolver->strUnit($productSubscription->getProduct(), 'wording_short') . '</strong> ' . Html::encode($productSubscription->getProduct()->name). '<br />' ;
} }
else { else {
$html .= 'Produit non défini<br />' ; $html .= 'Produit non défini<br />' ;

+ 3
- 3
producer/controllers/SubscriptionController.php View File

]); ]);


foreach ($arrayProductsSubscription as $productSubscription) { foreach ($arrayProductsSubscription as $productSubscription) {
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity;
$model->products['product_' . $productSubscription->id_product] = $productSubscription->getQuantity();
} }
} else { } else {
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404); throw new NotFoundHttpException('L\'abonnement est introuvable.', 404);
if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) { if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) {
foreach ($arrayProductsSubscription as $productSubscription) { foreach ($arrayProductsSubscription as $productSubscription) {
if ($product->id == $productSubscription->id_product) { if ($product->id == $productSubscription->id_product) {
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->product);
$quantity = $productSubscription->quantity * $coefficientUnit;
$coefficientUnit = $productModule->getSolver()->getUnitCoefficient($productSubscription->getProduct());
$quantity = $productSubscription->getQuantity() * $coefficientUnit;
} }
} }
} }

Loading…
Cancel
Save