diff --git a/module/sCommerceModule.php b/module/sCommerceModule.php index 3bd7c2d..fd992b0 100644 --- a/module/sCommerceModule.php +++ b/module/sCommerceModule.php @@ -75,11 +75,14 @@ $requestId = (int)request()->input('i', 0); $product = sCommerce::getProduct($requestId); - $categoryParentsIds = $sCommerceController->categoryParentsIds($product->category); + $categoryParentsIds = [0]; + if ($product->category) { + $categoryParentsIds = $sCommerceController->categoryParentsIds($product->category); + } $attributes = sAttribute::whereHas('categories', function ($q) use ($categoryParentsIds) { $q->whereIn('category', $categoryParentsIds); })->get(); - if ($attributes) { + if ($attributes->count()) { $tabs[] = 'prodattributes'; } diff --git a/src/Controllers/sCommerceController.php b/src/Controllers/sCommerceController.php index 19afa60..54e0583 100644 --- a/src/Controllers/sCommerceController.php +++ b/src/Controllers/sCommerceController.php @@ -424,7 +424,7 @@ protected function getParentsIds(int $categoryId): array $category = sCategory::find($categoryId); $parent = $category->getParent(); $this->categories = array_merge($this->categories, [$parent->id]); - if ($categoryId != evo()->getConfig('catalog_root', evo()->getConfig('site_start', 1))) { + if ($parent->id && $categoryId != evo()->getConfig('catalog_root', evo()->getConfig('site_start', 1))) { $this->categories = $this->getParentsIds($parent->id); } } diff --git a/src/sCommerce.php b/src/sCommerce.php index 3e575f9..df95b74 100644 --- a/src/sCommerce.php +++ b/src/sCommerce.php @@ -8,6 +8,7 @@ use Seiger\sCommerce\Controllers\sCommerceController; use Seiger\sCommerce\Models\sAttribute; use Seiger\sCommerce\Models\sProduct; +use Seiger\sCommerce\Models\sProductTranslate; class sCommerce { @@ -25,7 +26,16 @@ public function getProduct(int $productId, string $lang = ''): object $lang = $sCommerceController->langDefault(); } - return sProduct::lang($lang)->whereProduct($productId)->first() ?? new sProduct(); + $product = sProduct::lang($lang)->whereProduct($productId)->first(); + + if (!$product) { + $translate = sProductTranslate::whereProduct($productId)->first(); + if ($translate) { + $product = sProduct::lang($translate->lang)->whereProduct($productId)->first(); + } + } + + return $product ?? new sProduct(); } /**