From 9c22f2c855ad91d432479d698958ef192b901319 Mon Sep 17 00:00:00 2001 From: Apcenuu <62610873+Apcenuu@users.noreply.github.com> Date: Thu, 29 Jul 2021 20:37:35 +0700 Subject: [PATCH] Add cover on first position in pictures --- retailcrm/lib/RetailcrmCatalog.php | 53 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 41f0f0b..9eebbb5 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -112,8 +112,8 @@ class RetailcrmCatalog $id_lang = $this->default_lang; $homeCategory = $this->home_category; - $inactiveCategories = array(); - $categoriesIds = array(); + $inactiveCategories = []; + $categoriesIds = []; $types = Category::getCategories($id_lang, true, false); @@ -219,22 +219,17 @@ class RetailcrmCatalog if (!empty($combinations)) { foreach ($combinations as $combination) { - $arSet = array( + $arSet = [ 'group_name' => $combination['group_name'], 'attribute' => $combination['attribute_name'], - ); + ]; $arComb[] = $arSet; } } - $pictures = array(); $covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']); - - foreach ($covers as $cover) { - $picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default'); - $pictures[] = $picture; - } + $pictures = $this->getPictures($covers, $product, true); if (!$pictures) { $image = Image::getCover($product['id_product']); @@ -269,7 +264,7 @@ class RetailcrmCatalog $offerArticle = $article; } - $item = array( + $item = [ 'id' => $product['id_product'] . '#' . $offer['id_product_attribute'], 'productId' => $product['id_product'], 'productActivity' => ($available_for_order) ? 'Y' : 'N', @@ -286,7 +281,7 @@ class RetailcrmCatalog 'weight' => $weight, 'dimensions' => $dimensions, 'vatRate' => $product['rate'], - ); + ]; if (!empty($combinations)) { foreach ($arComb as $itemComb) { @@ -297,21 +292,17 @@ class RetailcrmCatalog yield RetailcrmTools::filter( 'RetailcrmFilterProcessOffer', $item, - array( + [ 'product' => $product, 'offer' => $offer - ) + ] ); } } else { $offersCount++; - $pictures = array(); $covers = Image::getImages($id_lang, $product['id_product'], null); - foreach ($covers as $cover) { - $picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default'); - $pictures[] = $picture; - } + $pictures = $this->getPictures($covers, $product); if ($this->version == "1.3") { $quantity = $product['quantity']; @@ -319,7 +310,7 @@ class RetailcrmCatalog $quantity = (int)StockAvailable::getQuantityAvailableByProduct($product['id_product']); } - $item = array( + $item = [ 'id' => $product['id_product'], 'productId' => $product['id_product'], 'productActivity' => ($available_for_order) ? 'Y' : 'N', @@ -336,14 +327,14 @@ class RetailcrmCatalog 'weight' => $weight, 'dimensions' => $dimensions, 'vatRate' => $product['rate'], - ); + ]; yield RetailcrmTools::filter( 'RetailcrmFilterProcessOffer', $item, - array( + [ 'product' => $product - ) + ] ); } } @@ -354,6 +345,22 @@ class RetailcrmCatalog RetailcrmCatalogHelper::setIcmlFileInfo($productsCount, $offersCount); } + private function getPictures(array $covers, array $product, $offers = false) + { + $pictures = []; + foreach ($covers as $cover) { + $picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default'); + + if ($offers === false && $cover['cover']) { + array_unshift($pictures, $picture); + } else { + $pictures[] = $picture; + } + + } + return $pictures; + } + private static function getProductsCount( $id_lang, Context $context = null