Browse Source

[backend] Correction bug cast Product dans méthode linkProduct

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
b38422ec7f
2 changed files with 6 additions and 7 deletions
  1. +4
    -5
      backend/controllers/DistributionController.php
  2. +2
    -2
      common/models/Distribution.php

+ 4
- 5
backend/controllers/DistributionController.php View File

$potentialRevenues = 0; $potentialRevenues = 0;
$potentialWeight = 0; $potentialWeight = 0;
foreach($productsArray as &$theProduct) { foreach($productsArray as &$theProduct) {
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; $quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ;
$theProduct['quantity_ordered'] = $quantityOrder ; $theProduct['quantity_ordered'] = $quantityOrder ;
if(!isset($theProduct['productDistribution'][0])) { if(!isset($theProduct['productDistribution'][0])) {
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProduct) ;
$theProductObject = (object) $theProduct ;
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProductObject) ;
} }
if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) {
] ; ] ;
} }
/*$productOrderArray = \yii\helpers\ArrayHelper::map($order->productOrder, 'id_product', 'quantity') ;
*/
foreach($productsArray as $product) { foreach($productsArray as $product) {
if(!isset($productOrderArray[$product['id']])) { if(!isset($productOrderArray[$product['id']])) {
$productOrderArray[$product['id']] = [ $productOrderArray[$product['id']] = [

+ 2
- 2
common/models/Distribution.php View File

* @param Product $product * @param Product $product
*/ */
public function linkProduct($product) public function linkProduct($product)
{
{
$productDistribution = ProductDistribution::searchOne([ $productDistribution = ProductDistribution::searchOne([
'id_distribution' => $this->id, 'id_distribution' => $this->id,
'id_product' => $product->id 'id_product' => $product->id
]) ; ]) ;
if(!$productDistribution) { if(!$productDistribution) {
$productDistribution = new ProductDistribution(); $productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id; $productDistribution->id_distribution = $this->id;

Loading…
Cancel
Save