@@ -189,6 +189,7 @@ class Distribution extends ActiveRecordCommon | |||
$distribution->linkProduct($product) ; | |||
} | |||
} | |||
$distribution->linkProductGift() ; | |||
} | |||
return $distribution ; | |||
@@ -262,6 +263,29 @@ class Distribution extends ActiveRecordCommon | |||
$productDistribution->save(); | |||
} | |||
/** | |||
* Lie le produit "Don" à la distribution | |||
*/ | |||
public function linkProductGift() | |||
{ | |||
$productGift = Product::getProductGift() ; | |||
if($productGift) { | |||
$productDistribution = ProductDistribution::searchOne([ | |||
'id_distribution' => $this->id, | |||
'id_product' => $productGift->id | |||
]) ; | |||
if(!$productDistribution) { | |||
$productDistribution = new ProductDistribution(); | |||
$productDistribution->id_distribution = $this->id; | |||
$productDistribution->id_product = $productGift->id; | |||
$productDistribution->active = 1; | |||
$productDistribution->save() ; | |||
} | |||
} | |||
} | |||
/** | |||
* Lie un point de vente aux jours de distribution futurs. | |||
* |
@@ -199,5 +199,22 @@ class Product extends ActiveRecordCommon | |||
{ | |||
return self::searchCount() ; | |||
} | |||
/** | |||
* Retourne le produit "Don". | |||
* | |||
* @return Product | |||
*/ | |||
public static function getProductGift() | |||
{ | |||
$productGift = Product::find() | |||
->where([ | |||
'product.id_producer' => 0 | |||
]) | |||
->andFilterWhere(['like','product.name','Don']) | |||
->one() ; | |||
return $productGift ; | |||
} | |||
} |
@@ -535,9 +535,8 @@ class OrderController extends ProducerBaseController | |||
// Produits | |||
$productsArray = Product::find() | |||
->where([ | |||
'id_producer' => $this->getProducer()->id, | |||
]) | |||
->orWhere(['id_producer' => $this->getProducer()->id,]) | |||
->orWhere(['id_producer' => 0,]) // produit "Don" | |||
->joinWith(['productDistribution' => function($query) use($distribution) { | |||
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ; | |||
}]) | |||
@@ -548,6 +547,10 @@ class OrderController extends ProducerBaseController | |||
$indexProduct = 0 ; | |||
foreach($productsArray as &$product) { | |||
if(is_null($product['photo'])) { | |||
$product['photo'] = '' ; | |||
} | |||
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ; | |||
$product['quantity_ordered'] = $quantityOrder ; | |||
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ; | |||
@@ -566,6 +569,7 @@ class OrderController extends ProducerBaseController | |||
$product['index'] = $indexProduct ++ ; | |||
} | |||
$json['products'] = $productsArray; | |||
} | |||