/** * 获取商品的扩展属性 * @param $product_id * @return array|bool */ public function getProductExtendAttrs($product_id) { if (empty($product_id)) { return false; } $extendInfo = ProductExtend::model()->findByAttributes(array('product_id' => $product_id)); if ($extendInfo) { $extendInfo = unserialize($extendInfo->other_info); } $productAttrNameList = $this->getProductExtendAttrList(); $attrArr = array(); if (!empty($extendInfo)) { foreach ($productAttrNameList as $k => $v) { if (empty($extendInfo[$k])) { continue; } $temp = array(); $temp['attr'] = $k; $temp['attr_name'] = $productAttrNameList[$k]; $temp['attr_content'] = $extendInfo[$k]; array_push($attrArr, $temp); } } return $attrArr; }
public function actionIndex() { $product_id = intval($_REQUEST['id']); $pInfo = Product::model()->getProductInfoById($product_id); if (empty($pInfo)) { $this->redirect('/?from=no_goods'); //跳转到首页 } $brandInfo = ''; if ($pInfo['brand_id']) { $brandInfo = Brand::model()->findByPk($pInfo['brand_id']); } $stock = Product::model()->getProductStock($product_id, $pInfo['is_multiple']); $attrList = ProductAttributes::model()->getProductAttrNameList(); $extendAttrList = ProductExtend::model()->getProductExtendAttrs($product_id); $is_like = Like::model()->getLikeStatus($this->user_id, $product_id); $cake = Category::model()->getCakeLine($pInfo['cat_id']); //获取商品的面包屑 $viewData = array(); $viewData['pInfo'] = $pInfo; $viewData['brandInfo'] = $brandInfo; $viewData['is_like'] = $is_like; $viewData['cake'] = $cake; $viewData['stock'] = $stock; $viewData['attrList'] = $attrList; $viewData['extendAttrList'] = $extendAttrList; $this->render('item/index', $viewData); }
protected function saveProductExtend($productId) { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $model = ProductExtend::model()->findByAttributes(array('product_id' => $_REQUEST['id'])); } if (empty($model)) { $model = new ProductExtend(); } $message = array(); $message['product_material'] = $_REQUEST['product_material']; //商品物料 $message['warranty'] = $_REQUEST['warranty']; //质保 $message['product_service'] = $_REQUEST['product_service']; //服务 $message['product_size'] = $_REQUEST['product_size']; //尺寸 $message['weight'] = $_REQUEST['weight']; //重量 $message['make_date'] = $_REQUEST['make_date']; //生产日期 $message['use_life'] = $_REQUEST['use_life']; //保质期 $message['product_return'] = $_REQUEST['product_return']; //退换货政策 $message['product_maintain'] = $_REQUEST['product_maintain']; //保养说明 $message['use_notice'] = $_REQUEST['use_notice']; //使用说明 $message['product_notice'] = $_REQUEST['product_notice']; //温馨提示 $model->product_id = $productId; $model->other_info = serialize($message); $flag = $model->save(); if (empty($flag)) { $error = $_REQUEST['id'] ? '修改商品扩展信息失败!' : '添加商品扩展信息失败!'; throw new exception($error); } return true; }
/** * 获取商品的扩展属性. * @param $id * @return array|bool|mixed */ public function getProductExtendInfo($id) { if (empty($id)) { return false; } $extendInfo = ProductExtend::model()->findByAttributes(array('product_id' => $id)); $data = array(); if ($extendInfo) { $data = unserialize($extendInfo->other_info); } return $data; }