From 983a3789d946520953d4204f01c4110f4c05520a Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Thu, 23 May 2024 12:16:48 +0200 Subject: [PATCH] FIX: Images Cover Flag ADD: Product Show Price Flag --- .env | 23 +++++++++++++++++++ .../src/Objects/Product/ImagesTrait.php | 15 +++++++----- .../src/Objects/Product/MetaTrait.php | 9 ++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..5565f180 --- /dev/null +++ b/.env @@ -0,0 +1,23 @@ +################################################################################ +# +# * This file is part of BadPixxel ProductMixer Module. +# * +# * Copyright (C) BadPixxel +# * +# * This program is free software: you can redistribute it +# * and/or modify it under the terms of the GNU General Public License +# * as published by the Free Software Foundation, version 3. +# * +# * This program is distributed in the hope that it will be useful, +# * but WITHOUT ANY WARRANTY; without even the implied warranty of +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# * See the GNU General Public License for more details. +# * +# * You should have received a copy of the GNU General Public License +# * long with this program. If not, see . +# +################################################################################ + +###> badpixxel/wall-e ### +GRUMPHP_BIN="modules/splashsync/vendor/bin/grumphp" +###< badpixxel/wall-e ### diff --git a/modules/splashsync/src/Objects/Product/ImagesTrait.php b/modules/splashsync/src/Objects/Product/ImagesTrait.php index cd078af9..e48cfdbd 100644 --- a/modules/splashsync/src/Objects/Product/ImagesTrait.php +++ b/modules/splashsync/src/Objects/Product/ImagesTrait.php @@ -463,6 +463,11 @@ private function updateImageCoverFlag(Image &$psImage, array $imgArray): void if ($psImage->cover !== $isCover) { $psImage->cover = $isCover; $this->needUpdate("Image"); + //====================================================================// + // Delete Cover Flag for Other Images + if ($isCover) { + Image::deleteCover($psImage->id_product); + } } } @@ -594,6 +599,7 @@ private function updateImgThumbnail(): void if (!file_exists($imagePath.'.jpg')) { continue; } + foreach (ImageType::getImagesTypes("products") as $imageType) { $imgThumb = _PS_PROD_IMG_DIR_.$imageObj->getExistingImgPath(); $imgThumb .= '-'.Tools::stripslashes($imageType['name']).'.jpg'; @@ -699,13 +705,12 @@ private function setImgArray(array $data): bool //====================================================================// // Search For Image In Current List $psImage = $this->searchImage($value["image"]["md5"]); - if (false == $psImage) { + if (!$psImage) { //====================================================================// // If Not found, Add this object to list $psImage = $this->addImageToProduct( $inImage, - (int) $this->getImagePosition($value), - (bool) $this->getImageCoverFlag($value) + (int) $this->getImagePosition($value) ); } //====================================================================// @@ -752,11 +757,10 @@ private function setImgArray(array $data): bool * * @param array $imgArray Splash Image Definition Array * @param int $position Image Position (On Base Product Sheet) - * @param bool $isCover Image is Cover Image * * @return false|Image */ - private function addImageToProduct(array $imgArray, int $position, bool $isCover) + private function addImageToProduct(array $imgArray, int $position) { //====================================================================// // Read File from Splash Server @@ -773,7 +777,6 @@ private function addImageToProduct(array $imgArray, int $position, bool $isCover $objectImage->legend = $newImageFile["name"] ?? $newImageFile["filename"]; $objectImage->id_product = $this->ProductId; $objectImage->position = $position; - $objectImage->cover = $isCover; //====================================================================// // Write Image To Database if (!$objectImage->add()) { diff --git a/modules/splashsync/src/Objects/Product/MetaTrait.php b/modules/splashsync/src/Objects/Product/MetaTrait.php index ff379d9f..6eb1778e 100644 --- a/modules/splashsync/src/Objects/Product/MetaTrait.php +++ b/modules/splashsync/src/Objects/Product/MetaTrait.php @@ -60,6 +60,13 @@ protected function buildMetaFields(): void ->microData("http://schema.org/Product", "onsale") ; //====================================================================// + // Display Price + $this->fieldsFactory()->create(SPL_T_BOOL) + ->identifier("show_price") + ->name($this->spl->l("Show Price")) + ->microData("http://schema.org/Product", "showPrice") + ; + //====================================================================// // Online Only $this->fieldsFactory()->create(SPL_T_BOOL) ->identifier("online_only") @@ -103,6 +110,7 @@ protected function getMetaFields(string $key, string $fieldName): void // OTHERS INFORMATIONS //====================================================================// case 'active': + case 'show_price': case 'on_sale': case 'online_only': $this->getSimpleBool($fieldName); @@ -188,6 +196,7 @@ protected function setMetaFields(string $fieldName, $fieldData): void //====================================================================// // Direct Writings case 'active': + case 'show_price': case 'on_sale': case 'online_only': $this->setSimple($fieldName, $fieldData);