code
stringlengths
15
9.96M
docstring
stringlengths
1
10.1k
func_name
stringlengths
1
124
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
6
186
url
stringlengths
50
236
license
stringclasses
4 values
public function getSearchArr() { $productPrimaryKey = Yii::$service->product->getPrimaryKey(); // 判断mongodb还是mysql存储product数据 $nameIsLang = $productPrimaryKey == '_id' ? true : false; $data = [ [ // selecit的Int 类型 'type' => 'select', 'title' => Yii::$service->page->translate->__('Status'), 'name' => 'status', 'columns_type' => 'int', // int使用标准匹配, string使用模糊查询 'value' => $this->_productHelper->getStatusArr(), ], [ // selecit的Int 类型 'type' => 'select', 'title' => Yii::$service->page->translate->__('Stock Status'), 'name' => 'is_in_stock', 'columns_type' => 'int', // int使用标准匹配, string使用模糊查询 'value' => $this->_productHelper->getInStockArr(), ], [ // 字符串类型 'type' => 'inputtext', 'title' => Yii::$service->page->translate->__('Product Name'), 'name' => 'name', 'columns_type' => 'string', 'lang' => $nameIsLang, ], [ // 字符串类型 'type' => 'inputtext', 'title' => Yii::$service->page->translate->__('Spu'), 'name' => 'spu', 'columns_type' => 'string', ], [ // 字符串类型 'type' => 'inputtext', 'title' => Yii::$service->page->translate->__('Sku'), 'name' => 'sku', 'columns_type' => 'string', ], [ // 时间区间类型搜索 'type' => 'inputdatefilter', 'name' => 'updated_at', 'columns_type' => 'int', 'value' => [ 'gte' => Yii::$service->page->translate->__('Updated Begin'), 'lt' => Yii::$service->page->translate->__('Updated End'), ], ], [ // 时间区间类型搜索 'type' => 'inputfilter', 'name' => 'qty', 'columns_type' => 'int', 'value' => [ 'gte' => Yii::$service->page->translate->__('Stock Qty Begin'), 'lt' => Yii::$service->page->translate->__('Stock Qty End'), ], ], ]; return $data; }
get search bar Arr config.
getSearchArr
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/productinfo/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/productinfo/Index.php
BSD-3-Clause
public function getEditBar() { /* if(!strstr($this->_currentParamUrl,"?")){ $csvUrl = $this->_currentParamUrl."?type=export"; }else{ $csvUrl = $this->_currentParamUrl."&type=export"; } <li class="line">line</li> <li><a class="icon csvdownload" href="'.$csvUrl.'" target="dwzExport" targetType="navTab" title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li> */ return '<ul class="toolBar"> <li><a class="add" href="'.$this->_editUrl.'" target="dialog" height="680" width="1200" drawable="true" mask="true"><span>' . Yii::$service->page->translate->__('Add') . '</span></a></li> <li><a class="add" href="'.$this->_batchInsertUrl.'" target="dialog" height="680" width="1200" drawable="true" mask="true"><span>' . Yii::$service->page->translate->__('Batch Add') . '</span></a></li> <li><a target="dialog" height="680" width="1200" drawable="true" mask="true" class="edit" href="'.$this->_editUrl.'?'.$this->_primaryKey.'={sid_user}" ><span>' . Yii::$service->page->translate->__('Update') . '</span></a></li> <li><a csrfName="' .CRequest::getCsrfName(). '" csrfVal="' .CRequest::getCsrfValue(). '" title="' . Yii::$service->page->translate->__('Are you sure you want to delete these records?') . '" target="selectedTodo" rel="'.$this->_primaryKey.'s" postType="string" href="'.$this->_deleteUrl.'" class="delete"><span>' . Yii::$service->page->translate->__('Batch Delete') . '</span></a></li> <li><a style="background-color: #eea236; border: #eea236;" href="http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecshop-shopfw-cj-product-data.html" target="_blank" ><span>批量采集商品</span></a></li> </ul>'; }
get edit html bar, it contains add ,eidt ,delete button.
getEditBar
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/productinfo/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/productinfo/Index.php
BSD-3-Clause
public function init() { $this->_service = Yii::$service->product; parent::init(); }
init param function ,execute in construct.
init
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/category/Product.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/category/Product.php
BSD-3-Clause
public function getSearchArr() { $nameInput = []; if (Yii::$service->product->serviceStorageName() == 'mongodb') { $nameInput = [ // 字符串类型 'type' => 'inputtext', 'title' => 'Name', 'name' => 'name', 'columns_type' => 'string', 'lang' => true, ]; } else { $nameInput = [ // 字符串类型 'type' => 'inputtext', 'title' => 'Name', 'name' => 'name', 'columns_type' => 'string', 'lang' => false, ]; } $data = [ $nameInput, [ // 字符串类型 'type' => 'inputtext', 'title' => Yii::$service->page->translate->__('Spu'), 'name' => 'spu', 'columns_type' =>'string', ], [ // 字符串类型 'type' => 'inputtext', 'title' => Yii::$service->page->translate->__('Sku'), 'name' => 'sku', 'columns_type' =>'string', ], [ // 时间区间类型搜索 'type' => 'inputdatefilter', 'name' => 'updated_at', 'title' => Yii::$service->page->translate->__('Updated At'), 'columns_type' =>'int', 'value' => [ 'gte' => Yii::$service->page->translate->__('Updated Begin'), 'lt' => Yii::$service->page->translate->__('Updated End'), ], ], ]; return $data; }
get search bar Arr config.
getSearchArr
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/category/Product.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/category/Product.php
BSD-3-Clause
public function getDbSearchBarHtml($data) { $searchBar = ''; if (!empty($data)) { $searchBar .= '<input type="hidden" name="search_type" value="search" />'; $searchBar .= '<table class="searchContent"> <tr>'; foreach ($data as $d) { $type = $d['type']; $name = $d['name']; $title = $d['title']; $value = $d['value']; if ($d['type'] == 'select') { $searchBar .= '<td> '.$value.' </td>'; } elseif ($d['type'] == 'chosen_select') { $searchBar .= '<td> '.$value.' </td>'; } elseif ($d['type'] == 'inputtext') { $searchBar .= '<td> '.$title.':<input type="text" value="'.(is_array($this->_param[$name]) ? $this->_param[$name]['$regex'] : $this->_param[$name]).'" name="'.$name.'" /> </td>'; } elseif ($d['type'] == 'inputdate') { $searchBar .= '<td> '.$title.'<input type="text" value="'.$this->_param[$name].'" name="'.$name.'" class="date" readonly="true" /> </td>'; } elseif ($d['type'] == 'inputdatefilter') { $value = $d['value']; if (is_array($value)) { foreach ($value as $t=>$title) { $searchBar .= '<td> '.$title.'<input type="text" value="'.$this->_param[$name.'_'.$t].'" name="'.$name.'_'.$t.'" class="date" readonly="true" /> </td>'; } } } elseif ($d['type'] == 'inputfilter') { $value = $d['value']; if (is_array($value)) { foreach ($value as $t=>$title) { $searchBar .= '<td> '.$title.'<input type="text" value="'.$this->_param[$name.'_'.$t].'" name="'.$name.'_'.$t.'" /> </td>'; } } } } $customSearchHtml = $this->customSearchBarHtml(); $searchBar .= $customSearchHtml; $searchBar .= '</tr> </table> <div class="subBar"> <ul> <li><a class="button productReset" ><span>' . Yii::$service->page->translate->__('All Product List') . '</span></a></li> <li><a class="button productSearch" ><span>' . Yii::$service->page->translate->__('Current Cateory Product') . '</span></a></li> </ul> </div>'; }
@param $data|array
getDbSearchBarHtml
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/category/Product.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/category/Product.php
BSD-3-Clause
public function init() { //$this->_saveUrl = CUrl::getUrl('catalog/category/managereditsave'); parent::init(); }
init param function ,execute in construct.
init
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/category/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/category/Index.php
BSD-3-Clause
public function getEditArr() { }
config edit array.
getEditArr
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/block/category/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/block/category/Index.php
BSD-3-Clause
public function actionImageupload() { $this->getBlock()->upload(); }
catalog
actionImageupload
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/controllers/ProductinfoController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/controllers/ProductinfoController.php
BSD-3-Clause
public function actionGetproductcategory() { $this->getBlock()->getProductCategory(); }
catalog product
actionGetproductcategory
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/controllers/ProductinfoController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/controllers/ProductinfoController.php
BSD-3-Clause
protected function getRandom($length = 6) { $str = null; $strPol = '123456789'; $max = strlen($strPol) - 1; for ($i = 0; $i < $length; $i++) { $str .= $strPol[rand(0, $max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数 } return $str; }
generate random string.
getRandom
php
fecshop/yii2_fecshop
app/appadmin/modules/Catalog/controllers/ProductinfoController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/appadmin/modules/Catalog/controllers/ProductinfoController.php
BSD-3-Clause
public function init() { parent::init(); /** * 如果模板路径没有配置,则配置模板路径 */ if (!Yii::$service->page->theme->fecshopThemeDir) { Yii::$service->page->theme->fecshopThemeDir = Yii::getAlias(CConfig::param('apphtml5BaseTheme')); } /** * 如果layout文件没有配置,则配置layout文件 */ if (!Yii::$service->page->theme->layoutFile) { Yii::$service->page->theme->layoutFile = CConfig::param('apphtml5BaseLayoutName'); } /* * set i18n translate category. */ Yii::$service->page->translate->category = 'apphtml5'; /* * 自定义Yii::$classMap,用于重写 */ }
init theme component property : $fecshopThemeDir and $layoutFile $fecshopThemeDir is apphtml5 base theme directory. layoutFile is current layout relative path.
init
php
fecshop/yii2_fecshop
app/apphtml5/modules/AppfrontController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/AppfrontController.php
BSD-3-Clause
public function getBlock($blockName = '') { if (!$blockName) { $blockName = $this->action->id; } if (!$this->blockNamespace) { $this->blockNamespace = Yii::$app->controller->module->blockNamespace; } if (!$this->blockNamespace) { throw new \yii\web\HttpException(406, 'blockNamespace is empty , you should config it in module->blockNamespace or controller blockNamespace '); } $viewId = $this->id; $viewId = str_replace('/', '\\', $viewId); $relativeFile = '\\'.$this->blockNamespace; $relativeFile .= '\\'.$viewId.'\\'.ucfirst($blockName); //查找是否在rewriteMap中存在重写 $relativeFile = Yii::mapGetName($relativeFile); return new $relativeFile(); }
@param $blockName | String get current block 这个函数的controller中得到block文件,譬如: cms模块的ArticleController的actinIndex()方法中使用$this->getBlock()->getLastData()方法, 对应的是cms/block/article/Index.php里面的getLastData(), 也就是说,这个block文件路径和controller的路径有一定的对应关系 这个思想来自于magento的block。
getBlock
php
fecshop/yii2_fecshop
app/apphtml5/modules/AppfrontController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/AppfrontController.php
BSD-3-Clause
public function render($view, $params = []) { $viewFile = Yii::$service->page->theme->getViewFile($view); $content = Yii::$app->view->renderFile($viewFile, $params, $this); return $this->renderContent($content); }
@param $view|string , (only) view file name ,by this module id, this controller id , generate view relative path. @param $params|Array, 这个是fecshop重写的render函数,根据fecshop的多模板机制 首先在高级别的模板中找view文件,如果找不到,按照模板路径优先级依次查找 直到找到view'文件。 1.get exist view file from mutil theme by theme protity. 2.get content by yii view compontent function renderFile() ,
render
php
fecshop/yii2_fecshop
app/apphtml5/modules/AppfrontController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/AppfrontController.php
BSD-3-Clause
public function findLayoutFile($view) { $layoutFile = ''; $relativeFile = 'layouts/'.Yii::$service->page->theme->layoutFile; $absoluteDir = Yii::$service->page->theme->getThemeDirArr(); foreach ($absoluteDir as $dir) { if ($dir) { $file = $dir.'/'.$relativeFile; if (file_exists($file)) { $layoutFile = $file; return $layoutFile; } } } throw new InvalidValueException('layout file is not exist!'); }
@param $view|string Get current layoutFile absolute path from mutil theme dir by protity. 首先在高级别的模板中找view文件,如果找不到,按照模板路径优先级依次查找 直到找到view'文件。
findLayoutFile
php
fecshop/yii2_fecshop
app/apphtml5/modules/AppfrontController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/AppfrontController.php
BSD-3-Clause
public function errorMessage($message) { Yii::$service->page->message->addError($message); return Yii::$service->url->redirectByUrlKey('customer/order'); }
@param $message | String 添加报错信息
errorMessage
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/order/Reorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/order/Reorder.php
BSD-3-Clause
public function remove($favorite_id) { Yii::$service->product->favorite->currentUserRemove($favorite_id); }
@param $favorite_id|string
remove
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/productfavorite/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/productfavorite/Index.php
BSD-3-Clause
protected function breadcrumbs($name) { if (Yii::$app->controller->module->params['forgot_reset_password_breadcrumbs']) { Yii::$service->page->breadcrumbs->addItems(['name' => $name]); } else { Yii::$service->page->breadcrumbs->active = false; } }
面包屑导航
breadcrumbs
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/account/Registerenable.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/account/Registerenable.php
BSD-3-Clause
public function sendForgotPasswordEmail($identity) { if ($identity) { Yii::$service->email->customer->sendForgotPasswordEmail($identity); } }
发送忘记密码邮件.
sendForgotPasswordEmail
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/account/Forgotpassword.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/account/Forgotpassword.php
BSD-3-Clause
public function sendLoginEmail($param) { if ($param) { Yii::$service->email->customer->sendLoginEmail($param); } }
发送登录邮件.
sendLoginEmail
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/account/Login.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/account/Login.php
BSD-3-Clause
public function sendRegisterEmail($param) { if ($param) { //Email::sendRegisterEmail($param); if (Yii::$service->email->customer->registerAccountIsNeedEnableByEmail) { $registerEnableToken = Yii::$service->customer->generateRegisterEnableToken($param['email']); if ($registerEnableToken) { $param['register_enable_token'] = $registerEnableToken; Yii::$service->email->customer->sendRegisterEmail($param); return true; } } else { Yii::$service->email->customer->sendRegisterEmail($param); return true; } } }
发送登录邮件.
sendRegisterEmail
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/block/account/Register.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/block/account/Register.php
BSD-3-Clause
public function init() { parent::init(); }
protected $_registerSuccessRedirectUrlKey = 'customer/account';
init
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/ProductreviewController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/ProductreviewController.php
BSD-3-Clause
public function actionLoginv() { Yii::$service->session->set('logintype', 'google'); $thirdLogin = Yii::$service->store->thirdLogin; global $googleapiinfo; $googleapiinfo['GOOGLE_CLIENT_ID'] = isset($thirdLogin['google']['CLIENT_ID']) ? $thirdLogin['google']['CLIENT_ID'] : ''; $googleapiinfo['GOOGLE_CLIENT_SECRET'] = isset($thirdLogin['google']['CLIENT_SECRET']) ? $thirdLogin['google']['CLIENT_SECRET'] : ''; $lib_google_base = Yii::getAlias('@fecshop/lib/google'); include $lib_google_base.'/Social.php'; $urlKey = 'customer/google/loginv'; $redirectUrl = Yii::$service->url->getUrl($urlKey); $Social_obj = new \Social($redirectUrl); $user = $Social_obj->google(); // 服务器放到国外才行。不然上面无法返回数据。 if (is_array($user) && !empty($user)) { $fullname = $user['name']; $email = $user['email']; if ($email) { $this->accountLogin($fullname, $email); } } }
google登录确认成功后,返回的url 通过下面,得到用户的email,first_name,last_name 然后登录。 由于阿里云是国内服务器,暂时还没有具体测试,这个需要 用国外的服务器才可以。因为需要服务器方面访问google的接口。国内服务器会被墙的。
actionLoginv
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/GoogleController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/GoogleController.php
BSD-3-Clause
public function accountLogin($full_name, $email) { $name_arr = explode(' ', $full_name); $first_name = $name_arr[0]; $last_name = $name_arr[1]; $user = [ 'first_name' =>$first_name, 'last_name' =>$last_name, 'email' =>$email, ]; Yii::$service->customer->registerThirdPartyAccountAndLogin($user, 'google'); echo '<script> window.close(); window.opener.location.reload(); </script>'; exit; }
google账户登录.
accountLogin
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/GoogleController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/GoogleController.php
BSD-3-Clause
public function actionIndex() { $result_arr = []; if (Yii::$app->request->isAjax) { $result_arr['loginStatus'] = false; $result_arr['favorite'] = false; $result_arr['favorite_product_count'] = 0; $product_id = Yii::$app->request->get('product_id'); $customer_name = ''; if (!Yii::$app->user->isGuest) { $identity = Yii::$app->user->identity; $customer_name = $identity['firstname'].' '.$identity['lastname']; $result_arr['customer_name'] = $customer_name; $result_arr['favorite_product_count'] = $identity['favorite_product_count'] ? $identity['favorite_product_count'] : 0; $result_arr['loginStatus'] = true; if ($product_id) { $favorite = Yii::$service->product->favorite->getByProductIdAndUserId($product_id); $favorite ? ($result_arr['favorite'] = true) : ''; } } if ($product_id) { // 添加csrf数据 $csrfName = \fec\helpers\CRequest::getCsrfName(); $csrfVal = \fec\helpers\CRequest::getCsrfValue(); $result_arr['csrfName'] = $csrfName; $result_arr['csrfVal'] = $csrfVal; $result_arr['product_id'] = $product_id; } $cartQty = Yii::$service->cart->getCartItemQty(); $result_arr['cart_qty'] = $cartQty; } echo json_encode($result_arr); exit; }
ajax 请求 ,得到是否登录账户的信息.
actionIndex
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AjaxController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AjaxController.php
BSD-3-Clause
public function actionLoginv() { //Yii::$service->session->set('fbs', 1); $thirdLogin = Yii::$service->store->thirdLogin; $facebook_app_id = isset($thirdLogin['facebook']['facebook_app_id']) ? $thirdLogin['facebook']['facebook_app_id'] : ''; $facebook_app_secret = isset($thirdLogin['facebook']['facebook_app_secret']) ? $thirdLogin['facebook']['facebook_app_secret'] : ''; $fb = new \Facebook\Facebook([ 'app_id' => $facebook_app_id, 'app_secret' => $facebook_app_secret, 'default_graph_version' => 'v2.10', ]); $helper = $fb->getRedirectLoginHelper(); if (isset($_GET['state'])) { $helper->getPersistentDataHandler()->set('state', $_GET['state']); } try { $accessToken = $helper->getAccessToken(); } catch(\Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(\Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } if (! isset($accessToken)) { if ($helper->getError()) { header('HTTP/1.0 401 Unauthorized'); echo "Error: " . $helper->getError() . "\n"; echo "Error Code: " . $helper->getErrorCode() . "\n"; echo "Error Reason: " . $helper->getErrorReason() . "\n"; echo "Error Description: " . $helper->getErrorDescription() . "\n"; } else { header('HTTP/1.0 400 Bad Request'); echo 'Bad request'; } exit; } $fb->setDefaultAccessToken($accessToken->getValue()); $response = $fb->get('/me?locale=en_US&fields=name,email'); $userNode = $response->getGraphUser(); $email = $userNode->getField('email'); $name = $userNode['name']; $fbid = $userNode['id']; //echo $email.$name.$fbid;exit; if ($email) { $this->accountLogin($fbid,$name,$email); exit; } else { $loginUrl = $helper->getLoginUrl(); header('Location: '.$loginUrl); } }
facebook 账号在facebook确认后,返回网站的url地址。
actionLoginv
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/FacebookController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/FacebookController.php
BSD-3-Clause
public function accountLogin($fbid,$name,$email) { $name_arr = explode(' ', $name); $first_name = $name_arr[0]; $last_name = $name_arr[1]; $user = [ 'first_name' =>$first_name, 'last_name' =>$last_name, 'email' =>$email, ]; Yii::$service->customer->registerThirdPartyAccountAndLogin($user, 'facebook'); echo '<script> window.close(); window.opener.location.reload(); </script>'; exit; }
facebook账户登录
accountLogin
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/FacebookController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/FacebookController.php
BSD-3-Clause
public function actionIndex() { if (Yii::$app->user->isGuest) { return Yii::$service->url->redirectByUrlKey('customer/account/login'); } $data = $this->getBlock()->getLastData(); return $this->render($this->action->id, $data); }
账户中心.
actionIndex
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AccountController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AccountController.php
BSD-3-Clause
public function actionLogin() { /* $toEmail = '[email protected]'; // \fecshop\app\appfront\modules\Mailer\Email::sendLoginEmail($toEmail); \fecshop\app\appfront\modules\Mailer\Email::sendRegisterEmail($toEmail); exit; */ if (!Yii::$app->user->isGuest) { return Yii::$service->url->redirectByUrlKey('customer/account'); } $param = Yii::$app->request->post('editForm'); if (!empty($param) && is_array($param)) { $this->getBlock()->login($param); if (!Yii::$app->user->isGuest) { return Yii::$service->customer->loginSuccessRedirect('customer/account'); } } $data = $this->getBlock()->getLastData($param); return $this->render($this->action->id, $data); }
登录.
actionLogin
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AccountController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AccountController.php
BSD-3-Clause
public function actionLogout() { $rt = Yii::$app->request->get('rt'); if (!Yii::$app->user->isGuest) { Yii::$app->user->logout(); Yii::$service->cart->clearCart(); } if ($rt) { $redirectUrl = base64_decode($rt); Yii::$service->url->redirect($redirectUrl); } else { Yii::$service->url->redirect(Yii::$service->url->HomeUrl()); } }
登出账户.
actionLogout
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AccountController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AccountController.php
BSD-3-Clause
public function actionLogininfo() { if (!Yii::$app->user->isGuest) { echo json_encode([ 'loginStatus' => true, ]); exit; } }
ajax 请求 ,得到是否登录账户的信息.
actionLogininfo
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AccountController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AccountController.php
BSD-3-Clause
public function actionForgotpassword() { if (!Yii::$app->user->isGuest) { return Yii::$service->url->redirectByUrlKey('customer/account'); } $data = $this->getBlock()->getLastData(); return $this->render($this->action->id, $data); }
忘记密码?
actionForgotpassword
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/AccountController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/AccountController.php
BSD-3-Clause
public function init() { parent::init(); }
protected $_registerSuccessRedirectUrlKey = 'customer/account';
init
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/NewsletterController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/NewsletterController.php
BSD-3-Clause
public function init() { parent::init(); }
protected $_registerSuccessRedirectUrlKey = 'customer/account';
init
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/OrderController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/OrderController.php
BSD-3-Clause
public function init() { parent::init(); }
protected $_registerSuccessRedirectUrlKey = 'customer/account';
init
php
fecshop/yii2_fecshop
app/apphtml5/modules/Customer/controllers/PointController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Customer/controllers/PointController.php
BSD-3-Clause
public function getProductBySkus($skus) { if (is_array($skus) && !empty($skus)) { $filter['select'] = [ 'sku', 'spu', 'name', 'image', 'price', 'special_price', 'special_from', 'special_to', 'brand_id','is_in_stock', 'url_key', 'score', ]; $filter['where'] = ['in', 'sku', $skus]; $products = Yii::$service->product->getProducts($filter); // $products = Yii::$service->category->product->convertToCategoryInfo($products); //var_dump($products); return $products; } }
public function getBestSellerProduct(){ $best_skus = Yii::$app->controller->module->params['homeBestSellerSku']; return $this->getProductBySkus($best_skus); }
getProductBySkus
php
fecshop/yii2_fecshop
app/apphtml5/modules/Cms/block/home/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Cms/block/home/Index.php
BSD-3-Clause
public function actionIndex() { $data = $this->getBlock()->getLastData(); if (!is_array($data) && empty($data)) { return Yii::$service->url->redirect404(); } return $this->render($this->action->id, $data); }
网站信息管理
actionIndex
php
fecshop/yii2_fecshop
app/apphtml5/modules/Cms/controllers/ArticleController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Cms/controllers/ArticleController.php
BSD-3-Clause
public function actionIndex() { $data = $this->getBlock()->getLastData(); return $this->render($this->action->id, $data); }
网站信息管理
actionIndex
php
fecshop/yii2_fecshop
app/apphtml5/modules/Cms/controllers/HomeController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Cms/controllers/HomeController.php
BSD-3-Clause
public function doCheckoutPayment($token) { $methodName_ = 'DoExpressCheckoutPayment'; $nvpStr_ = Yii::$service->payment->paypal->getCheckoutPaymentNvpStr($token); //echo $nvpStr_;exit; $doCheckoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_); //var_dump($doCheckoutReturn); //exit; if (strstr(strtolower($doCheckoutReturn['ACK']), 'success')) { return $doCheckoutReturn; } else { if ($doCheckoutReturn['ACK'] == 'Failure') { $message = $doCheckoutReturn['L_LONGMESSAGE0']; // 添加报错信息。 //Message::error($message); Yii::$service->helper->errors->add($message); } else { Yii::$service->helper->errors->add('paypal express payment error.'); } return false; } }
@param $token | String 通过paypal的api接口,进行支付下单
doCheckoutPayment
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
BSD-3-Clause
public function updateAddress($post) { return Yii::$service->cart->updateGuestCart($this->_billing, $this->_shipping_method, $this->_payment_method); }
@param $post | Array 登录用户,保存货运地址到customer address ,然后把生成的 address_id 写入到cart中。 shipping method写入到cart中 payment method 写入到cart中 updateCart
updateAddress
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
BSD-3-Clause
public function checkOrderInfoAndInit($post) { $address_one = ''; $billing = isset($post['billing']) ? $post['billing'] : ''; if (!Yii::$service->order->checkRequiredAddressAttr($billing)) { return false; } $this->_billing = $billing; $shipping_method = isset($post['shipping_method']) ? $post['shipping_method'] : ''; $payment_method = isset($post['payment_method']) ? $post['payment_method'] : ''; // 验证货运方式 if (!$shipping_method) { Yii::$service->helper->errors->add('shipping method can not empty'); return false; } else { //if (!Yii::$service->shipping->ifIsCorrect($shipping_method)) { // Yii::$service->helper->errors->add('shipping method is not correct'); // // return false; //} } // 订单备注信息不能超过1500字符 $orderRemarkStrMaxLen = Yii::$service->order->orderRemarkStrMaxLen; $order_remark = isset($post['order_remark']) ? $post['order_remark'] : ''; if ($order_remark && $orderRemarkStrMaxLen) { $order_remark_strlen = strlen($order_remark); if ($order_remark_strlen > $orderRemarkStrMaxLen) { Yii::$service->helper->errors->add('order remark string length can not gt {orderRemarkStrMaxLen}', ['orderRemarkStrMaxLen' => $orderRemarkStrMaxLen]); return false; } else { // 去掉xss攻击字符,关于防止xss攻击的yii文档参看:http://www.yiichina.com/doc/guide/2.0/security-best-practices#fang-zhi-xss-gong-ji $this->_order_remark = $order_remark; } } $this->_shipping_method = $shipping_method; $this->_payment_method = $payment_method; Yii::$service->payment->setPaymentMethod($this->_payment_method); return true; }
@param $post | Array @return bool 检查前台传递的信息是否正确。同时初始化一部分类变量
checkOrderInfoAndInit
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php
BSD-3-Clause
public function initAddress() { $this->_address_list = Yii::$service->customer->address->currentAddressList(); if (is_array($this->_address_list) && !empty($this->_address_list)) { // 用户存在地址列表,但是,cart中没有customer_address_id // 这种情况下,从用户地址列表中取出来默认地址,然后设置成当前的地址。 foreach ($this->_address_list as $adss_id => $info) { if ($info['is_default'] == 1) { $this->_address_id = $adss_id; //$this->_address_view_file = 'checkout/onepage/index/address_select.php'; $addressModel = Yii::$service->customer->address->getByPrimaryKey($this->_address_id); if ($addressModel['country']) { $this->_country = $addressModel['country']; $this->_address['country'] = $this->_country; } if ($addressModel['state']) { $this->_state = $addressModel['state']; $this->_address['state'] = $this->_state; } if ($addressModel['first_name']) { $this->_address['first_name'] = $addressModel['first_name']; } if ($addressModel['last_name']) { $this->_address['last_name'] = $addressModel['last_name']; } if ($addressModel['email']) { $this->_address['email'] = $addressModel['email']; } if ($addressModel['telephone']) { $this->_address['telephone'] = $addressModel['telephone']; } if ($addressModel['street1']) { $this->_address['street1'] = $addressModel['street1']; } if ($addressModel['street2']) { $this->_address['street2'] = $addressModel['street2']; } if ($addressModel['city']) { $this->_address['city'] = $addressModel['city']; } if ($addressModel['zip']) { $this->_address['zip'] = $addressModel['zip']; } break; } } } else { $cart = Yii::$service->cart->quote->getCart(); $address_info = []; if (!Yii::$app->user->isGuest) { $identity = Yii::$app->user->identity; $address_info['email'] = $identity['email']; $address_info['first_name'] = $identity['firstname']; $address_info['last_name'] = $identity['lastname']; } if (isset($cart['customer_email']) && !empty($cart['customer_email'])) { $address_info['email'] = $cart['customer_email']; } if (isset($cart['customer_firstname']) && !empty($cart['customer_firstname'])) { $address_info['first_name'] = $cart['customer_firstname']; } if (isset($cart['customer_lastname']) && !empty($cart['customer_lastname'])) { $address_info['last_name'] = $cart['customer_lastname']; } if (isset($cart['customer_telephone']) && !empty($cart['customer_telephone'])) { $address_info['telephone'] = $cart['customer_telephone']; } if (isset($cart['customer_address_country']) && !empty($cart['customer_address_country'])) { $address_info['country'] = $cart['customer_address_country']; $this->_country = $address_info['country']; } if (isset($cart['customer_address_state']) && !empty($cart['customer_address_state'])) { $address_info['state'] = $cart['customer_address_state']; } if (isset($cart['customer_address_city']) && !empty($cart['customer_address_city'])) { $address_info['city'] = $cart['customer_address_city']; } if (isset($cart['customer_address_zip']) && !empty($cart['customer_address_zip'])) { $address_info['zip'] = $cart['customer_address_zip']; } if (isset($cart['customer_address_street1']) && !empty($cart['customer_address_street1'])) { $address_info['street1'] = $cart['customer_address_street1']; } if (isset($cart['customer_address_street2']) && !empty($cart['customer_address_street2'])) { $address_info['street2'] = $cart['customer_address_street2']; } $this->_address = $address_info; } if (!$this->_country) { $this->_country = Yii::$service->helper->country->getDefaultCountry(); $this->_address['country'] = $this->_country; } }
初始化地址信息,首先从当前用户里面取值,然后从cart表中取数据覆盖 1. 初始化 $this->_address,里面保存的各个地址信息。 2. 如果是登录用户,而且.
initAddress
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function initCountry() { $this->_countrySelect = Yii::$service->helper->country->getAllCountryOptions('', '', $this->_country); }
初始化国家下拉条。
initCountry
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function initState($country = '') { $state = isset($this->_address['state']) ? $this->_address['state'] : ''; if (!$country) { $country = $this->_country; } $stateHtml = Yii::$service->helper->country->getStateOptionsByContryCode($country, $state); if (!$stateHtml) { $stateHtml = '<input id="state" name="billing[state]" value="'.$state.'" title="State" class="address_state input-text" style="" type="text">'; } else { $stateHtml = '<select id="address:state" class="address_state validate-select" title="State" name="billing[state]"> <option value="">Please select region, state or province</option>' .$stateHtml.'</select>'; } $this->_stateHtml = $stateHtml; }
初始化省市
initState
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function ajaxChangecountry() { $country = Yii::$app->request->get('country'); $country = \Yii::$service->helper->htmlEncode($country); $state = $this->initState($country); echo json_encode([ 'state' => $this->_stateHtml, ]); exit; }
当改变国家的时候,ajax获取省市信息.
ajaxChangecountry
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function getProductOptions($product_one, $custom_option_sku) { $custom_option_info_arr = []; $custom_option = isset($product_one['custom_option']) ? $product_one['custom_option'] : ''; $custom_option_sku = $product_one['custom_option_sku']; if (isset($custom_option[$custom_option_sku]) && !empty($custom_option[$custom_option_sku])) { $custom_option_info = $custom_option[$custom_option_sku]; foreach ($custom_option_info as $attr=>$val) { if (!in_array($attr, ['qty', 'sku', 'price', 'image'])) { $attr = str_replace('_', ' ', $attr); $attr = ucfirst($attr); $custom_option_info_arr[$attr] = $val; } } } $spu_options = $product_one['spu_options']; if (is_array($spu_options) && !empty($spu_options)) { foreach ($spu_options as $label => $val) { $custom_option_info_arr[$label] = $val; } } return $custom_option_info_arr; }
将产品页面选择的颜色尺码等显示出来,包括custom option 和spu options部分的数据.
getProductOptions
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function getShippings($custom_shipping_method = '') { $country = $this->_country; if (!$this->_state) { $region = '*'; } else { $region = $this->_state; } $cartProductInfo = Yii::$service->cart->quoteItem->getCartProductInfo(); $product_weight = $cartProductInfo['product_weight']; $product_volume_weight = $cartProductInfo['product_volume_weight']; $product_final_weight = max($product_weight, $product_volume_weight); $cartShippingMethod = $this->_cart_info['shipping_method']; // 当前的货运方式 $current_shipping_method = Yii::$service->shipping->getCurrentShippingMethod($custom_shipping_method, $cartShippingMethod, $country, $region, $product_final_weight); $this->_shipping_method = $current_shipping_method; // 得到所有,有效的shipping method $shippingArr = $this->getShippingArr($product_final_weight, $current_shipping_method, $country, $region = '*'); return $shippingArr; }
@param $current_shipping_method | String 当前选择的货运方式 @return Array,数据格式为: [ 'method'=> $method, 'label' => $label, 'name' => $name, 'cost' => $symbol.$currentCurrencyCost, 'check' => $check, 'shipping_i' => $shipping_i, ] 根据选择的货运方式,得到费用等信息。
getShippings
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function getPayment() { $paymentArr = Yii::$service->payment->getStandardPaymentArr(); $pArr = []; if (!$this->_payment_method) { if (isset($this->_cart_info['payment_method']) && !empty($this->_cart_info['payment_method'])) { $this->_payment_method = $this->_cart_info['payment_method']; } //echo $this->_payment_method; if (!$this->_payment_method) { $i = 0; foreach ($paymentArr as $k => $v) { $i++; if ($i == 1) { $this->_payment_method = $k; $v['checked'] = true; } $pArr[$k] = $v; } } else { foreach ($paymentArr as $k => $v) { if ($this->_payment_method == $k) { $v['checked'] = true; } $pArr[$k] = $v; } //var_dump($paymentArr); } } return $pArr; }
@return 得到所有的支付方式 在获取的同时,判断$this->_payment_method 是否存在,不存在则取 第一个支付方式,作为$this->_payment_method的值。
getPayment
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function setValue($getExpressCheckoutReturn) { if ($getExpressCheckoutReturn['FIRSTNAME']) { $this->_address['first_name'] = $getExpressCheckoutReturn['FIRSTNAME']; } if ($getExpressCheckoutReturn['LASTNAME']) { $this->_address['last_name'] = $getExpressCheckoutReturn['LASTNAME']; } if ($getExpressCheckoutReturn['EMAIL']) { $this->_address['email'] = $getExpressCheckoutReturn['EMAIL']; } if ($getExpressCheckoutReturn['SHIPTOCOUNTRYCODE']) { $this->_address['country'] = $getExpressCheckoutReturn['SHIPTOCOUNTRYCODE']; if ($this->_address['country'] == 'C2') { $this->_address['country'] = 'CN'; } $this->_country = $this->_address['country']; if ($this->_address['country']) { $this->_address['country_name'] = Yii::$service->helper->country->getCountryNameByKey($this->_address['country']); } } if ($getExpressCheckoutReturn['SHIPTOSTATE']) { $this->_address['state'] = $getExpressCheckoutReturn['SHIPTOSTATE']; } if ($getExpressCheckoutReturn['SHIPTOCITY']) { $this->_address['city'] = $getExpressCheckoutReturn['SHIPTOCITY']; } if ($getExpressCheckoutReturn['SHIPTOSTREET']) { $this->_address['street1'] = $getExpressCheckoutReturn['SHIPTOSTREET']; } if ($getExpressCheckoutReturn['SHIPTOSTREET2']) { $this->_address['street2'] = $getExpressCheckoutReturn['SHIPTOSTREET2']; } if ($getExpressCheckoutReturn['SHIPTOZIP']) { $this->_address['zip'] = $getExpressCheckoutReturn['SHIPTOZIP']; } }
初始化信息。
setValue
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/express/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/express/Review.php
BSD-3-Clause
public function doCheckoutPayment($token) { $methodName_ = 'DoExpressCheckoutPayment'; $nvpStr_ = Yii::$service->payment->paypal->getCheckoutPaymentNvpStr($token); //echo '<br/>nvpStr_:<br/>"'.$nvpStr_.'<br/><br/>'; $doCheckoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_); //echo '<br/>doCheckoutReturn <br/><br/>'; //var_dump($doCheckoutReturn); //echo '<br/>doCheckoutReturn <br/><br/>'; //exit; if (strstr(strtolower($doCheckoutReturn['ACK']), 'success')) { return $doCheckoutReturn; } else { if ($doCheckoutReturn['ACK'] == 'Failure') { $message = $doCheckoutReturn['L_LONGMESSAGE0']; // 添加报错信息。 //Message::error($message); Yii::$service->helper->errors->add($message); } else { Yii::$service->helper->errors->add('paypal express payment error.'); } return false; } }
@param $token | String 通过paypal的api接口,进行支付下单
doCheckoutPayment
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
BSD-3-Clause
public function updateAddress($post) { return Yii::$service->cart->updateGuestCart($this->_billing, $this->_shipping_method, $this->_payment_method); }
@param $post | Array 登录用户,保存货运地址到customer address ,然后把生成的 address_id 写入到cart中。 shipping method写入到cart中 payment method 写入到cart中 updateCart
updateAddress
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
BSD-3-Clause
public function checkOrderInfoAndInit($post) { $address_one = ''; $billing = isset($post['billing']) ? $post['billing'] : ''; if (!Yii::$service->order->checkRequiredAddressAttr($billing)) { return false; } $this->_billing = $billing; $shipping_method = isset($post['shipping_method']) ? $post['shipping_method'] : ''; $payment_method = isset($post['payment_method']) ? $post['payment_method'] : ''; // 验证货运方式 if (!$shipping_method) { Yii::$service->helper->errors->add('shipping method can not empty'); return false; } else { if (!Yii::$service->shipping->ifIsCorrect($shipping_method)) { Yii::$service->helper->errors->add('shipping method is not correct'); return false; } } $this->_shipping_method = $shipping_method; $this->_payment_method = $payment_method; Yii::$service->payment->setPaymentMethod($this->_payment_method); return true; }
@param $post | Array @return bool 检查前台传递的信息是否正确。同时初始化一部分类变量
checkOrderInfoAndInit
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/block/paypal/standard/Placeorder.php
BSD-3-Clause
public function actionStart() { $this->initFunc(); Yii::$service->page->theme->layoutFile = 'wxpay_jsapi.php'; $data = Yii::$service->payment->wxpayJsApi->getScanCodeStart(); $data['success_url'] = Yii::$service->payment->getStandardSuccessRedirectUrl(); return $this->render($this->action->id, $data); }
支付开始页面.
actionStart
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
BSD-3-Clause
public function actionIpn() { Yii::$service->payment->wxpay->ipn(); }
IPN消息推送地址 IPN过来后,不清除session中的 increment_id ,也不清除购物车 仅仅是更改订单支付状态。
actionIpn
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
BSD-3-Clause
public function actionSuccess() { $this->initFunc(); $data = [ 'increment_id' => $this->_increment_id, ]; // 清理购物车中的产品。(游客用户的购物车在成功页面清空) if (Yii::$app->user->isGuest) { Yii::$service->cart->clearCartProductAndCoupon(); } // 清理session中的当前的increment_id Yii::$service->order->removeSessionIncrementId(); return $this->render('../../payment/checkmoney/success', $data); }
废弃 成功支付页面.
actionSuccess
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/WxpayjsapiController.php
BSD-3-Clause
public function actionStart() { $this->initFunc(); //Yii::$service->page->theme->layoutFile = 'wxpay_jsapi.php'; $objectxml = Yii::$service->payment->wxpayH5->getScanCodeStart(); //var_dump($objectxml); $returnUrl = Yii::$service->payment->getStandardReturnUrl(); $return_Url = urlencode($returnUrl); $url = $objectxml['mweb_url'] . '&redirect_url=' . $return_Url; //echo $url; return Yii::$service->url->redirect($url); }
支付开始页面.
actionStart
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
BSD-3-Clause
public function actionIpn() { Yii::$service->payment->wxpay->ipn(); }
IPN消息推送地址 IPN过来后,不清除session中的 increment_id ,也不清除购物车 仅仅是更改订单支付状态。
actionIpn
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
BSD-3-Clause
public function actionSuccess() { $this->initFunc(); $data = [ 'increment_id' => $this->_increment_id, ]; // 清理购物车中的产品。(游客用户的购物车在成功页面清空) if (Yii::$app->user->isGuest) { Yii::$service->cart->clearCartProductAndCoupon(); } // 清理session中的当前的increment_id Yii::$service->order->removeSessionIncrementId(); return $this->render('../../payment/checkmoney/success', $data); }
废弃 成功支付页面.
actionSuccess
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/Wxpayh5Controller.php
BSD-3-Clause
public function actionStart() { $payment_method = isset($this->_order_model['payment_method']) ? $this->_order_model['payment_method'] : ''; if ($payment_method) { $complateUrl = Yii::$service->payment->getStandardSuccessRedirectUrl($payment_method); if ($complateUrl) { // 登录用户,在支付前清空购物车。 //if(!Yii::$app->user->isGuest){ // Yii::$service->cart->clearCartProductAndCoupon(); //} // 清空购物车 Yii::$service->cart->clearCartProductAndCoupon(); Yii::$service->url->redirect($complateUrl); exit; } } $homeUrl = Yii::$service->url->homeUrl(); Yii::$service->url->redirect($homeUrl); }
支付开始页面.
actionStart
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
BSD-3-Clause
public function actionSuccess() { $data = [ 'increment_id' => $this->_increment_id, ]; // 清理购物车中的产品。(游客用户的购物车在成功页面清空) if (Yii::$app->user->isGuest) { Yii::$service->cart->clearCartProductAndCoupon(); } // 清理session中的当前的increment_id Yii::$service->order->removeSessionIncrementId(); return $this->render('../../payment/checkmoney/success', $data); }
成功支付页面.
actionSuccess
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
BSD-3-Clause
public function actionIpn() { }
IPN消息推送地址 IPN过来后,不清除session中的 increment_id ,也不清除购物车 仅仅是更改订单支付状态。
actionIpn
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/CheckmoneyController.php
BSD-3-Clause
public function actionReview() { $payment_method = Yii::$service->payment->paypal->express_payment_method; Yii::$service->payment->setPaymentMethod($payment_method); $_csrf = Yii::$app->request->post('_csrf'); if ($_csrf) { $status = $this->getBlock('placeorder')->getLastData(); if ($status) { return; } } $data = $this->getBlock()->getLastData(); if (is_array($data) && !empty($data)) { return $this->render($this->action->id, $data); } else { return $data; } }
2.Review 从paypal确认后返回
actionReview
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/paypal/ExpressController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/paypal/ExpressController.php
BSD-3-Clause
public function actionReview() { $payment_method = Yii::$service->payment->paypal->standard_payment_method; Yii::$service->payment->setPaymentMethod($payment_method); $this->getBlock('placeorder')->getLastData(); }
2.Review 从paypal确认后返回
actionReview
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/paypal/StandardController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/paypal/StandardController.php
BSD-3-Clause
public function actionStart() { // $AopSdkFile = Yii::getAlias('@fecshop/lib/alipay/AopSdk.php'); // require($AopSdkFile); // echo '支付宝支付跳转中...'; return '支付宝支付跳转中...'.Yii::$service->payment->alipay->start(); }
在网站下单页面,选择支付宝支付方式后, 跳转到支付宝支付页面前准备的部分。
actionStart
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
BSD-3-Clause
public function actionReview() { $reviewStatus = Yii::$service->payment->alipay->review(); if($reviewStatus){ $successRedirectUrl = Yii::$service->payment->getStandardSuccessRedirectUrl(); return Yii::$service->url->redirect($successRedirectUrl); }else{ echo Yii::$service->helper->errors->get('<br/>'); return; } }
从支付宝支付成功后,跳转返回 fec-shop 的部分
actionReview
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
BSD-3-Clause
public function actionIpn() { \Yii::info('alipay ipn begin', 'fecshop_debug'); $post = Yii::$app->request->post(); if (is_array($post) && !empty($post)) { \Yii::info('', 'fecshop_debug'); $post = \Yii::$service->helper->htmlEncode($post); ob_start(); ob_implicit_flush(false); var_dump($post); $post_log = ob_get_clean(); \Yii::info($post_log, 'fecshop_debug'); $ipnStatus = Yii::$service->payment->alipay->receiveIpn($post); if($ipnStatus){ echo 'success'; return; } } }
IPN,支付宝消息接收部分
actionIpn
php
fecshop/yii2_fecshop
app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
BSD-3-Clause
public function getProductOptions($product_one) { $custom_option_info_arr = []; $custom_option = isset($product_one['custom_option']) ? $product_one['custom_option'] : ''; $custom_option_sku = $product_one['custom_option_sku']; if (isset($custom_option[$custom_option_sku]) && !empty($custom_option[$custom_option_sku])) { $custom_option_info = $custom_option[$custom_option_sku]; foreach ($custom_option_info as $attr=>$val) { if (!in_array($attr, ['qty', 'sku', 'price', 'image'])) { $attr = str_replace('_', ' ', $attr); $attr = ucfirst($attr); $custom_option_info_arr[$attr] = $val; } } } $spu_options = $product_one['spu_options']; if (is_array($spu_options) && !empty($spu_options)) { foreach ($spu_options as $label => $val) { $custom_option_info_arr[$label] = $val; } } return $custom_option_info_arr; }
将产品页面选择的颜色尺码等显示出来,包括custom option 和spu options部分的数据.
getProductOptions
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/cart/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/cart/Index.php
BSD-3-Clause
public function guestCreateAndLoginAccount($post) { $create_account = $post['create_account']; $billing = $post['billing']; if (!is_array($billing) || empty($billing)) { Yii::$service->helper->errors->add('billing must be array and can not empty'); return false; } if ($create_account) { $customer_password = $billing['customer_password']; $confirm_password = $billing['confirm_password']; if ($customer_password != $confirm_password) { Yii::$service->helper->errors->add('the passwords are inconsistent'); return false; } $passMin = Yii::$service->customer->getRegisterPassMinLength(); $passMax = Yii::$service->customer->getRegisterPassMaxLength(); if (strlen($customer_password) < $passMin) { Yii::$service->helper->errors->add('password must Greater than {min_password}', ['min_password' =>$passMin]); return false; } if (strlen($customer_password) > $passMax) { Yii::$service->helper->errors->add('password must less than {max_password}', ['max_password' =>$passMax]); return false; } $param['email'] = $billing['email']; $param['password'] = $billing['customer_password']; $param['firstname'] = $billing['first_name']; $param['lastname'] = $billing['last_name']; if (!Yii::$service->customer->register($param)) { return false; } else { Yii::$service->customer->Login([ 'email' => $billing['email'], 'password' => $billing['customer_password'], ]); } } return true; }
@param $post|Array,前台传递参数数组。 如果游客选择了创建账户,并且输入了密码,则使用address email作为账号, 进行账号的注册和登录。
guestCreateAndLoginAccount
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
BSD-3-Clause
public function updateAddress($post) { if (!Yii::$app->user->isGuest) { $billing = $post['billing']; $address_id = $post['address_id']; if (!$address_id) { $identity = Yii::$app->user->identity; $customer_id = $identity['id']; $one = [ 'first_name' => $billing['first_name'], 'last_name' => $billing['last_name'], 'email' => $billing['email'], 'company' => '', 'telephone' => $billing['telephone'], 'fax' => '', 'street1' => $billing['street1'], 'street2' => $billing['street2'], 'city' => $billing['city'], 'state' => $billing['state'], 'zip' => $billing['zip'], 'country' => $billing['country'], 'customer_id' => $customer_id, 'is_default' => 1, ]; $address_id = Yii::$service->customer->address->save($one); $this->_address_id = $address_id; if (!$address_id) { Yii::$service->helper->errors->add('new customer address save fail'); return false; } //echo "$address_id,$this->_shipping_method,$this->_payment_method"; } return Yii::$service->cart->updateLoginCart($this->_address_id, $this->_shipping_method, $this->_payment_method); } else { return Yii::$service->cart->updateGuestCart($this->_billing, $this->_shipping_method, $this->_payment_method); } return true; }
@param $post | Array 登录用户,保存货运地址到customer address ,然后把生成的 address_id 写入到cart中。 shipping method写入到cart中 payment method 写入到cart中 updateCart
updateAddress
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
BSD-3-Clause
public function checkOrderInfoAndInit($post) { $address_one = ''; $address_id = isset($post['address_id']) ? $post['address_id'] : ''; $billing = isset($post['billing']) ? $post['billing'] : ''; if ($address_id) { $this->_address_id = $address_id; if (Yii::$app->user->isGuest) { Yii::$service->helper->errors->add('address id can not use for guest'); return false; // address_id 这种情况,必须是登录用户。 } else { $customer_id = Yii::$app->user->identity->id; if (!$customer_id) { Yii::$service->helper->errors->add('customer id is empty'); return false; } else { $address_one = Yii::$service->customer->address->getAddressByIdAndCustomerId($address_id, $customer_id); if (!$address_one) { Yii::$service->helper->errors->add('current address id is not belong to current user'); return false; } else { // 从address_id中取出来的字段,查看是否满足必写的要求。 if (!Yii::$service->order->checkRequiredAddressAttr($address_one)) { return false; } $arr['customer_id'] = $customer_id; foreach ($address_one as $k=>$v) { $arr[$k] = $v; } $this->_billing = $arr; } } } } elseif ($billing && is_array($billing)) { // 检查address的必写字段是否都存在 //var_dump($billing);exit; if (!Yii::$service->order->checkRequiredAddressAttr($billing)) { return false; } $this->_billing = $billing; } $shipping_method = isset($post['shipping_method']) ? $post['shipping_method'] : ''; $payment_method = isset($post['payment_method']) ? $post['payment_method'] : ''; // 验证货运方式 if (!$shipping_method) { Yii::$service->helper->errors->add('shipping method can not empty'); return false; } else { //if (!Yii::$service->shipping->ifIsCorrect($shipping_method)) { // Yii::$service->helper->errors->add('shipping method is not correct'); // // return false; //} } // 验证支付方式 if (!$payment_method) { Yii::$service->helper->errors->add('payment method can not empty'); return false; } else { if (!Yii::$service->payment->ifIsCorrectStandard($payment_method)) { Yii::$service->helper->errors->add('payment method is not correct'); return false; } } // 增加event $beforeEventName = 'event_place_order_check_order'; Yii::$service->event->trigger($beforeEventName, $post); $eventCheckErr = Yii::$service->event->getErrStr(); // 事件检查结果,是否存在报错,得到报错信息 if ($eventCheckErr) { Yii::$service->helper->errors->add($eventCheckErr); return false; } // 订单备注信息不能超过1500字符 $orderRemarkStrMaxLen = Yii::$service->order->orderRemarkStrMaxLen; $order_remark = isset($post['order_remark']) ? $post['order_remark'] : ''; if ($order_remark && $orderRemarkStrMaxLen) { $order_remark_strlen = strlen($order_remark); if ($order_remark_strlen > $orderRemarkStrMaxLen) { Yii::$service->helper->errors->add('order remark string length can not gt {orderRemarkStrMaxLen}', ['orderRemarkStrMaxLen' => $orderRemarkStrMaxLen]); return false; } else { // 去掉xss攻击字符,关于防止xss攻击的yii文档参看:http://www.yiichina.com/doc/guide/2.0/security-best-practices#fang-zhi-xss-gong-ji $this->_order_remark = $order_remark; } } $this->_shipping_method = $shipping_method; $this->_payment_method = $payment_method; Yii::$service->payment->setPaymentMethod($this->_payment_method); return true; }
@param $post | Array @return bool 检查前台传递的信息是否正确。同时初始化一部分类变量
checkOrderInfoAndInit
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Placeorder.php
BSD-3-Clause
public function initAddress() { //$this->_cart_address = Yii::$service->cart->quote->getCartAddress(); $cart = Yii::$service->cart->quote->getCart(); $address_id = $cart['customer_address_id']; $address_info = []; if (!Yii::$app->user->isGuest) { $identity = Yii::$app->user->identity; $address_info['email'] = $identity['email']; $address_info['first_name'] = $identity['firstname']; $address_info['last_name'] = $identity['lastname']; } if (isset($cart['customer_email']) && !empty($cart['customer_email'])) { $address_info['email'] = $cart['customer_email']; } if (isset($cart['customer_firstname']) && !empty($cart['customer_firstname'])) { $address_info['first_name'] = $cart['customer_firstname']; } if (isset($cart['customer_lastname']) && !empty($cart['customer_lastname'])) { $address_info['last_name'] = $cart['customer_lastname']; } if (isset($cart['customer_telephone']) && !empty($cart['customer_telephone'])) { $address_info['telephone'] = $cart['customer_telephone']; } if (isset($cart['customer_address_country']) && !empty($cart['customer_address_country'])) { $address_info['country'] = $cart['customer_address_country']; $this->_country = $address_info['country']; } if (isset($cart['customer_address_state']) && !empty($cart['customer_address_state'])) { $address_info['state'] = $cart['customer_address_state']; } if (isset($cart['customer_address_city']) && !empty($cart['customer_address_city'])) { $address_info['city'] = $cart['customer_address_city']; } if (isset($cart['customer_address_zip']) && !empty($cart['customer_address_zip'])) { $address_info['zip'] = $cart['customer_address_zip']; } if (isset($cart['customer_address_street1']) && !empty($cart['customer_address_street1'])) { $address_info['street1'] = $cart['customer_address_street1']; } if (isset($cart['customer_address_street2']) && !empty($cart['customer_address_street2'])) { $address_info['street2'] = $cart['customer_address_street2']; } $this->_address = $address_info; $this->_address_list = Yii::$service->customer->address->currentAddressList(); //var_dump($this->_address_list); // 如果购物车存在customer_address_id,而且用户地址中也存在customer_address_id // 则执行if{}内代码。 if ($address_id && isset($this->_address_list[$address_id]) && !empty($this->_address_list[$address_id])) { $this->_address_id = $address_id; $this->_address_view_file = 'checkout/onepage/index/address_select.php'; $addressModel = Yii::$service->customer->address->getByPrimaryKey($this->_address_id); if ($addressModel['country']) { $this->_country = $addressModel['country']; $this->_address['country'] = $this->_country; } if ($addressModel['state']) { $this->_state = $addressModel['state']; $this->_address['state'] = $this->_state; } if ($addressModel['first_name']) { $this->_address['first_name'] = $addressModel['first_name']; } if ($addressModel['last_name']) { $this->_address['last_name'] = $addressModel['last_name']; } if ($addressModel['email']) { $this->_address['email'] = $addressModel['email']; } if ($addressModel['telephone']) { $this->_address['telephone'] = $addressModel['telephone']; } if ($addressModel['street1']) { $this->_address['street1'] = $addressModel['street1']; } if ($addressModel['street2']) { $this->_address['street2'] = $addressModel['street2']; } if ($addressModel['city']) { $this->_address['city'] = $addressModel['city']; } if ($addressModel['zip']) { $this->_address['zip'] = $addressModel['zip']; } } elseif (is_array($this->_address_list) && !empty($this->_address_list)) { // 用户存在地址列表,但是,cart中没有customer_address_id // 这种情况下,从用户地址列表中取出来默认地址,然后设置成当前的地址。 foreach ($this->_address_list as $adss_id => $info) { if ($info['is_default'] == 1) { $this->_address_id = $adss_id; $this->_address_view_file = 'checkout/onepage/index/address_select.php'; $addressModel = Yii::$service->customer->address->getByPrimaryKey($this->_address_id); if ($addressModel['country']) { $this->_country = $addressModel['country']; $this->_address['country'] = $this->_country; } if ($addressModel['state']) { $this->_state = $addressModel['state']; $this->_address['state'] = $this->_state; } if ($addressModel['first_name']) { $this->_address['first_name'] = $addressModel['first_name']; } if ($addressModel['last_name']) { $this->_address['last_name'] = $addressModel['last_name']; } if ($addressModel['email']) { $this->_address['email'] = $addressModel['email']; } if ($addressModel['telephone']) { $this->_address['telephone'] = $addressModel['telephone']; } if ($addressModel['street1']) { $this->_address['street1'] = $addressModel['street1']; } if ($addressModel['street2']) { $this->_address['street2'] = $addressModel['street2']; } if ($addressModel['city']) { $this->_address['city'] = $addressModel['city']; } if ($addressModel['zip']) { $this->_address['zip'] = $addressModel['zip']; } break; } } } else { $this->_address_view_file = 'checkout/onepage/index/address.php'; // 从购物车里面取出来数据。 $_cartAddress //$cart_info = Yii::$service->cart->getCartInfo(); } if (!$this->_country) { $this->_country = Yii::$service->helper->country->getDefaultCountry(); $this->_address['country'] = $this->_country; } }
初始化地址信息,首先从当前用户里面取值,然后从cart表中取数据覆盖 1. 初始化 $this->_address,里面保存的各个地址信息。 2. 如果是登录用户,而且.
initAddress
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function initCountry() { $this->_countrySelect = Yii::$service->helper->country->getAllCountryOptions('', '', $this->_country); }
初始化国家下拉条。
initCountry
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function initState($country = '') { $state = isset($this->_address['state']) ? $this->_address['state'] : ''; if (!$country) { $country = $this->_country; } $stateHtml = Yii::$service->helper->country->getStateOptionsByContryCode($country, $state); if (!$stateHtml) { $stateHtml = '<input id="state" placeholder="'. Yii::$service->page->translate->__('Your State').'" name="billing[state]" value="'.$state.'" title="State" class="address_state input-text" style="" type="text">'; } else { $stateHtml = '<select id="address:state" class="address_state validate-select" title="State" name="billing[state]"> <option value="">Please select region, state or province</option>' .$stateHtml.'</select>'; } $this->_stateHtml = $stateHtml; }
初始化省市
initState
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function ajaxChangecountry() { $country = Yii::$app->request->get('country'); $country = \Yii::$service->helper->htmlEncode($country); $state = $this->initState($country); echo json_encode([ 'state' => $this->_stateHtml, ]); exit; }
当改变国家的时候,ajax获取省市信息.
ajaxChangecountry
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function getProductOptions($product_one, $custom_option_sku) { $custom_option_info_arr = []; $custom_option = isset($product_one['custom_option']) ? $product_one['custom_option'] : ''; $custom_option_sku = $product_one['custom_option_sku']; if (isset($custom_option[$custom_option_sku]) && !empty($custom_option[$custom_option_sku])) { $custom_option_info = $custom_option[$custom_option_sku]; foreach ($custom_option_info as $attr=>$val) { if (!in_array($attr, ['qty', 'sku', 'price', 'image'])) { $attr = str_replace('_', ' ', $attr); $attr = ucfirst($attr); $custom_option_info_arr[$attr] = $val; } } } $spu_options = $product_one['spu_options']; if (is_array($spu_options) && !empty($spu_options)) { foreach ($spu_options as $label => $val) { $custom_option_info_arr[$label] = $val; } } return $custom_option_info_arr; }
将产品页面选择的颜色尺码等显示出来,包括custom option 和spu options部分的数据.
getProductOptions
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function getShippings($custom_shipping_method = '') { $country = $this->_country; if (!$this->_state) { $region = '*'; } else { $region = $this->_state; } $cartProductInfo = Yii::$service->cart->quoteItem->getCartProductInfo(); //echo $country ; $product_weight = $cartProductInfo['product_weight']; $product_volume_weight = $cartProductInfo['product_volume_weight']; $product_final_weight = max($product_weight, $product_volume_weight); $cartShippingMethod = $this->_cart_info['shipping_method']; //echo "$custom_shipping_method,$cartShippingMethod"; $current_shipping_method = Yii::$service->shipping->getCurrentShippingMethod($custom_shipping_method, $cartShippingMethod, $country, $region, $product_final_weight); $this->_shipping_method = $current_shipping_method; // 得到所有,有效的shipping method $shippingArr = $this->getShippingArr($product_final_weight, $current_shipping_method, $country, $region); return $shippingArr; }
@param $current_shipping_method | String 当前选择的货运方式 @return Array,数据格式为: * [ 'method'=> $method, 'label' => $label, 'name' => $name, 'cost' => $symbol.$currentCurrencyCost, 'check' => $check, 'shipping_i' => $shipping_i, ] 得到所有的,有效shipping method数组。
getShippings
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function getPayment() { $paymentArr = Yii::$service->payment->getStandardPaymentArr(); $pArr = []; if (!$this->_payment_method) { if (isset($this->_cart_info['payment_method']) && !empty($this->_cart_info['payment_method'])) { $this->_payment_method = $this->_cart_info['payment_method']; } //echo $this->_payment_method; if (!$this->_payment_method) { $i = 0; foreach ($paymentArr as $k => $v) { $i++; if ($i == 1) { $this->_payment_method = $k; $v['checked'] = true; } $pArr[$k] = $v; } } else { $checked_payment = 0; foreach ($paymentArr as $k => $v) { if ($this->_payment_method == $k) { $v['checked'] = true; $checked_payment = 1; } $pArr[$k] = $v; } if (!$checked_payment) { foreach ($paymentArr as $k => $v) { $this->_payment_method = $k; $pArr[$k]['checked'] = true; break; } } //var_dump($paymentArr); } } return $pArr; }
@return 得到所有的支付方式 在获取的同时,判断$this->_payment_method 是否存在,不存在则取 第一个支付方式,作为$this->_payment_method的值。
getPayment
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function ajaxUpdateOrderAndShipping() { $country = Yii::$app->request->get('country'); $shipping_method = Yii::$app->request->get('shipping_method'); $address_id = Yii::$app->request->get('address_id'); $state = Yii::$app->request->get('state'); $country = \Yii::$service->helper->htmlEncode($country); $shipping_method = \Yii::$service->helper->htmlEncode($shipping_method); $address_id = \Yii::$service->helper->htmlEncode($address_id); $state = \Yii::$service->helper->htmlEncode($state); if ($address_id) { $this->_address_id = $address_id; $addressModel = Yii::$service->customer->address->getByPrimaryKey($this->_address_id); if ($addressModel['country']) { $country = $addressModel['country']; $this->_country = $addressModel['country']; } if ($addressModel['state']) { $state = $addressModel['state']; $this->_state = $addressModel['state']; } } elseif ($country) { $this->_country = $country; if (!$state) { $state = '*'; } $this->_state = $state; } if ($this->_country && $this->_state) { $shippings = $this->getShippings($shipping_method); $payments = $this->getPayment(); /** * 下面是Fecshop的widget,通过一个一个数据数组+第一个view文件 * 组合得到对应的html代码,返回给$shippingHtml * 由于fecshop多多模板系统,预先从高级别的模板路径中依次查找view文件,存在则使用该view文件. */ $shippingView = [ 'view' => 'checkout/onepage/index/shipping.php', ]; $shippingParam = [ 'shippings' => $shippings, ]; $shippingHtml = Yii::$service->page->widget->render($shippingView, $shippingParam); /** * 先通过item计算出来重量,得到运费 然后setShippingCost($shippingCost),将当前根据传递参数计算 * 出来的运费结果set到quote.shippingCost中, * 原因:这里是用户勾选切换国家地址进行的运费计算反馈给用户,但是该信息不更新到数据库,仅仅显示出来 * 相应的费用给用户看,因此,shippingCost通过传递的参数计算出来设置到quote中,而不是通过数据库中保存 * 的信息计算。 */ $quoteItem = Yii::$service->cart->quoteItem->getCartProductInfo(); $product_weight = $quoteItem['product_weight']; // 计算运费。 $avaiable_method = Yii::$service->shipping->getAvailableShippingMethods($country,$region,$product_weight); $shippingInfo = $avaiable_method[$shipping_method]; $shippingCost = Yii::$service->shipping->getShippingCost($shipping_method, $shippingInfo, $product_weight, $country, $state); Yii::$service->cart->quote->setShippingCost($shippingCost); /** * 下面通过当前的货币,购物车信息等数组数据,+上view文件 * 返回order部分的html内容。 */ // 得到当前货币 $currency_info = Yii::$service->page->currency->getCurrencyInfo(); $reviewOrderView = [ 'view' => 'checkout/onepage/index/review_order.php', ]; $cart_info = $this->getCartInfo(true, $shipping_method, $this->_country, $this->_state); $reviewOrderParam = [ 'cart_info' => $cart_info, 'currency_info' => $currency_info, ]; $reviewOrderHtml = Yii::$service->page->widget->render($reviewOrderView, $reviewOrderParam); echo json_encode([ 'status' => 'success', 'shippingHtml' => $shippingHtml, 'reviewOrderHtml' => $reviewOrderHtml, ]); exit; } }
js函数 ajaxreflush() 执行后,就会执行这个函数 在 1.切换address list, 2.取消coupon, 3.切换国家和省市信息, 4.更改货运方式等 集中情况下,就会触发执行当前函数, 该函数会根据传递的参数,重新计算shipping 和order 部分信息,返回 给前端。 @proeprty Array, @return json_encode(Array),Array格式如下: [ 'status' => 'success', 'shippingHtml' => $shippingHtml, 'reviewOrderHtml' => $reviewOrderHtml, ] 返回给js后,js根据数据将信息更新到相应的部分。
ajaxUpdateOrderAndShipping
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/block/onepage/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/block/onepage/Index.php
BSD-3-Clause
public function actionAdd() { $custom_option = Yii::$app->request->post('custom_option'); $product_id = Yii::$app->request->post('product_id'); $qty = Yii::$app->request->post('qty'); //$custom_option = \Yii::$service->helper->htmlEncode($custom_option); $product_id = \Yii::$service->helper->htmlEncode($product_id); $qty = \Yii::$service->helper->htmlEncode($qty); $qty = abs(ceil((int) $qty)); if ($qty && $product_id) { if ($custom_option) { $custom_option_sku = json_decode($custom_option, true); } if (empty($custom_option_sku)) { $custom_option_sku = null; } $item = [ 'product_id' => $product_id, 'qty' => $qty, 'custom_option_sku' => $custom_option_sku, ]; $innerTransaction = Yii::$app->db->beginTransaction(); try { $addToCart = Yii::$service->cart->addProductToCart($item); if ($addToCart) { echo json_encode([ 'status' => 'success', 'items_count' => Yii::$service->cart->quote->getCartItemCount(), ]); $innerTransaction->commit(); exit; } else { $errors = Yii::$service->helper->errors->get(','); echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__($errors), //'items_count' => Yii::$service->cart->quote->getCartItemCount(), ]); $innerTransaction->rollBack(); exit; } } catch (\Exception $e) { $innerTransaction->rollBack(); } } }
把产品加入到购物车.
actionAdd
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/controllers/CartController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/controllers/CartController.php
BSD-3-Clause
public function actionAddcoupon() { if (Yii::$app->user->isGuest) { // 记忆一下登录成功返回购物车页面 $cartUrl = Yii::$service->url->getUrl('checkout/cart'); Yii::$service->customer->setLoginSuccessRedirectUrl($cartUrl); echo json_encode([ 'status' => 'fail', 'content'=> 'nologin', ]); exit; } $coupon_code = trim(Yii::$app->request->post('coupon_code')); $coupon_code = \Yii::$service->helper->htmlEncode($coupon_code); if ($coupon_code) { $innerTransaction = Yii::$app->db->beginTransaction(); try { if (Yii::$service->cart->coupon->addCoupon($coupon_code)) { $innerTransaction->commit(); } else { $innerTransaction->rollBack(); } } catch (\Exception $e) { $innerTransaction->rollBack(); } $error_arr = Yii::$service->helper->errors->get(); if (!empty($error_arr)) { $error_str = implode(',', $error_arr); echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__($error_str), ]); exit; } else { echo json_encode([ 'status' => 'success', 'content'=> Yii::$service->page->translate->__('add coupon success'), ]); exit; } } else { echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__('coupon is empty'), ]); exit; } }
购物车中添加优惠券.
actionAddcoupon
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/controllers/CartController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/controllers/CartController.php
BSD-3-Clause
public function actionCancelcoupon() { if (Yii::$app->user->isGuest) { // 记忆一下登录成功返回购物车页面 $cartUrl = Yii::$service->url->getUrl('checkout/cart'); Yii::$service->customer->setLoginSuccessRedirectUrl($cartUrl); echo json_encode([ 'status' => 'fail', 'content'=> 'nologin', ]); exit; } $coupon_code = trim(Yii::$app->request->post('coupon_code')); if ($coupon_code) { $innerTransaction = Yii::$app->db->beginTransaction(); try { $cancelStatus = Yii::$service->cart->coupon->cancelCoupon($coupon_code); if (!$cancelStatus) { echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__('coupon is not exist'), ]); $innerTransaction->rollBack(); exit; } $error_arr = Yii::$service->helper->errors->get(true); if (!empty($error_arr)) { if (is_array($error_arr)) { $error_str = implode(',', $error_arr); } else { $error_str = $error_arr; } echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__($error_str), ]); $innerTransaction->rollBack(); exit; } else { echo json_encode([ 'status' => 'success', 'content'=> Yii::$service->page->translate->__('cacle coupon success'), ]); $innerTransaction->commit(); exit; } } catch (\Exception $e) { $innerTransaction->rollBack(); } } else { echo json_encode([ 'status' => 'fail', 'content'=> Yii::$service->page->translate->__('coupon is empty'), ]); exit; } }
购物车中取消优惠券.
actionCancelcoupon
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/controllers/CartController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/controllers/CartController.php
BSD-3-Clause
public function actionIndex() { $guestOrder = Yii::$app->store->get('order', 'guestOrder'); if($guestOrder != Yii::$app->store->enable && Yii::$app->user->isGuest){ $checkoutOrderUrl = Yii::$service->url->getUrl('checkout/onepage/index'); Yii::$service->customer->setLoginSuccessRedirectUrl($checkoutOrderUrl); return Yii::$service->url->redirectByUrlKey('customer/account/login'); } $_csrf = Yii::$app->request->post('_csrf'); if ($_csrf) { $status = $this->getBlock('placeorder')->getLastData(); if (!$status) { //var_dump(Yii::$service->helper->errors->get()); //exit; } } $data = $this->getBlock()->getLastData(); if (is_array($data) && !empty($data)) { return $this->render($this->action->id, $data); } else { return $data; } }
public function init(){ Yii::$service->page->theme->layoutFile = 'one_step_checkout.php'; }
actionIndex
php
fecshop/yii2_fecshop
app/apphtml5/modules/Checkout/controllers/OnepageController.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Checkout/controllers/OnepageController.php
BSD-3-Clause
protected function getAjaxProductHtml($products) { $parentThis['products'] = $products; $config = [ 'view' => 'cms/home/index/product.php', ]; $html = Yii::$service->page->widget->renderContent('category_product_price', $config, $parentThis); echo json_encode([ 'html' => $html, ]); exit; }
@param $products | Array ,产品数组 得到分类产品数据
getAjaxProductHtml
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getProductPage() { $productNumPerPage = $this->getNumPerPage(); $productCount = $this->_productCount; $pageNum = $this->getPageNum(); $this->_page_count = ceil($productCount / $productNumPerPage); $config = [ 'class' => 'fecshop\app\apphtml5\widgets\Page', 'view' => 'widgets/page.php', 'pageNum' => $pageNum, 'numPerPage' => $productNumPerPage, 'countTotal' => $productCount, 'page' => $this->_page, ]; return Yii::$service->page->widget->renderContent('category_product_page', $config); }
得到toolbar的分页部分
getProductPage
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getFilterAttr() { if (!$this->_filter_attr) { $this->_filter_attr = $filterAttr = Yii::$service->search->filterAttr; } return $this->_filter_attr; }
得到侧栏属性过滤属性
getFilterAttr
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getFormatFilterPrice($price_item) { list($f_price, $l_price) = explode('-', $price_item); $str = ''; if ($f_price == '0' || $f_price) { $f_price = Yii::$service->product->price->formatPrice($f_price); $str .= $f_price['symbol'].$f_price['value'].'---'; } if ($l_price) { $l_price = Yii::$service->product->price->formatPrice($l_price); $str .= $l_price['symbol'].$l_price['value']; } return $str; }
产品价格显示格式处理
getFormatFilterPrice
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getOrderBy() { $primaryKey = Yii::$service->category->getPrimaryKey(); $sort = Yii::$app->request->get($this->_sort); $direction = Yii::$app->request->get($this->_direction); $category_query_config = Yii::$app->controller->module->params['category_query']; if (isset($category_query_config['sort'])) { $sortConfig = $category_query_config['sort']; if (is_array($sortConfig)) { //return $category_query_config['numPerPage'][0]; if ($sort && isset($sortConfig[$sort])) { $orderInfo = $sortConfig[$sort]; } else { foreach ($sortConfig as $k => $v) { $orderInfo = $v; if (!$direction) { $direction = $v['direction']; } break; } } $db_columns = $orderInfo['db_columns']; if ($direction == 'desc') { $direction = -1; } else { $direction = 1; } //var_dump([$db_columns => $direction]); return [$db_columns => $direction]; } } }
得到排序数组,用于查询。
getOrderBy
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getNumPerPage() { if (!$this->_numPerPageVal) { $numPerPage = Yii::$app->request->get($this->_numPerPage); $category_query_config = Yii::$app->controller->module->params['search_query']; if (!$numPerPage) { if (isset($category_query_config['numPerPage'])) { if (is_array($category_query_config['numPerPage'])) { $this->_numPerPageVal = $category_query_config['numPerPage'][0]; } } } elseif (!$this->_numPerPageVal) { if (isset($category_query_config['numPerPage']) && is_array($category_query_config['numPerPage'])) { $numPerPageArr = $category_query_config['numPerPage']; if (in_array((int) $numPerPage, $numPerPageArr)) { $this->_numPerPageVal = $numPerPage; } else { throw new InvalidValueException('Incorrect numPerPage value:'.$numPerPage); } } } } return $this->_numPerPageVal; }
得到每页显示的产品的个数。
getNumPerPage
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getPageNum() { $numPerPage = Yii::$app->request->get($this->_page); return $numPerPage ? (int) $numPerPage : 1; }
得到第几页
getPageNum
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function getSearchProductColl() { $select = [ 'product_id','sku', 'spu', 'name', 'image', 'price', 'special_price', 'special_from', 'special_to', 'brand_id','is_in_stock', 'url_key', 'score', ]; $where = $this->_where; $search_text = Yii::$app->controller->module->params['search_query']; $pageNum = $this->getPageNum(); $numPerPage = $this->getNumPerPage(); $product_search_max_count = Yii::$app->controller->module->params['product_search_max_count']; $filterAttr = $this->getFilterAttr(); return Yii::$service->search->getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count, $filterAttr); }
得到搜索的产品collection
getSearchProductColl
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function initSearch() { //$primaryKey = Yii::$service->category->getPrimaryKey(); //$primaryVal = Yii::$app->request->get($primaryKey); //$this->_primaryVal = $primaryVal; //$category = Yii::$service->category->getByPrimaryKey($primaryVal); //$this->_category = $category ; $searchText = Yii::$app->request->get('q'); $searchText = \Yii::$service->helper->htmlEncode($searchText); $this->_searchText = $searchText; $search_page_title_format = Yii::$app->controller->module->params['search_page_title_format']; $search_page_meta_keywords_format = Yii::$app->controller->module->params['search_page_meta_keywords_format']; $search_page_meta_description_format = Yii::$app->controller->module->params['search_page_meta_description_format']; $this->breadcrumbs(); if ($search_page_title_format) { $title = str_replace('%s', $searchText, $search_page_title_format); } else { $title = $searchText; } if ($search_page_meta_keywords_format) { $meta_keywords = str_replace('%s', $searchText, $search_page_meta_keywords_format); } else { $meta_keywords = $searchText; } if ($search_page_meta_description_format) { $meta_description = str_replace('%s', $searchText, $search_page_meta_description_format); } else { $meta_description = $searchText; } Yii::$app->view->registerMetaTag([ 'name' => 'keywords', 'content' => $meta_keywords, ]); Yii::$app->view->registerMetaTag([ 'name' => 'description', 'content' => $meta_description, ]); $this->_title = $title; Yii::$app->view->title = $this->_title; $this->_where = $this->initWhere(); }
初始化部分
initSearch
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
protected function breadcrumbs() { if (Yii::$app->controller->module->params['search_breadcrumbs']) { Yii::$service->page->breadcrumbs->addItems(['name' => $this->_searchText]); } else { Yii::$service->page->breadcrumbs->active = false; } }
面包屑导航
breadcrumbs
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalogsearch/block/index/Index.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalogsearch/block/index/Index.php
BSD-3-Clause
public function getLastData() { $product_id = Yii::$app->request->post('product_id'); //没有登录的用户跳转到登录页面 if (Yii::$app->user->isGuest) { $product = Yii::$service->product->getByPrimaryKey($product_id); $url = Yii::$service->url->getUrl($product['url_key']); Yii::$service->customer->setLoginSuccessRedirectUrl($url); return Yii::$service->url->redirectByUrlKey('customer/account/login'); } $identity = Yii::$app->user->identity; $user_id = $identity->id; $addStatus = Yii::$service->product->favorite->add($product_id, $user_id); if (!$addStatus) { Yii::$service->page->message->addByHelperErrors(); } //$favoriteParam = Yii::$app->getModule('catalog')->params['favorite']; $appName = Yii::$service->helper->getAppName(); $category_breadcrumbs = Yii::$app->store->get($appName.'_catalog','favorite_addSuccessRedirectFavoriteList'); // 跳转。 if ($category_breadcrumbs == Yii::$app->store->enable) { return Yii::$service->url->redirectByUrlKey('customer/productfavorite'); } else { $product = Yii::$service->product->getByPrimaryKey($product_id); $urlKey = $product['url_key']; return Yii::$service->url->redirectByUrlKey($urlKey); } }
用户添加收藏产品
getLastData
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/favoriteproduct/Add.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/favoriteproduct/Add.php
BSD-3-Clause
public function getAddCaptcha() { if (!$this->_add_captcha) { $appName = Yii::$service->helper->getAppName(); $addCaptcha = Yii::$app->store->get($appName.'_catalog','review_add_captcha'); // $reviewParam = Yii::$app->getModule('catalog')->params['review']; $this->_add_captcha = ($addCaptcha == Yii::$app->store->enable) ? true : false; } return $this->_add_captcha; }
@return boolean , review页面是否开启验证码验证。
getAddCaptcha
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
BSD-3-Clause
protected function getProductPriceInfo($product) { $price = $product['price']; $special_price = $product['special_price']; $special_from = $product['special_from']; $special_to = $product['special_to']; return Yii::$service->product->price->getCurrentCurrencyProductPriceInfo($price, $special_price, $special_from, $special_to); }
@param $product | String Or Object 得到产品的价格信息
getProductPriceInfo
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
BSD-3-Clause
protected function getSpuData() { $spu = $this->_product['spu']; $filter = [ 'select' => ['size'], 'where' => [ ['spu' => $spu], ], 'asArray' => true, ]; $coll = Yii::$service->product->coll($filter); if (is_array($coll['coll']) && !empty($coll['coll'])) { foreach ($coll['coll'] as $one) { $spu = $one['spu']; } } }
废弃
getSpuData
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Add.php
BSD-3-Clause
protected function getProductPage($countTotal) { if ($countTotal <= $this->numPerPage) { //echo "$countTotal <= $this->numPerPage"; return ''; } $config = [ 'class' => 'fecshop\app\apphtml5\widgets\Page', 'view' => 'widgets/page.php', 'pageNum' => $this->pageNum, 'numPerPage' => $this->numPerPage, 'countTotal' => $countTotal, 'page' => $this->_page, ]; return Yii::$service->page->widget->renderContent('category_product_page', $config); }
@param $countTotal | Int 得到toolbar的分页部分
getProductPage
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
BSD-3-Clause
public function initParam() { $this->pageNum = Yii::$app->request->get($this->_page); $this->pageNum = $this->pageNum ? $this->pageNum : 1; $this->spu = Yii::$app->request->get('spu'); $this->product_id = Yii::$app->request->get('_id'); // $review = Yii::$app->getModule('catalog')->params['review']; $appName = Yii::$service->helper->getAppName(); $reviewPageReviewCount = Yii::$app->store->get($appName.'_catalog','review_reviewPageReviewCount'); //$productPageReviewCount = $reviewPageReviewCount ? $reviewPageReviewCount : 10; $this->numPerPage = $reviewPageReviewCount ? $reviewPageReviewCount : $this->numPerPage; }
初始化参数
initParam
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
BSD-3-Clause
protected function getProductPriceInfo($product) { $price = $product['price']; $special_price = $product['special_price']; $special_from = $product['special_from']; $special_to = $product['special_to']; return Yii::$service->product->price->getCurrentCurrencyProductPriceInfo($price, $special_price, $special_from, $special_to); }
产品价格信息
getProductPriceInfo
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/reviewproduct/Lists.php
BSD-3-Clause
public function getAllItems() { $custom_option_attr_info = Yii::$service->product->getCustomOptionAttrInfo($this->attr_group); //######### $my_arr = []; $arr = []; //#在custom_option里面第一个属性 $img_attr = ''; if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) { foreach ($custom_option_attr_info as $attr => $info) { if (isset($info['showAsImg']) && $info['showAsImg']) { $img_attr = $attr; break; } } } $img_arr = []; if (is_array($this->custom_option) && (!empty($this->custom_option))) { foreach ($this->custom_option as $option) { $qty = $option['qty']; if ($qty > 0) { $this->_custom_option_arr[] = $option; if (isset($option[$img_attr])) { $val = $option[$img_attr]; $img_arr[$val] = $option['image']; } foreach ($option as $k=>$v) { $my_arr[$k][] = $v; } } } } if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) { foreach ($custom_option_attr_info as $attr => $info) { if (isset($info['display']['type']) && ($info['display']['type'] == 'select')) { if (isset($info['display']['data']) && is_array($info['display']['data'])) { foreach ($info['display']['data'] as $val) { if (is_array($my_arr[$attr]) && in_array($val, $my_arr[$attr])) { $t_arr = [ 'key' => $val, 'val' => $val, ]; $require = isset($info['require']) ? $info['require'] : 0; if (isset($info['showAsImg']) && $info['showAsImg']) { if (isset($img_arr[$val])) { $t_arr['image'] = $img_arr[$val]; } } $arr[$attr]['info'][] = $t_arr; $arr[$attr]['require'] = $require; } } } } } } return $arr; }
得到custom option 部分
getAllItems
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/product/CustomOption.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/product/CustomOption.php
BSD-3-Clause
public function getLastData() { if (!$this->spu || !$this->product_id) { return; } if ($this->filterBySpu) { $data = $this->getReviewsBySpu($this->spu); $count = $data['count']; $coll = $data['coll']; return [ '_id' => $this->product_id, 'spu' => $this->spu, 'coll' => $coll, 'noActiveStatus'=> Yii::$service->product->review->noActiveStatus(), 'reviw_rate_star_info' => $this->reviw_rate_star_info, 'review_count' => $this->review_count, 'reviw_rate_star_average' => $this->reviw_rate_star_average, ]; } }
得到当前spu下面的所有评论信息。
getLastData
php
fecshop/yii2_fecshop
app/apphtml5/modules/Catalog/block/product/Review.php
https://github.com/fecshop/yii2_fecshop/blob/master/app/apphtml5/modules/Catalog/block/product/Review.php
BSD-3-Clause