Skip to content

Commit

Permalink
[FIX] Product Attributes and Translates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Feb 23, 2024
1 parent df152b1 commit f331a63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions module/sCommerceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/sCommerceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/sCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit f331a63

Please sign in to comment.