Index.php 22.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
        $productPrimaryKey = Yii::$service->product->getPrimaryKey();
T
Terry 已提交
60 61
        $reviewHelper = $this->_reviewHelper;
        $reviewHelper::initReviewConfig();
T
Terry 已提交
62
        list($review_count, $reviw_rate_star_average, $reviw_rate_star_info) = $reviewHelper::getReviewAndStarCount($this->_product);
63
        $this->filterProductImg($this->_product['image']);
64 65
        $groupAttrInfo = Yii::$service->product->getGroupAttrInfo($this->_product['attr_group']);
        $groupAttrArr = $this->getGroupAttrArr($groupAttrInfo);
_
__FresHmaN 已提交
66
        return [
67
            'groupAttrArr'              => $groupAttrArr,
T
Terry 已提交
68
            'name'                      => Yii::$service->store->getStoreAttrVal($this->_product['name'], 'name'),
69 70
            'image_thumbnails'          => $this->_image_thumbnails,
            'image_detail'              => $this->_image_detail,
T
Terry 已提交
71
            'sku'                       => $this->_product['sku'],
72
            'package_number'            => $this->_product['package_number'],
T
Terry 已提交
73 74 75 76
            'spu'                       => $this->_product['spu'],
            'attr_group'                => $this->_product['attr_group'],
            'review_count'              => $review_count,
            'reviw_rate_star_average'   => $reviw_rate_star_average,
T
Terry 已提交
77
            'reviw_rate_star_info'      => $reviw_rate_star_info,
T
Terry 已提交
78 79
            'price_info'                => $this->getProductPriceInfo(),
            'tier_price'                => $this->_product['tier_price'],
80
            'media_size' => [
T
Terry 已提交
81 82 83
                'small_img_width'       => $productImgSize['small_img_width'],
                'small_img_height'      => $productImgSize['small_img_height'],
                'middle_img_width'      => $productImgSize['middle_img_width'],
_
__FresHmaN 已提交
84
            ],
T
Terry 已提交
85 86 87 88
            'productImgMagnifier'       => $productImgMagnifier,
            'options'                   => $this->getSameSpuInfo(),
            'custom_option'             => $this->_product['custom_option'],
            'description'               => Yii::$service->store->getStoreAttrVal($this->_product['description'], 'description'),
T
Terry 已提交
89
            '_id'                       => $this->_product[$productPrimaryKey],
T
Terry 已提交
90
            'buy_also_buy'              => $this->getProductBySkus($skus),
_
__FresHmaN 已提交
91 92
        ];
    }
93 94
    
    public function getGroupAttrArr($groupAttrInfo){
95
        $gArr = [];
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        // 增加重量,长宽高,体积重等信息
        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';
        }
117 118 119 120 121 122
        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 已提交
123
                    // get translate 
124 125
                    if (isset($info['display']['lang']) && $info['display']['lang'] && is_array($attrVal)) {
                        $attrVal = Yii::$service->store->getStoreAttrVal($attrVal, $attr);
T
Terry 已提交
126
                    } else if ($attrVal && !is_array($attrVal)) {
127
                        $attrVal = Yii::$service->page->translate->__($attrVal);
128
                    }
T
Terry 已提交
129 130
                    $attr = Yii::$service->page->translate->__($attr);
                    $gArr[$attr] = $attrVal;
131 132 133 134 135 136 137 138 139 140 141 142 143
                } else if (isset($this->_product['attr_group_info']) && is_array($this->_product['attr_group_info'])) {
                    $attr_group_info = $this->_product['attr_group_info'];
                    if (isset($attr_group_info[$attr]) && $attr_group_info[$attr]) {
                        $attrVal = $attr_group_info[$attr];
                        // get translate 
                        if (isset($info['display']['lang']) && $info['display']['lang'] && is_array($attrVal)) {
                            $attrVal = Yii::$service->store->getStoreAttrVal($attrVal, $attr);
                        } else if ($attrVal && !is_array($attrVal)) {
                            $attrVal = Yii::$service->page->translate->__($attrVal);
                        }
                        $attr = Yii::$service->page->translate->__($attr);
                        $gArr[$attr] = $attrVal;
                    }
144 145 146
                }
            }
        }
147
        
148 149
        return $gArr;
    }
150
    
151
    /**
152
     * @param $product_images | Array ,产品的图片属性
153 154 155 156 157 158 159
     * 根据图片数组,得到橱窗图,和描述图
     * 橱窗图:在产品详细页面顶部,放大镜显示部分的产品列表
     * 描述图,在产品description文字描述后面显示的产品图片。
     */
    public function filterProductImg($product_images){
        $this->_image_thumbnails        = $product_images;
        //$this->_image_detail['gallery'] = $product_images['gallery'];
160
        if (isset($product_images['gallery']) && is_array($product_images['gallery'])) {
161 162
            $thumbnails_arr = [];
            $detail_arr     = [];
163
            foreach ($product_images['gallery'] as $one) {
164 165
                $is_thumbnails  = $one['is_thumbnails'];
                $is_detail      = $one['is_detail'];
166
                if ($is_thumbnails == 1) {
167 168
                    $thumbnails_arr[]   = $one;
                }
169
                if ($is_detail == 1) {
170 171 172 173 174 175
                    $detail_arr[]       = $one;
                }
            }
            $this->_image_thumbnails['gallery'] = $thumbnails_arr;
            $this->_image_detail     = $detail_arr;
        }
176
        if (isset($product_images['main']['is_detail']) && $product_images['main']['is_detail'] == 1 ) {
177 178 179 180 181
            $this->_image_detail[] = $product_images['main'];
        }
        
    }
    
182
    /**废弃
183 184 185
     * @param $data | Array 和当前产品的spu相同,但sku不同的产品  数组。
     * @param $current_size | String 当前产品的size值
     * @param $current_color | String 当前产品的颜色值
_
__FresHmaN 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198
     * @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);
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        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 已提交
240 241 242 243 244
                }
            }
        }
        return [$all_attr1, $all_attr2, $attr1_2_attr2, $attr2_2_attr1];
    }
T
Terry 已提交
245

T
Terry 已提交
246
    /**
247
     * @param $select | Array , 需要查询的字段。
T
Terry 已提交
248
     * 得到当前spu下面的所有的sku的数组、
249
     * 这个是为了产品详细页面的spu下面的产品切换,譬如同一spu下的不同的颜色尺码切换。
T
Terry 已提交
250 251 252
     */
    protected function getSpuData($select)
    {
253
        $spu = $this->_product['spu'];
T
Terry 已提交
254
        return Yii::$service->product->spuCollData($select, $this->_productSpuAttrArr, $spu);
T
Terry 已提交
255
    }
T
Terry 已提交
256

_
__FresHmaN 已提交
257
    /**
258 259 260 261
     * @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 已提交
262 263 264
     */
    protected function getSameSpuInfo()
    {
265
        $groupAttr = Yii::$service->product->getGroupAttr($this->_product['attr_group']);
T
Terry 已提交
266
        // 当前的产品对应的spu属性组的属性,譬如 ['color','size','myyy']
T
Terry 已提交
267
        $this->_productSpuAttrArr = Yii::$service->product->getSpuAttr($this->_product['attr_group']);
268 269
        //var_dump($this->_productSpuAttrArr);exit;
        $this->_spuAttrShowAsImg = Yii::$service->product->getSpuImgAttr($this->_product['attr_group']);
T
Terry 已提交
270
        if (!is_array($this->_productSpuAttrArr) || empty($this->_productSpuAttrArr)) {
_
__FresHmaN 已提交
271 272
            return;
        }
T
Terry 已提交
273 274
        // 当前的spu属性对应值数组 $['color'] = 'red'

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

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

T
Terry 已提交
322
        $spuShowArr = [];
T
Terry 已提交
323
        foreach ($spuValColl as $spuAttr => $attrValArr) {
T
Terry 已提交
324
            $attr_coll = [];
325 326 327 328 329
            if (is_array($attrValArr)) {
                foreach ($attrValArr as $attrVal) {
                    $attr_info = $this->getSpuAttrInfo($spuAttr, $attrVal, $reverse_val_spu);
                    $attr_coll[] = $attr_info;
                }
T
Terry 已提交
330 331 332 333 334 335
            }
            $spuShowArr[] = [
                'label' => $spuAttr,
                'value' => $attr_coll,
            ];
        }
T
Terry 已提交
336

T
Terry 已提交
337 338
        return $spuShowArr;
    }
339
    // spu属性部分
T
Terry 已提交
340 341
    protected function getSpuAttrInfo($spuAttr, $attrVal, $reverse_val_spu)
    {
T
Terry 已提交
342 343
        $current = $this->_currentSpuAttrValArr;
        $active = false;
T
Terry 已提交
344 345
        if (isset($this->_currentSpuAttrValArr[$spuAttr])) {
            if ($attrVal != $this->_currentSpuAttrValArr[$spuAttr]) {
T
Terry 已提交
346
                $current[$spuAttr] = $attrVal;
T
Terry 已提交
347
            } else {
T
Terry 已提交
348 349 350
                $active = true;
            }
        }
351 352
        $reverse_key = $this->generateSpuReverseKey($current);
        $return = [];
T
Terry 已提交
353
        $return['attr_val'] = $attrVal;
354
        $return['active'] = 'noactive';
T
Terry 已提交
355

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

T
Terry 已提交
383 384
        return $return;
    }
T
Terry 已提交
385 386 387

    protected function generateSpuReverseKey($one)
    {
T
Terry 已提交
388
        $reverse_key = '';
389 390 391 392 393
        if (is_array($this->_productSpuAttrArr)) {
            foreach ($this->_productSpuAttrArr as $spuAttr) {
                $spuValColl[$spuAttr][] = $one[$spuAttr];
                $reverse_key .= $one[$spuAttr];
            }
_
__FresHmaN 已提交
394
        }
T
Terry 已提交
395
        return  $reverse_key;
_
__FresHmaN 已提交
396 397 398
    }

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

        return $data;
    }

    /**
     * @return array
     *               得到当前货币状态下的产品的价格和特价信息。
     */
    protected function getProductPriceInfo()
    {
432
        $price = $this->_product['price'];
_
__FresHmaN 已提交
433
        $special_price = $this->_product['special_price'];
434 435
        $special_from = $this->_product['special_from'];
        $special_to = $this->_product['special_to'];
_
__FresHmaN 已提交
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450

        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()
    {
451 452
        $primaryKey = Yii::$service->product->getPrimaryKey();
        $primaryVal = Yii::$app->request->get($primaryKey);
_
__FresHmaN 已提交
453
        $this->_primaryVal = $primaryVal;
454
        $product = Yii::$service->product->getByPrimaryKey($primaryVal);
455 456 457 458 459 460 461 462 463 464
        if ($product) {
            $enableStatus = Yii::$service->product->getEnableStatus();
            if ($product['status'] != $enableStatus){
                
                return false;
            }
        } else {
            
            return false;
        }
465
        $this->_product = $product;
_
__FresHmaN 已提交
466
        Yii::$app->view->registerMetaTag([
467
            'name' => 'keywords',
_
__FresHmaN 已提交
468 469 470
            'content' => Yii::$service->store->getStoreAttrVal($product['meta_keywords'], 'meta_keywords'),
        ]);
        Yii::$app->view->registerMetaTag([
471
            'name' => 'description',
_
__FresHmaN 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
            '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;
490
        return true;
_
__FresHmaN 已提交
491 492 493 494 495 496 497 498 499 500
    }

    // 面包屑导航
    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');
501
                    $parent_url = Yii::$service->url->getUrl($info['url_key']);
_
__FresHmaN 已提交
502 503 504 505 506 507 508 509
                    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;
        }
    }
510
    // 买了的人还买了什么,通过产品字段取出来sku,然后查询得到。
_
__FresHmaN 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523
    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];
524 525 526
                $products = Yii::$service->product->getProducts($filter);
                //var_dump($products);
                $products = Yii::$service->category->product->convertToCategoryInfo($products);
_
__FresHmaN 已提交
527 528 529 530 531 532

                return $products;
            }
        }
    }
}