Index.php 21.5 KB
Newer Older
_
__FresHmaN 已提交
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecshop\app\apphtml5\modules\Catalog\block\product;

12
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
_
__FresHmaN 已提交
13 14 15 16 17 18 19 20
use Yii;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class Index
{
21
    // 当前产品
_
__FresHmaN 已提交
22
    protected $_product;
23
    // 产品页面的title
_
__FresHmaN 已提交
24
    protected $_title;
25
    // 产品的主键对应的值
_
__FresHmaN 已提交
26
    protected $_primaryVal;
27
    // 产品的spu属性数组。
T
Terry 已提交
28
    protected $_productSpuAttrArr;
29
    // 以图片方式显示的spu属性
T
Terry 已提交
30
    protected $_spuAttrShowAsImg;
31 32 33 34
    // 在产品详细页面,在橱窗图部分,以放大镜的方式显示的产品图片列表
    protected $_image_thumbnails;
    // 在产品详细页面,在产品描述部分显示的产品图片列表
    protected $_image_detail;
35 36 37 38 39
    /**
     * 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
     */
    protected $_reviewHelperName = '\fecshop\app\apphtml5\modules\Catalog\helpers\Review';
    protected $_reviewHelper;
40 41
    protected $_currentSpuAttrValArr;
     protected $_spuAttrShowAsImgArr;
42 43 44 45 46 47 48 49 50
    
    public function __construct()
    {
        /**
         * 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
         */
        list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);  
        
    }
_
__FresHmaN 已提交
51 52 53 54
    public function getLastData()
    {
        $productImgSize = Yii::$app->controller->module->params['productImgSize'];
        $productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier'];
55
        if (!$this->initProduct()) {
56 57 58
            Yii::$service->url->redirect404();
            return;
        }
T
Terry 已提交
59 60
        $reviewHelper = $this->_reviewHelper;
        $reviewHelper::initReviewConfig();
T
Terry 已提交
61
        list($review_count, $reviw_rate_star_average, $reviw_rate_star_info) = $reviewHelper::getReviewAndStarCount($this->_product);
62
        $this->filterProductImg($this->_product['image']);
63 64
        $groupAttrInfo = Yii::$service->product->getGroupAttrInfo($this->_product['attr_group']);
        $groupAttrArr = $this->getGroupAttrArr($groupAttrInfo);
_
__FresHmaN 已提交
65
        return [
66
            'groupAttrArr'              => $groupAttrArr,
T
Terry 已提交
67
            'name'                      => Yii::$service->store->getStoreAttrVal($this->_product['name'], 'name'),
68 69
            'image_thumbnails'          => $this->_image_thumbnails,
            'image_detail'              => $this->_image_detail,
T
Terry 已提交
70
            'sku'                       => $this->_product['sku'],
71
            'package_number'            => $this->_product['package_number'],
T
Terry 已提交
72 73 74 75
            'spu'                       => $this->_product['spu'],
            'attr_group'                => $this->_product['attr_group'],
            'review_count'              => $review_count,
            'reviw_rate_star_average'   => $reviw_rate_star_average,
T
Terry 已提交
76
            'reviw_rate_star_info'      => $reviw_rate_star_info,
T
Terry 已提交
77 78
            'price_info'                => $this->getProductPriceInfo(),
            'tier_price'                => $this->_product['tier_price'],
79
            'media_size' => [
T
Terry 已提交
80 81 82
                'small_img_width'       => $productImgSize['small_img_width'],
                'small_img_height'      => $productImgSize['small_img_height'],
                'middle_img_width'      => $productImgSize['middle_img_width'],
_
__FresHmaN 已提交
83
            ],
T
Terry 已提交
84 85 86 87 88 89
            'productImgMagnifier'       => $productImgMagnifier,
            'options'                   => $this->getSameSpuInfo(),
            'custom_option'             => $this->_product['custom_option'],
            'description'               => Yii::$service->store->getStoreAttrVal($this->_product['description'], 'description'),
            '_id'                       => $this->_product['_id'],
            'buy_also_buy'              => $this->getProductBySkus($skus),
_
__FresHmaN 已提交
90 91
        ];
    }
92 93
    
    public function getGroupAttrArr($groupAttrInfo){
94
        $gArr = [];
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        // 增加重量,长宽高,体积重等信息
        if ($this->_product['weight']) {
            $weightName = Yii::$service->page->translate->__('weight');
            $gArr[$weightName] = $this->_product['weight'].' Kg';
        }
        if ($this->_product['long']) {
            $longName = Yii::$service->page->translate->__('long');
            $gArr[$longName] = $this->_product['long'].' Cm';
        }
        if ($this->_product['width']) {
            $widthName = Yii::$service->page->translate->__('width');
            $gArr[$widthName] = $this->_product['width'].' Cm';
        }
        if ($this->_product['high']) {
            $highName = Yii::$service->page->translate->__('high');
            $gArr[$highName] = $this->_product['high'].' Cm';
        }
        if ($this->_product['volume_weight']) {
            $volumeWeightName = Yii::$service->page->translate->__('volume weight');
            $gArr[$volumeWeightName] = $this->_product['volume_weight'].' Kg';
        }
116 117 118 119 120 121
        if (is_array($groupAttrInfo)) {
            foreach ($groupAttrInfo as $attr => $info) {
                //var_dump($attr);
                //var_dump($info);
                if (isset($this->_product[$attr]) && $this->_product[$attr]) {
                    $attrVal = $this->_product[$attr];
T
Terry 已提交
122
                    // get translate 
123 124
                    if (isset($info['display']['lang']) && $info['display']['lang'] && is_array($attrVal)) {
                        $attrVal = Yii::$service->store->getStoreAttrVal($attrVal, $attr);
T
Terry 已提交
125
                    } else if ($attrVal && !is_array($attrVal)) {
126
                        $attrVal = Yii::$service->page->translate->__($attrVal);
127
                    }
T
Terry 已提交
128 129
                    $attr = Yii::$service->page->translate->__($attr);
                    $gArr[$attr] = $attrVal;
130 131 132
                }
            }
        }
133
        
134 135 136 137 138 139 140 141 142 143 144
        return $gArr;
    }
    /**
     * @property $product_images | Array ,产品的图片属性
     * 根据图片数组,得到橱窗图,和描述图
     * 橱窗图:在产品详细页面顶部,放大镜显示部分的产品列表
     * 描述图,在产品description文字描述后面显示的产品图片。
     */
    public function filterProductImg($product_images){
        $this->_image_thumbnails        = $product_images;
        //$this->_image_detail['gallery'] = $product_images['gallery'];
145
        if (isset($product_images['gallery']) && is_array($product_images['gallery'])) {
146 147
            $thumbnails_arr = [];
            $detail_arr     = [];
148
            foreach ($product_images['gallery'] as $one) {
149 150
                $is_thumbnails  = $one['is_thumbnails'];
                $is_detail      = $one['is_detail'];
151
                if ($is_thumbnails == 1) {
152 153
                    $thumbnails_arr[]   = $one;
                }
154
                if ($is_detail == 1) {
155 156 157 158 159 160
                    $detail_arr[]       = $one;
                }
            }
            $this->_image_thumbnails['gallery'] = $thumbnails_arr;
            $this->_image_detail     = $detail_arr;
        }
161
        if (isset($product_images['main']['is_detail']) && $product_images['main']['is_detail'] == 1 ) {
162 163 164 165 166
            $this->_image_detail[] = $product_images['main'];
        }
        
    }
    
167
    /**废弃
_
__FresHmaN 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
     * @property $data | Array 和当前产品的spu相同,但sku不同的产品  数组。
     * @property $current_size | String 当前产品的size值
     * @property $current_color | String 当前产品的颜色值
     * @return array 分别为
     *               $all_attr1 所有的颜色数组
     *               $all_attr2  所有的尺码数组
     *               $attr1_2_attr2 当前尺码下的所有颜色数组。
     *               $attr2_2_attr1 当前颜色下的所有尺码数组。
     */
    protected function getAttr1AndAttr2Info($data, $current_attr1, $current_attr2, $attr1, $attr2)
    {
        $all_attr1 = [];
        $all_attr2 = [];
        $attr1_2_attr2 = [];
        $attr2_2_attr1 = [];
        //var_dump($data);
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
        if (is_array($data) && !empty($data)) {
            foreach ($data as $one) {
                $attr1_val = isset($one[$attr1]) ? $one[$attr1] : '';
                $attr2_val = isset($one[$attr2]) ? $one[$attr2] : '';
                //echo $attr1_val;
                //echo $size;
                //echo '##';
                $image = $one['image'];
                $name = $one['name'];
                $url_key = $one['url_key'];
                if ($attr1_val || $attr2_val) {
                    if ($attr1_val) {
                        $all_attr1[$attr1_val] = [
                            'name'        => $name,
                            'image'    => $image,
                            'url_key'    => $url_key,
                        ];
                    }
                    if ($attr2_val) {
                        $all_attr2[$attr2_val] = [
                            'name'        => $name,
                            'image'    => $image,
                            'url_key'    => $url_key,
                        ];
                    }
                    //echo $attr2_val.'#'.$current_attr2;
                    //echo '<br/>';
                    if ($attr2_val && $current_attr2 == $attr2_val) {
                        $attr1_2_attr2[$attr1_val] = [
                            'name'        => $name,
                            'image'    => $image,
                            'url_key'    => $url_key,
                        ];
                    }
                    if ($attr1_val && $current_attr1 == $attr1_val) {
                        $attr2_2_attr1[$attr2_val] = [
                            'name'        => $name,
                            'image'    => $image,
                            'url_key'    => $url_key,
                        ];
                    }
_
__FresHmaN 已提交
225 226 227 228 229
                }
            }
        }
        return [$all_attr1, $all_attr2, $attr1_2_attr2, $attr2_2_attr1];
    }
T
Terry 已提交
230

T
Terry 已提交
231
    /**
232
     * @property $select | Array , 需要查询的字段。
T
Terry 已提交
233
     * 得到当前spu下面的所有的sku的数组、
234
     * 这个是为了产品详细页面的spu下面的产品切换,譬如同一spu下的不同的颜色尺码切换。
T
Terry 已提交
235 236 237
     */
    protected function getSpuData($select)
    {
238
        $spu = $this->_product['spu'];
T
Terry 已提交
239 240
        $select = array_merge($select, $this->_productSpuAttrArr);

T
Terry 已提交
241
        $filter = [
242 243
            'select'    => $select,
            'where'            => [
T
Terry 已提交
244 245 246 247 248
                ['spu' => $spu],
            ],
            'asArray' => true,
        ];
        $coll = Yii::$service->product->coll($filter);
T
Terry 已提交
249

T
Terry 已提交
250 251
        return $coll['coll'];
    }
T
Terry 已提交
252

_
__FresHmaN 已提交
253
    /**
254 255 256 257
     * @return Array得到spu下面的sku的spu属性的数据。用于在产品
     * 得到spu下面的sku的spu属性的数据。用于在产品详细页面显示其他的sku
     * 譬如页面:https://fecshop.appfront.fancyecommerce.com/raglan-sleeves-letter-printed-crew-neck-sweatshirt-53386451-77774122
     * 该spu的其他sku的颜色尺码也在这里显示出来。
_
__FresHmaN 已提交
258 259 260
     */
    protected function getSameSpuInfo()
    {
261
        $groupAttr = Yii::$service->product->getGroupAttr($this->_product['attr_group']);
T
Terry 已提交
262
        // 当前的产品对应的spu属性组的属性,譬如 ['color','size','myyy']
T
Terry 已提交
263
        $this->_productSpuAttrArr = Yii::$service->product->getSpuAttr($this->_product['attr_group']);
264 265
        //var_dump($this->_productSpuAttrArr);exit;
        $this->_spuAttrShowAsImg = Yii::$service->product->getSpuImgAttr($this->_product['attr_group']);
T
Terry 已提交
266
        if (!is_array($this->_productSpuAttrArr) || empty($this->_productSpuAttrArr)) {
_
__FresHmaN 已提交
267 268
            return;
        }
T
Terry 已提交
269 270
        // 当前的spu属性对应值数组 $['color'] = 'red'

T
Terry 已提交
271
        $this->_currentSpuAttrValArr = [];
T
Terry 已提交
272
        foreach ($this->_productSpuAttrArr as $spuAttr) {
T
Terry 已提交
273
            $spuAttrVal = $this->_product[$spuAttr];
T
Terry 已提交
274
            if ($spuAttrVal) {
T
Terry 已提交
275
                $this->_currentSpuAttrValArr[$spuAttr] = $spuAttrVal;
T
Terry 已提交
276
            } else {
T
Terry 已提交
277
                // 如果某个spuAttr的值为空,则退出,这个说明产品数据有问题。
T
Terry 已提交
278
                return;
T
Terry 已提交
279
            }
_
__FresHmaN 已提交
280
        }
T
Terry 已提交
281
        // 得到当前的spu下面的所有的值
282 283
        $select = ['name', 'image', 'url_key'];
        $data = $this->getSpuData($select);
T
Terry 已提交
284
        $spuValColl = [];
T
Terry 已提交
285
        // 通过值,找到spu。
T
Terry 已提交
286
        $reverse_val_spu = [];
T
Terry 已提交
287 288
        if (is_array($data) && !empty($data)) {
            foreach ($data as $one) {
T
Terry 已提交
289
                $reverse_key = '';
T
Terry 已提交
290
                foreach ($this->_productSpuAttrArr as $spuAttr) {
T
Terry 已提交
291 292 293
                    $spuValColl[$spuAttr][$one[$spuAttr]] = $one[$spuAttr];
                    $reverse_key .= $one[$spuAttr];
                }
T
Terry 已提交
294

T
Terry 已提交
295 296
                //$active = 'class="active"';
                $one['main_img'] = isset($one['image']['main']['image']) ? $one['image']['main']['image'] : '';
297
                $one['url'] = Yii::$service->url->getUrl($one['url_key']);
T
Terry 已提交
298
                $reverse_val_spu[$reverse_key] = $one;
299
                $showAsImgVal = $one[$this->_spuAttrShowAsImg];
T
Terry 已提交
300 301
                if ($showAsImgVal) {
                    if (!isset($this->_spuAttrShowAsImgArr[$this->_spuAttrShowAsImg])) {
T
Terry 已提交
302 303 304 305
                        $this->_spuAttrShowAsImgArr[$showAsImgVal] = $one;
                    }
                }
            }
_
__FresHmaN 已提交
306
        }
T
Terry 已提交
307 308
        // 得到各个spu属性对应的值的集合。
        foreach ($spuValColl as $spuAttr => $attrValArr) {
T
Terry 已提交
309
            $spuValColl[$spuAttr] = array_unique($attrValArr);
T
Terry 已提交
310
            $spuValColl[$spuAttr] = $this->sortSpuAttr($spuAttr, $spuValColl[$spuAttr]);
T
Terry 已提交
311
        }
T
Terry 已提交
312

T
Terry 已提交
313
        $spuShowArr = [];
T
Terry 已提交
314
        foreach ($spuValColl as $spuAttr => $attrValArr) {
T
Terry 已提交
315
            $attr_coll = [];
316 317 318 319 320
            if (is_array($attrValArr)) {
                foreach ($attrValArr as $attrVal) {
                    $attr_info = $this->getSpuAttrInfo($spuAttr, $attrVal, $reverse_val_spu);
                    $attr_coll[] = $attr_info;
                }
T
Terry 已提交
321 322 323 324 325 326
            }
            $spuShowArr[] = [
                'label' => $spuAttr,
                'value' => $attr_coll,
            ];
        }
T
Terry 已提交
327

T
Terry 已提交
328 329
        return $spuShowArr;
    }
330
    // spu属性部分
T
Terry 已提交
331 332
    protected function getSpuAttrInfo($spuAttr, $attrVal, $reverse_val_spu)
    {
T
Terry 已提交
333 334
        $current = $this->_currentSpuAttrValArr;
        $active = false;
T
Terry 已提交
335 336
        if (isset($this->_currentSpuAttrValArr[$spuAttr])) {
            if ($attrVal != $this->_currentSpuAttrValArr[$spuAttr]) {
T
Terry 已提交
337
                $current[$spuAttr] = $attrVal;
T
Terry 已提交
338
            } else {
T
Terry 已提交
339 340 341
                $active = true;
            }
        }
342 343
        $reverse_key = $this->generateSpuReverseKey($current);
        $return = [];
T
Terry 已提交
344
        $return['attr_val'] = $attrVal;
345
        $return['active'] = 'noactive';
T
Terry 已提交
346

T
Terry 已提交
347
        //echo $reverse_key."<br/>";
T
Terry 已提交
348
        if (isset($reverse_val_spu[$reverse_key]) && is_array($reverse_val_spu[$reverse_key])) {
T
Terry 已提交
349 350
            $return['active'] = 'active';
            $arr = $reverse_val_spu[$reverse_key];
T
Terry 已提交
351 352
            foreach ($arr as $k=>$v) {
                $return[$k] = $v;
T
Terry 已提交
353
            }
T
Terry 已提交
354
            if ($spuAttr == $this->_spuAttrShowAsImg) {
T
Terry 已提交
355 356
                $return['show_as_img'] = $arr['main_img'];
            }
T
Terry 已提交
357 358 359
        } else {
            // 如果是图片,不存在,则使用备用的。
            if ($spuAttr == $this->_spuAttrShowAsImg) {
T
Terry 已提交
360 361
                $return['active'] = 'active';
                $arr = $this->_spuAttrShowAsImgArr[$attrVal];
T
Terry 已提交
362 363 364
                if (is_array($arr) && !empty($arr)) {
                    foreach ($arr as $k=>$v) {
                        $return[$k] = $v;
T
Terry 已提交
365 366 367 368 369
                    }
                }
                $return['show_as_img'] = $arr['main_img'];
            }
        }
T
Terry 已提交
370
        if ($active) {
T
Terry 已提交
371 372
            $return['active'] = 'current';
        }
T
Terry 已提交
373

T
Terry 已提交
374 375
        return $return;
    }
T
Terry 已提交
376 377 378

    protected function generateSpuReverseKey($one)
    {
T
Terry 已提交
379
        $reverse_key = '';
380 381 382 383 384
        if (is_array($this->_productSpuAttrArr)) {
            foreach ($this->_productSpuAttrArr as $spuAttr) {
                $spuValColl[$spuAttr][] = $one[$spuAttr];
                $reverse_key .= $one[$spuAttr];
            }
_
__FresHmaN 已提交
385
        }
T
Terry 已提交
386
        return  $reverse_key;
_
__FresHmaN 已提交
387 388 389 390 391 392 393 394
    }

    /**
     *	@property $data | Array  各个尺码对应的产品数组
     *  @return array 排序后的数组
     *		该函数,按照在配置中的size的顺序,将$data中的数据进行排序,让其按照尺码的由小到大的顺序
     * 		排列,譬如 :s,m,l,xl,xxl,xxxl等
     */
T
Terry 已提交
395
    protected function sortSpuAttr($spuAttr, $data)
_
__FresHmaN 已提交
396 397 398 399
    {
        // 对size排序一下
        $size = [];
        $attr_group = $this->_product['attr_group'];
400 401
        $attrInfo = Yii::$service->product->getGroupAttrInfo($attr_group);
        $size_arr = isset($attrInfo[$spuAttr]['display']['data']) ? $attrInfo[$spuAttr]['display']['data'] : '';
_
__FresHmaN 已提交
402 403 404 405 406 407 408
        $d_arr = [];
        if (is_array($size_arr) && !empty($size_arr)) {
            foreach ($size_arr as $size) {
                if (isset($data[$size])) {
                    $d_arr[$size] = $data[$size];
                }
            }
T
Terry 已提交
409
            if (!empty($d_arr)) {
_
__FresHmaN 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422
                return $d_arr;
            }
        }

        return $data;
    }

    /**
     * @return array
     *               得到当前货币状态下的产品的价格和特价信息。
     */
    protected function getProductPriceInfo()
    {
423
        $price = $this->_product['price'];
_
__FresHmaN 已提交
424
        $special_price = $this->_product['special_price'];
425 426
        $special_from = $this->_product['special_from'];
        $special_to = $this->_product['special_to'];
_
__FresHmaN 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

        return Yii::$service->product->price->getCurrentCurrencyProductPriceInfo($price, $special_price, $special_from, $special_to);
    }

    /**
     * 初始化数据包括
     * 主键值:$this->_primaryVal
     * 当前产品对象:$this->_product
     * Meta keywords , Meta Description等信息的设置。
     * Title的设置。
     * 根据当前产品的attr_group(属性组信息)重新给Product Model增加相应的属性组信息
     * 然后,重新获取当前产品对象:$this->_product,此时加入了配置中属性组对应的属性。
     */
    protected function initProduct()
    {
442 443
        $primaryKey = Yii::$service->product->getPrimaryKey();
        $primaryVal = Yii::$app->request->get($primaryKey);
_
__FresHmaN 已提交
444
        $this->_primaryVal = $primaryVal;
445
        $product = Yii::$service->product->getByPrimaryKey($primaryVal);
446 447 448 449 450 451 452 453 454 455
        if ($product) {
            $enableStatus = Yii::$service->product->getEnableStatus();
            if ($product['status'] != $enableStatus){
                
                return false;
            }
        } else {
            
            return false;
        }
456
        $this->_product = $product;
_
__FresHmaN 已提交
457
        Yii::$app->view->registerMetaTag([
458
            'name' => 'keywords',
_
__FresHmaN 已提交
459 460 461
            'content' => Yii::$service->store->getStoreAttrVal($product['meta_keywords'], 'meta_keywords'),
        ]);
        Yii::$app->view->registerMetaTag([
462
            'name' => 'description',
_
__FresHmaN 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
            'content' => Yii::$service->store->getStoreAttrVal($product['meta_description'], 'meta_description'),
        ]);
        $this->_title = Yii::$service->store->getStoreAttrVal($product['meta_title'], 'meta_title');
        $name = Yii::$service->store->getStoreAttrVal($product['name'], 'name');
        //$this->breadcrumbs($name);
        $this->_title = $this->_title ? $this->_title : $name;
        Yii::$app->view->title = $this->_title;
        //$this->_where = $this->initWhere();

        // 通过上面查询的属性组,得到属性组对应的属性列表
        // 然后重新查询产品
        $attr_group = $this->_product['attr_group'];

        Yii::$service->product->addGroupAttrs($attr_group);

        // 重新查询产品信息。
        $product = Yii::$service->product->getByPrimaryKey($primaryVal);
        $this->_product = $product;
481
        return true;
_
__FresHmaN 已提交
482 483 484 485 486 487 488 489 490 491
    }

    // 面包屑导航
    protected function breadcrumbs($name)
    {
        if (Yii::$app->controller->module->params['category_breadcrumbs']) {
            $parent_info = Yii::$service->category->getAllParentInfo($this->_category['parent_id']);
            if (is_array($parent_info) && !empty($parent_info)) {
                foreach ($parent_info as $info) {
                    $parent_name = Yii::$service->store->getStoreAttrVal($info['name'], 'name');
492
                    $parent_url = Yii::$service->url->getUrl($info['url_key']);
_
__FresHmaN 已提交
493 494 495 496 497 498 499 500
                    Yii::$service->page->breadcrumbs->addItems(['name' => $parent_name, 'url' => $parent_url]);
                }
            }
            Yii::$service->page->breadcrumbs->addItems(['name' => $name]);
        } else {
            Yii::$service->page->breadcrumbs->active = false;
        }
    }
501
    // 买了的人还买了什么,通过产品字段取出来sku,然后查询得到。
_
__FresHmaN 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514
    protected function getProductBySkus($skus)
    {
        $buy_also_buy_sku = $this->_product['buy_also_buy_sku'];
        if ($buy_also_buy_sku) {
            $skus = explode(',', $buy_also_buy_sku);
            if (is_array($skus) && !empty($skus)) {
                $filter['select'] = [
                    'sku', 'spu', 'name', 'image',
                    'price', 'special_price',
                    'special_from', 'special_to',
                    'url_key', 'score',
                ];
                $filter['where'] = ['in', 'sku', $skus];
515 516 517
                $products = Yii::$service->product->getProducts($filter);
                //var_dump($products);
                $products = Yii::$service->category->product->convertToCategoryInfo($products);
_
__FresHmaN 已提交
518 519 520 521 522 523

                return $products;
            }
        }
    }
}