Skip to content

Commit

Permalink
Merge pull request #280 from PrestaShop/fix-undefined-array-key
Browse files Browse the repository at this point in the history
Fixed undefined array key category_name in statistics
  • Loading branch information
Hlavtox authored Oct 1, 2024
2 parents 36c8a36 + e6e8c9c commit 5b312ca
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/Calculator/StatisticsCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use DbQuery;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductLazyArray;
use PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductPresenter;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
Expand Down Expand Up @@ -146,17 +147,19 @@ public function computeConversionRate(&$stats, $dateStart = null)
$combination = implode(',', $combinationArr);
}

$imgDetails = $this->getProductImage($productDetails);
$presentedProduct = $this->getPresentedProduct($productDetails);
$imgDetails = $this->getProductImage($presentedProduct);

$stats[$idProductAndAttribute] = [
'position' => $position,
'count' => $count,
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'name' => $productDetails['name'],
'combination' => $combination,
'category_name' => $productDetails['category_name'],
'category_name' => $presentedProduct['category_name'],
'image_small_url' => $imgDetails['small']['url'],
'link' => $productDetails['link'],
'link' => $presentedProduct['link'],
'reference' => $productDetails['reference'],
'price' => $this->locale->formatPrice($productDetails['price'], $this->context->currency->iso_code),
'quantity' => $productDetails['quantity'],
Expand All @@ -167,20 +170,12 @@ public function computeConversionRate(&$stats, $dateStart = null)
}
}

/**
* getProductImage
*
* @param array $productDetails
*
* @return array
*/
public function getProductImage($productDetails)
private function getPresentedProduct($productDetails)
{
$imgDetails = [];

$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
$imageRetriever = new ImageRetriever($this->context->link);

$presenter = new ProductPresenter(
$imageRetriever,
$this->context->link,
Expand All @@ -189,18 +184,31 @@ public function getProductImage($productDetails)
$this->context->getTranslator()
);

$presentedProduct = $presenter->present(
return $presenter->present(
$presentationSettings,
$productDetails,
$this->context->language
);
}

/**
* getProductImage
*
* @param mixed|ProductLazyArray $presentedProduct
*
* @return array
*/
public function getProductImage($presentedProduct)
{
$imgDetails = [];

foreach ($presentedProduct as $key => $value) {
if ($key == 'embedded_attributes') {
$imgDetails = $value['cover'];
}
}
if (!$imgDetails) {
$imageRetriever = new ImageRetriever($this->context->link);
$imgDetails = $imageRetriever->getNoPictureImage($this->context->language);
}

Expand Down

0 comments on commit 5b312ca

Please sign in to comment.