|
@@ -30,6 +30,7 @@ class LiquidTagProduct extends AbstractBlock
|
|
|
$this->quantity = 0;
|
|
|
$this->limit = 10;
|
|
|
$this->categoryId = 0;
|
|
|
+ $this->categoryIds = '';
|
|
|
$this->templateFile = null;
|
|
|
|
|
|
// 正则表达式解析传入的参数
|
|
@@ -57,6 +58,9 @@ class LiquidTagProduct extends AbstractBlock
|
|
|
case 'category_id':
|
|
|
$this->categoryId = (int)$value;
|
|
|
break;
|
|
|
+ case 'category_ids':
|
|
|
+ $this->categoryIds = $value;
|
|
|
+ break;
|
|
|
case 'template':
|
|
|
$this->templateFile = $value;
|
|
|
break;
|
|
@@ -72,6 +76,9 @@ class LiquidTagProduct extends AbstractBlock
|
|
|
return $this->renderList();
|
|
|
} elseif ($this->mode === 'single') {
|
|
|
return $this->renderSingle();
|
|
|
+ } elseif ($this->mode === 'lists') {
|
|
|
+ //支持多分类
|
|
|
+ return $this->renderLists();
|
|
|
}
|
|
|
|
|
|
// 如果模式不正确,返回空字符串
|
|
@@ -91,6 +98,20 @@ class LiquidTagProduct extends AbstractBlock
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
+ private function renderLists()
|
|
|
+ {
|
|
|
+ $categoryIds = explode(',', $this->categoryIds);
|
|
|
+ // 从数据库获取产品列表
|
|
|
+ $products = DistProduct::getProductsByCategoryIds($categoryIds, $this->limit);
|
|
|
+
|
|
|
+ if ($products->count() > 0) {
|
|
|
+ return $this->renderTemplate(['products' => $products->toArray()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有产品,返回空字符串
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
private function renderSingle()
|
|
|
{
|
|
|
// 从数据库获取单个产品信息
|