bianjunhui 17 ساعت پیش
والد
کامیت
6d61216244
1فایلهای تغییر یافته به همراه9 افزوده شده و 4 حذف شده
  1. 9 4
      packages/Webkul/BagistoApi/src/State/FilterableAttributesProvider.php

+ 9 - 4
packages/Webkul/BagistoApi/src/State/FilterableAttributesProvider.php

@@ -132,6 +132,11 @@ class FilterableAttributesProvider implements ProviderInterface
         $attributeId = $item->id;
         $column = $item->type === 'select' ? 'integer_value' : 'text_value';
 
+        // Table aliases are prefixed by Laravel (e.g. "pav" becomes "ly_pav"),
+        // so raw SQL fragments must use the prefixed alias explicitly.
+        $prefix = DB::getTablePrefix();
+        $alias = $prefix.'pav';
+
         $countQuery = DB::table('product_attribute_values as pav')
             ->join('product_attribute_values as pav_status', function ($join) {
                 $join->on('pav_status.product_id', '=', 'pav.product_id')
@@ -158,12 +163,12 @@ class FilterableAttributesProvider implements ProviderInterface
         if ($column === 'integer_value') {
             $counts = (clone $countQuery)
                 ->whereIn('pav.integer_value', $optionIds)
-                ->selectRaw('pav.integer_value as option_id, COUNT(DISTINCT pav.product_id) as total')
+                ->selectRaw($alias.'.integer_value as option_id, COUNT(DISTINCT '.$alias.'.product_id) as total')
                 ->groupBy('pav.integer_value')
                 ->pluck('total', 'option_id')
                 ->toArray();
         } else {
-            $counts = $this->countMultiSelectOptions(clone $countQuery, $optionIds);
+            $counts = $this->countMultiSelectOptions(clone $countQuery, $optionIds, $alias);
         }
 
         foreach ($options as $option) {
@@ -175,11 +180,11 @@ class FilterableAttributesProvider implements ProviderInterface
      * Count products for multiselect/checkbox options whose values are stored
      * as comma-separated option ids in the text_value column.
      */
-    private function countMultiSelectOptions($query, array $optionIds): array
+    private function countMultiSelectOptions($query, array $optionIds, string $alias): array
     {
         $rows = $query
             ->whereNotNull('pav.text_value')
-            ->selectRaw('pav.text_value, COUNT(DISTINCT pav.product_id) as total')
+            ->selectRaw($alias.'.text_value, COUNT(DISTINCT '.$alias.'.product_id) as total')
             ->groupBy('pav.text_value')
             ->get();