Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed undefined array key category_name in statistics #280

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fan of this line because I already have it line 150.

$imgDetails = $imageRetriever->getNoPictureImage($this->context->language);
}

Expand Down
Loading