From f575db156f1bfa48bd1400a429e071bd4cc5c346 Mon Sep 17 00:00:00 2001 From: merdan Date: Fri, 23 Sep 2022 17:25:07 +0500 Subject: [PATCH] menu brand links test ready --- .../API/Http/Resources/Catalog/Product.php | 3 +- .../Shop/src/Repositories/MenuRepository.php | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/Sarga/API/Http/Resources/Catalog/Product.php b/packages/Sarga/API/Http/Resources/Catalog/Product.php index cd7fa748b..b48bdfca6 100644 --- a/packages/Sarga/API/Http/Resources/Catalog/Product.php +++ b/packages/Sarga/API/Http/Resources/Catalog/Product.php @@ -83,9 +83,8 @@ class Product extends JsonResource */ private function specialPriceInfo() { - if($this->type == 'configurable') + if($this->type == 'configurable' && $variant = $this->product->getTypeInstance()->getMinPriceVariant()) { - $variant = $this->product->getTypeInstance()->getMinPriceVariant(); $product = $variant->product; }else{ diff --git a/packages/Sarga/Shop/src/Repositories/MenuRepository.php b/packages/Sarga/Shop/src/Repositories/MenuRepository.php index a9c0138b9..d3f75d71f 100644 --- a/packages/Sarga/Shop/src/Repositories/MenuRepository.php +++ b/packages/Sarga/Shop/src/Repositories/MenuRepository.php @@ -48,4 +48,42 @@ class MenuRepository extends Repository return $menu; } + + public function update(array $data, $id) + { + $menu = $this->find($id); + } + + /** + * Set same value to all locales in category. + * + * To Do: Move column from the `category_translations` to `category` table. And remove + * this created method. + * + * @param array $data + * @param string $attributeNames + * @return array + */ + private function setSameAttributeValueToAllLocale(array $data, ...$attributeNames) + { + $requestedLocale = core()->getRequestedLocaleCode(); + + $model = app()->make($this->model()); + + foreach ($attributeNames as $attributeName) { + foreach (core()->getAllLocales() as $locale) { + if ($requestedLocale == $locale->code) { + foreach ($model->translatedAttributes as $attribute) { + if ($attribute === $attributeName) { + $data[$locale->code][$attribute] = isset($data[$requestedLocale][$attribute]) + ? $data[$requestedLocale][$attribute] + : $data[$data['locale']][$attribute]; + } + } + } + } + } + + return $data; + } } \ No newline at end of file