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 getStatusArr()
{
return [
$this->status_enable => Yii::$service->page->translate->__('Enable'),
$this->status_disable => Yii::$service->page->translate->__('Disable'),
];
} | 得到状态数组 | getStatusArr | php | fecshop/yii2_fecshop | services/product/Brandcategory.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Brandcategory.php | BSD-3-Clause |
public function formatPrice($price)
{
$currencyInfo = $this->getCurrentInfo();
$price = Yii::$service->helper->format->numberFormat($price * $currencyInfo['rate']);
return [
'code' => $currencyInfo['code'],
'symbol' => $currencyInfo['symbol'],
'value' => $price,
];
} | @param $price | Float 产品的价格
得到当前货币状态下的产品的价格信息。 | formatPrice | php | fecshop/yii2_fecshop | services/product/Price.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php | BSD-3-Clause |
public function formatSamplePrice($price)
{
$currencyInfo = $this->getCurrentInfo();
$price = $price * $currencyInfo['rate'];
$price = Yii::$service->helper->format->numberFormat($price);
return $currencyInfo['symbol'].$price;
} | @param $price | Float 产品价格
@return String , 带有相应货币符号的价格 | formatSamplePrice | php | fecshop/yii2_fecshop | services/product/Price.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php | BSD-3-Clause |
public function getCartPriceByProductId($productId, $qty, $custom_option_sku, $format = 1)
{
$product = Yii::$service->product->getByPrimaryKey($productId);
$custom_option_price = 0;
$status = isset($product['status']) ? $product['status'] : 0;
if ($product['price'] && Yii::$service->product->isActive($status)) {
$price = $product['price'];
$special_price = isset($product['special_price']) ? $product['special_price'] : 0;
$special_from = isset($product['special_from']) ? $product['special_from'] : '';
$special_to = isset($product['special_to']) ? $product['special_to'] : '';
$tier_price = isset($product['tier_price']) ? $product['tier_price'] : [];
$custom_option = isset($product['custom_option']) ? $product['custom_option'] : '';
if (!empty($custom_option) && $custom_option_sku && isset($custom_option[$custom_option_sku])) {
if ($co = $custom_option[$custom_option_sku]) {
$custom_option_price = isset($co['price']) ? $co['price'] : 0;
}
}
return $this->getCartPrice(
$price,
$special_price,
$special_from,
$special_to,
$qty,
$custom_option_price,
$tier_price,
$format
);
}
} | @param $productId | String
@param $qty | Int
@param $custom_option_sku | String
@param $format | Int , 返回的价格的格式,0代表为美元格式,1代表为当前货币格式,2代表美元和当前货币格式都有
通过产品以及个数,custonOptionSku 得到产品的最终价格 | getCartPriceByProductId | php | fecshop/yii2_fecshop | services/product/Price.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php | BSD-3-Clause |
protected function getCurrentInfo()
{
if (!$this->_currencyInfo) {
$this->_currencyInfo = Yii::$service->page->currency->getCurrencyInfo();
}
return $this->_currencyInfo;
} | 得到当前的货币信息,并保存到对象属性中,方便多次调用. | getCurrentInfo | php | fecshop/yii2_fecshop | services/product/Price.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php | BSD-3-Clause |
public function getCurrentCurrencyProductPriceInfo($price, $special_price, $special_from, $special_to)
{
$price = (float)$price;
$special_price = (float)$special_price;
$special_from = (int)$special_from;
$special_to = (int)$special_to;
$this->currentOff = 0;
$price_info = $this->formatPrice($price);
$return['price'] = [
'symbol' => $price_info['symbol'],
'value' => $price_info['value'],
'code' => $price_info['code'],
];
$specialIsActive = $this->specialPriceisActive($price, $special_price, $special_from, $special_to);
if ($specialIsActive) {
$special_price_info = Yii::$service->product->price->formatPrice($special_price);
$return['special_price'] = [
'symbol' => $special_price_info['symbol'],
'value' => $special_price_info['value'],
'code' => $special_price_info['code'],
];
if ($price_info['value'] > 0) {
$off = ($price_info['value'] - $special_price_info['value']) / $price_info['value'];
$this->currentOff = round($off * 100);
}
}
return $return;
} | 通过该函数,得到产品的价格信息,如果特价是active的,则会有特价信息。
@param $price | Float 产品的价格
@param $special_price | Float 产品的特价
@param $special_from | Int 产品的特检开始时间
@param $special_to | Int 产品的特检结束时间
@return $return | Array 产品的价格信息 | getCurrentCurrencyProductPriceInfo | php | fecshop/yii2_fecshop | services/product/Price.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php | BSD-3-Clause |
public function getCategoryProduct()
{
return 'category best sell product';
} | 得到全部产品中热销的产品 | getCategoryProduct | php | fecshop/yii2_fecshop | services/product/BestSell.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/BestSell.php | BSD-3-Clause |
public function getProduct()
{
} | 得到全部产品中热销的产品 | getProduct | php | fecshop/yii2_fecshop | services/product/BestSell.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/BestSell.php | BSD-3-Clause |
public function getEnableStatus()
{
$model = $this->_productModel;
return $model::STATUS_ENABLE;
} | 得到分类激活状态的值 | getEnableStatus | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function getBySku($sku, $returnArr = true)
{
if ($sku) {
if ($returnArr) {
$product = $this->_productModel->find()->asArray()
->where(['sku' => $sku])
->one();
} else {
$product = $this->_productModel->findOne(['sku' => $sku]);
}
$primaryKey = $this->getPrimaryKey();
if (isset($product[$primaryKey]) && !empty($product[$primaryKey])) {
return $this->unserializeData($product) ;
}
}
} | @param $sku|array
@param $returnArr|bool 返回的数据是否是数组格式,如果设置为
false,则返回的是对象数据
@return array or Object
通过sku 获取产品,一个产品 | getBySku | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function getBySpu($spu, $returnArr = true)
{
if ($spu) {
if ($returnArr) {
return $this->_productModel->find()->asArray()
->where(['spu' => $spu])
->all();
} else {
return $this->_productModel->find()
->where(['spu' => $spu])
->all();
}
}
} | @param $spu|array
@param $returnArr|bool 返回的数据是否是数组格式,如果设置为
false,则返回的是对象数据
@return array or Object
通过spu 获取产品数组 | getBySpu | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function apiGetByPrimaryKey($primaryKey)
{
$one = $this->getByPrimaryKey($primaryKey);
if (!$one || !$one['sku']) {
return null;
}
return $one;
} | @param $primaryKey | String 主键
@return array ,和getByPrimaryKey()的不同在于,该方式不走active record,因此可以获取产品的所有数据的。 | apiGetByPrimaryKey | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function apiSave($product_one)
{
$this->save($product_one);
return true;
} | @param $product_one | String 产品数据数组。这个要和mongodb里面保存的产品数据格式一致。
通过api保存产品 | apiSave | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function apiDelete($primaryKey)
{
$this->remove($primaryKey);
return true;
} | @param $primaryKey | String
通过api删除产品 | apiDelete | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function addGroupAttrs($attr_group)
{
$attrInfo = Yii::$service->product->getGroupAttrInfo($attr_group);
if (is_array($attrInfo) && !empty($attrInfo)) {
$attrs = array_keys($attrInfo);
$this->_productModel->addCustomProductAttrs($attrs);
}
} | @param $attr_group | String
根据产品的属性组名,得到属性数组,然后将属性数组附加到Product(model)的属性中。 | addGroupAttrs | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
protected function serializeSaveData($one)
{
// 得到
$attr_group = $one['attr_group'];
$groupAttrs = Yii::$service->product->getGroupAttr($attr_group);
$groupArr = [];
if (is_array($one['attr_group_info']) && !empty($one['attr_group_info'])) {
$groupArr = $one['attr_group_info'];
}
foreach ($one as $k => $v) {
if (in_array($k, $this->serializeAttrs)) {
$one[$k] = serialize($v);
}
if (is_array($groupAttrs) && in_array($k, $groupAttrs)) {
$groupArr[$k] = $v;
unset($one[$k]);
}
}
$one['attr_group_info'] = serialize($groupArr);
return $one;
} | 保存的数据进行serialize序列化 | serializeSaveData | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
protected function unserializeData($one, $withCategory = false)
{
if (!is_array($one) && !is_object($one)) {
return $one;
}
foreach ($one as $k => $v) {
if (in_array($k, $this->serializeAttrs)) {
$one[$k] = unserialize($v);
}
}
if ($withCategory) {
$one['category'] = $this->getCategoryIdsByProductId($one['id']);
}
return $one;
} | 保存的数据进行serialize序列化 | unserializeData | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
protected function initSave(&$one)
{
$primaryKey = $this->getPrimaryKey();
$PrimaryVal = 1;
if (!isset($one[$primaryKey]) || !$one[$primaryKey]) {
$PrimaryVal = 0;
}
if (!$PrimaryVal && (!isset($one['sku']) || empty($one['sku']))) {
Yii::$service->helper->errors->add('sku must exist');
return false;
}
if (!$PrimaryVal && (!isset($one['spu']) || empty($one['spu']))) {
Yii::$service->helper->errors->add('spu must exist');
return false;
}
$defaultLangName = \Yii::$service->fecshoplang->getDefaultLangAttrName('name');
if ($PrimaryVal && $one['name'] && empty($one['name'][$defaultLangName])) {
Yii::$service->helper->errors->add('name {default_lang_name} can not empty', ['default_lang_name' => $defaultLangName]);
return false;
}
if (!isset($one['name'][$defaultLangName]) || empty($one['name'][$defaultLangName])) {
Yii::$service->helper->errors->add('name {default_lang_name} can not empty', ['default_lang_name' => $defaultLangName]);
return false;
}
$defaultLangDes = \Yii::$service->fecshoplang->getDefaultLangAttrName('description');
if ($PrimaryVal && $one['description'] && empty($one['description'][$defaultLangDes])) {
Yii::$service->helper->errors->add('description {default_lang_des} can not empty', ['default_lang_des' => $defaultLangDes]);
return false;
}
if (!isset($one['description'][$defaultLangDes]) || empty($one['description'][$defaultLangDes])) {
Yii::$service->helper->errors->add('description {default_lang_des} can not empty', ['default_lang_des' => $defaultLangDes]);
return false;
}
return true;
} | @param $one|array
对保存的数据进行数据验证
sku spu 默认语言name , 默认语言description不能为空。 | initSave | php | fecshop/yii2_fecshop | services/product/ProductMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMysqldb.php | BSD-3-Clause |
public function getStatusArr()
{
return [
$this->status_enable => Yii::$service->page->translate->__('Enable'),
$this->status_disable => Yii::$service->page->translate->__('Disable'),
];
} | 得到状态数组 | getStatusArr | php | fecshop/yii2_fecshop | services/product/Brand.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Brand.php | BSD-3-Clause |
public function getBrandNameById($brandId)
{
$brandModel = $this->getByPrimaryKey($brandId);
if (!$brandModel['id']) {
return '';
}
return Yii::$service->store->getStoreAttrVal($brandModel['name'], 'name');
} | @param $brandId | int, 品牌id
根据品牌id,得到品牌的name | getBrandNameById | php | fecshop/yii2_fecshop | services/product/Brand.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Brand.php | BSD-3-Clause |
public function changeToMongoStorage()
{
$this->storage = 'AttrGroupMongodb';
$currentService = $this->getStorageService($this);
$this->_attrGroup = new $currentService();
} | 动态更改为mongodb model | changeToMongoStorage | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function changeToMysqlStorage()
{
$this->storage = 'AttrGroupMysqldb';
$currentService = $this->getStorageService($this);
$this->_attrGroup = new $currentService();
} | 动态更改为mongodb model | changeToMysqlStorage | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function getPrimaryKey()
{
return $this->_attrGroup->getPrimaryKey();
} | get artile's primary key. | getPrimaryKey | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function getByPrimaryKey($primaryKey)
{
return $this->_attrGroup->getByPrimaryKey($primaryKey);
} | get model by primary key. | getByPrimaryKey | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function getByName($name)
{
return $this->_attrGroup->getByName($name);
} | get model by name | getByName | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function save($one)
{
if (!$this->checkSaveOne($one)) {
return false;
}
$attr_ids = $one['attr_ids'];
if (is_array($attr_ids)) {
$one['attr_ids'] = serialize($attr_ids);
}
return $this->_attrGroup->save($one);
} | @param $one|array , save one data .
@param $originUrlKey|string , article origin url key.
save $data to cms model,then,add url rewrite info to system service urlrewrite. | save | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function getByRemoteId($remoteId)
{
return $this->_attr->getByRemoteId($remoteId);
} | get artile model by primary key. | getByRemoteId | php | fecshop/yii2_fecshop | services/product/AttrGroup.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/AttrGroup.php | BSD-3-Clause |
public function getEnableStatus()
{
$model = $this->_productModel;
return $model::STATUS_ENABLE;
} | 得到分类激活状态的值 | getEnableStatus | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function getBySku($sku, $returnArr = true)
{
if ($sku) {
if ($returnArr) {
$product = $this->_productModel->find()->asArray()
->where(['sku' => $sku])
->one();
} else {
$product = $this->_productModel->findOne(['sku' => $sku]);
}
$primaryKey = $this->getPrimaryKey();
if (isset($product[$primaryKey]) && !empty($product[$primaryKey])) {
return $product;
}
}
} | @param $sku|array
@param $returnArr|bool 返回的数据是否是数组格式,如果设置为
false,则返回的是对象数据
@return array or Object
通过sku 获取产品,一个产品 | getBySku | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function getBySpu($spu, $returnArr = true)
{
if ($spu) {
if ($returnArr) {
return $this->_productModel->find()->asArray()
->where(['spu' => $spu])
->all();
} else {
return $this->_productModel->find()
->where(['spu' => $spu])
->all();
}
}
} | @param $spu|array
@param $returnArr|bool 返回的数据是否是数组格式,如果设置为
false,则返回的是对象数据
@return array or Object
通过spu 获取产品数组 | getBySpu | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function apiGetByPrimaryKey($primaryKey)
{
$collection = $this->_productModel->find()->getCollection();
$cursor = $collection->findOne(['_id' => $primaryKey]);
$arr = [];
foreach ($cursor as $k => $v) {
$arr[$k] = $v;
}
return $arr;
} | @param $primaryKey | String 主键
@return array ,和getByPrimaryKey()的不同在于,该方式不走active record,因此可以获取产品的所有数据的。 | apiGetByPrimaryKey | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function apiSave($product_one)
{
$collection = $this->_productModel->find()->getCollection();
$collection->save($product_one);
return true;
} | @param $product_one | String 产品数据数组。这个要和mongodb里面保存的产品数据格式一致。
通过api保存产品 | apiSave | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function apiDelete($primaryKey)
{
$collection = $this->_productModel->find()->getCollection();
$collection->remove(['_id' => $primaryKey]);
return true;
} | @param $primaryKey | String
通过api删除产品 | apiDelete | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function addGroupAttrs($attr_group)
{
$attrInfo = Yii::$service->product->getGroupAttrInfo($attr_group);
if (is_array($attrInfo) && !empty($attrInfo)) {
$attrs = array_keys($attrInfo);
$this->_productModel->addCustomProductAttrs($attrs);
}
} | @param $attr_group | String
根据产品的属性组名,得到属性数组,然后将属性数组附加到Product(model)的属性中。 | addGroupAttrs | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function getCategoryIdsByProductIds($product_ids)
{
$coll = $this->_productModel->find()->asArray()
->where([
'in', '_id', $product_ids
])->all();
$categoryIds = [];
foreach ($coll as $one) {
if (isset($one['category']) && !empty($one['category']) && is_array($one['category'])) {
$categoryIds = array_merge($categoryIds, $one['category']);
}
}
return array_unique($categoryIds);
} | @param $product_ids | array, 产品id数组
通过产品id数组,得到分类id数组。 | getCategoryIdsByProductIds | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
protected function initSave(&$one)
{
$primaryKey = $this->getPrimaryKey();
$PrimaryVal = 1;
if (!isset($one[$primaryKey]) || !$one[$primaryKey]) {
$PrimaryVal = 0;
}
if (!$PrimaryVal && (!isset($one['sku']) || empty($one['sku']))) {
Yii::$service->helper->errors->add('sku must exist');
return false;
}
if (!$PrimaryVal && (!isset($one['spu']) || empty($one['spu']))) {
Yii::$service->helper->errors->add('spu must exist');
return false;
}
$defaultLangName = \Yii::$service->fecshoplang->getDefaultLangAttrName('name');
if ($PrimaryVal && $one['name'] && empty($one['name'][$defaultLangName])) {
Yii::$service->helper->errors->add('name {default_lang_name} can not empty', ['default_lang_name' => $defaultLangName]);
return false;
}
if (!isset($one['name'][$defaultLangName]) || empty($one['name'][$defaultLangName])) {
Yii::$service->helper->errors->add('name {default_lang_name} can not empty', ['default_lang_name' => $defaultLangName]);
return false;
}
$defaultLangDes = \Yii::$service->fecshoplang->getDefaultLangAttrName('description');
if ($PrimaryVal && $one['description'] && empty($one['description'][$defaultLangDes])) {
Yii::$service->helper->errors->add('description {default_lang_des} can not empty', ['default_lang_des' => $defaultLangDes]);
return false;
}
if (!isset($one['description'][$defaultLangDes]) || empty($one['description'][$defaultLangDes])) {
Yii::$service->helper->errors->add('description {default_lang_des} can not empty', ['default_lang_des' => $defaultLangDes]);
return false;
}
return true;
} | @param $one|array
对保存的数据进行数据验证
sku spu 默认语言name , 默认语言description不能为空。 | initSave | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function getProducts($filter)
{
$where = $filter['where'];
if (empty($where)) {
return [];
}
$select = $filter['select'];
$query = $this->_productModel->find()->asArray();
$query->where($where);
$query->andWhere(['status' => $this->getEnableStatus()]);
if (is_array($select) && !empty($select)) {
$query->select($select);
}
return $query->all();
} | 通过where条件 和 查找的select 字段信息,得到产品的列表信息,
这里一般是用于前台的区块性的不分页的产品查找。
结果数据没有进行进一步处理,需要前端获取数据后在处理。 | getProducts | php | fecshop/yii2_fecshop | services/product/ProductMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductMongodb.php | BSD-3-Clause |
public function validateProductCustomOption($custom_option, $product_custom_option)
{
if (empty($product_custom_option) && empty($custom_option)) {
return true; // 都为空,说明不需要验证。
}
if ($custom_option) {
$co_sku = $this->getCustomOptionSkuByValue($custom_option);
//$product_custom_option = $product['custom_option'];
if (!is_array($product_custom_option)) {
Yii::$service->helper->errors->add('this product custom option is error');
return;
}
foreach ($product_custom_option as $p_sku => $option) {
if ($p_sku == $co_sku) {
return true;
}
}
}
Yii::$service->helper->errors->add('this product custom option can not find in this product');
return false;
} | @param $custom_option | Array 前台传递的custom option 一维数组。
@param $product_custom_option | Array 数据库中存储的产品custom_option的值
验证前台传递的custom option 是否正确。 | validateProductCustomOption | php | fecshop/yii2_fecshop | services/product/Info.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Info.php | BSD-3-Clause |
public function getProductCOSku($custom_option_arr, $product_custom_option)
{
if (is_array($product_custom_option) && !empty($product_custom_option)) {
foreach ($product_custom_option as $co_sku => $info) {
$bool = true;
if (is_array($info) && !empty($info)) {
foreach ($info as $k=>$v) {
if (isset($custom_option_arr[$k]) && ($custom_option_arr[$k] != $v)) {
$bool = false;
break;
}
}
if ($bool) {
return $co_sku;
}
}
}
}
} | @param $custom_option_arr | Array , 用户选择提交数据,格式为
[
'color' => 'red',
'size' => 'L',
]
@param $product_custom_option | Array , 产品表中的custom_option属性值,譬如:
[
"black-s-s2-s3": [
"my_color": "black",
"my_size": "S",
"my_size2": "S2",
"my_size3": "S3",
"sku": "black-s-s2-s3",
"qty": NumberInt(99999),
"price": 0,
"image": "/2/01/20161024170457_10036.jpg"
],
]
通过前台传递的custom option 得到customOptionSku. | getProductCOSku | php | fecshop/yii2_fecshop | services/product/Info.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Info.php | BSD-3-Clause |
public function changeToMongoStorage()
{
$this->storage = 'ReviewMongodb';
$currentService = $this->getStorageService($this);
$this->_review = new $currentService();
} | 动态更改为mongodb model | changeToMongoStorage | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function changeToMysqlStorage()
{
$this->storage = 'ReviewMysqldb';
$currentService = $this->getStorageService($this);
$this->_review = new $currentService();
} | 动态更改为mongodb model | changeToMysqlStorage | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function getCountBySpu($spu)
{
return $this->_review->getCountBySpu($spu);
} | @param $spu | String.
通过spu找到评论总数。 | getCountBySpu | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function getListBySpu($filter)
{
return $this->_review->getListBySpu($filter);
} | example filter:
[
'numPerPage' => 20,
'pageNum' => 1,
'orderBy' => ['review_date' => SORT_DESC],
where' => [
['spu' => 'uk10001'],
],
'asArray' => true,
]
通过spu找到评论listing. | getListBySpu | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function addReview($review_data)
{
return $this->_review->addReview($review_data);
} | @param $review_data | Array
增加评论 前台增加评论调用的函数。 | addReview | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function lists($filter)
{
return $this->_review->lists($filter);
} | 查看review 的列表 | lists | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function remove($ids)
{
return $this->_review->remove($ids);
} | @param $ids | Array or String
@return boolean
根据提供的ReviewId,删除产品评论 | remove | php | fecshop/yii2_fecshop | services/product/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Review.php | BSD-3-Clause |
public function changeToMongoStorage()
{
$this->storage = 'AttrMongodb';
$currentService = $this->getStorageService($this);
$this->_attr = new $currentService();
} | 动态更改为mongodb model | changeToMongoStorage | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function changeToMysqlStorage()
{
$this->storage = 'AttrMysqldb';
$currentService = $this->getStorageService($this);
$this->_attr = new $currentService();
} | 动态更改为mongodb model | changeToMysqlStorage | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function getPrimaryKey()
{
return $this->_attr->getPrimaryKey();
} | get artile's primary key. | getPrimaryKey | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function getByPrimaryKey($primaryKey)
{
return $this->_attr->getByPrimaryKey($primaryKey);
} | get artile model by primary key. | getByPrimaryKey | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function getByAttrTypeAndName($attr_type, $name)
{
return $this->_attr->getByAttrTypeAndName($attr_type, $name);
} | get artile model by primary key. | getByAttrTypeAndName | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function getByRemoteId($remoteId)
{
return $this->_attr->getByRemoteId($remoteId);
} | get artile model by primary key. | getByRemoteId | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function save($one)
{
if (!$this->checkSaveOne($one)) {
return false;
}
if (is_array($one['display_data'])) {
$one['display_data'] = serialize($one['display_data']);
}
return $this->_attr->save($one);
} | @param $one|array , save one data .
@param $originUrlKey|string , article origin url key.
save $data to cms model,then,add url rewrite info to system service urlrewrite. | save | php | fecshop/yii2_fecshop | services/product/Attr.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Attr.php | BSD-3-Clause |
public function getQtyByProductIds($productIds)
{
if (!is_array($productIds)) {
Yii::$service->helper->errors->add('ProductIds must be Array');
return false;
}
$data = $this->_flatQtyModel->find()->asArray()->where([
'in','product_id',$productIds
])->all();
$arr = [];
foreach ($data as $one) {
$arr[$one['product_id']] = $one['qty'];
}
return $arr;
} | @param $productIds | Array , 字符串数组
@return Array ,example
[
'product_id' => 'qty',
]
得到产品的主库存,对于Custom Option里面的库存,该函数无法获取。 | getQtyByProductIds | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function saveProductStock($product_id, $one)
{
if (!$product_id) {
Yii::$service->helper->errors->add('save product qty error: product is empty');
return false;
}
if (!isset($one['qty'])) {
Yii::$service->helper->errors->add('save product qty error: product qty is empty');
return false;
}
// 保存自定义部分的qty
/*
if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
$custom_option_qty = 0;
//得到所有的产品custom option qty数据
$co_sku_arr = $this->getProductCustomOptionSkuArr($product_id);
$product_sku_arr = [];
foreach ($one['custom_option'] as $custom_option_sku => $c_one) {
$productCustomOptionQty = $this->_COQtyModel->find()
->where([
'product_id' => $product_id,
'custom_option_sku' => $custom_option_sku,
])
->one();
$product_sku_arr[] = $custom_option_sku;
if (!$productCustomOptionQty['product_id']) {
$productCustomOptionQty = new $this->_COQtyModelName;
$productCustomOptionQty->product_id = $product_id;
$productCustomOptionQty->custom_option_sku = $custom_option_sku;
}
$productCustomOptionQty->qty = $c_one['qty'];
$custom_option_qty += $c_one['qty'];
$productCustomOptionQty->save();
}
// 如果是custom option,主库存 = 各个custom option 的库存的相加和
$one['qty'] = $custom_option_qty;
$delete_sku_arr = array_diff($co_sku_arr, $product_sku_arr);
// 删除掉产品中不存在customOptionSku对应的库存、
if (!empty($delete_sku_arr) && is_array($delete_sku_arr)) {
$this->_COQtyModel->deleteAll([
'and',
['product_id' => $product_id],
['in','custom_option_sku',$delete_sku_arr]
]);
}
}
*/
// 保存产品flat qty
$productFlatQty = $this->_flatQtyModel->find()
->where(['product_id' => $product_id])
->one();
if (!$productFlatQty['product_id']) {
$productFlatQty = new $this->_flatQtyModelName;
$productFlatQty->product_id = $product_id;
}
$productFlatQty->qty = $one['qty'];
$productFlatQty->save();
// 更新产品表的qty(此数据为了排序使用)
Yii::$service->product->updateProductFlatQty($product_id, $one['qty']);
return true;
} | @param $product_id | String , mongodb中的产品id字符串
@param $one | Array , data example:
$one = [
'qty' => 44, # sku的库存个数
'custom_option' => [
'red-s-s2-s3' => [
'qty' => 44,
] # 淘宝模式的sku的库存格式,red-s-s2-s3代表自定义属性sku
]
]
由于存在淘宝和京东模式,因此库存有两种,对于单个产品,只有一种是有效的,
对于产品的淘宝和京东模式,可以参看文档:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_product.html# | saveProductStock | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function removeProductStock($product_id)
{
if (!$product_id) {
Yii::$service->helper->errors->add('remove product qty error: product is empty');
}
// 保存产品flat qty
$this->_flatQtyModel->deleteAll(['product_id' => $product_id]);
$this->_COQtyModel->deleteAll(['product_id' => $product_id]);
return true;
} | @param $product_id | String , mongodb中的产品id字符串
产品做删除的时候,需要在mysql中删除掉库存 | removeProductStock | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function checkOnShelfStatus($is_in_stock)
{
if ($is_in_stock == 1) {
return true;
}
return false;
} | @param $is_in_stock | Int, 状态
@return bool
检查产品是否是上架上台 | checkOnShelfStatus | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function getProductFlatQty($product_id)
{
$productFlatQty = $this->_flatQtyModel->find()->asArray()
->where([
'product_id' => $product_id
])->one();
if (isset($productFlatQty['qty'])) {
return $productFlatQty['qty'] ? $productFlatQty['qty'] : 0;
} else {
return 0;
}
} | @param $product_id | String
得到产品的库存个数(Flat Qty) | getProductFlatQty | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function getProductCustomOptionQty($product_id, $onlySku=false)
{
$arr = $this->_COQtyModel->find()->asArray()
->where([
'product_id' => $product_id
])->all();
$r_arr = [];
if (is_array($arr)) {
foreach ($arr as $one) {
$custom_option_sku = $one['custom_option_sku'];
$qty = $one['qty'];
$r_arr[$custom_option_sku] = $qty;
}
}
return $r_arr;
} | @param $product_id | String
@param $onlySku | boolean 返回数组是否只有 $custom_option_sku
得到产品的custom option 部分的库存 | getProductCustomOptionQty | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function getProductCustomOptionSkuArr($product_id)
{
$arr = $this->_COQtyModel->find()->asArray()
->where([
'product_id' => $product_id
])->all();
$sku_arr = [];
if (is_array($arr)) {
foreach ($arr as $one) {
$sku_arr[] = $one['custom_option_sku'];
}
}
return $sku_arr;
} | @param $product_id | String
得到产品的所有custom_option_sku 数组 | getProductCustomOptionSkuArr | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function getProductCustomOptionSkuQty($product_id, $custom_option_sku)
{
$productCustomOptionQty = $this->_COQtyModel->find()->asArray()
->where([
'product_id' => $product_id,
'custom_option_sku' => $custom_option_sku
])->one();
if (isset($productCustomOptionQty['qty'])) {
return $productCustomOptionQty['qty'];
} else {
return 0;
}
} | @param $product_id | String
得到产品的custom option 部分,相应的$custom_option_sku的库存 | getProductCustomOptionSkuQty | php | fecshop/yii2_fecshop | services/product/Stock.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Stock.php | BSD-3-Clause |
public function getBaseUrl()
{
return Yii::$service->image->GetImgUrl($this->imageFloder, 'common');
} | 得到保存产品图片所在相对根目录的url路径. | getBaseUrl | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getBaseDir()
{
return Yii::$service->image->GetImgDir($this->imageFloder, 'common');
} | 得到保存产品图片所在相对根目录的文件夹路径. | getBaseDir | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getUrl($str)
{
return Yii::$service->image->GetImgUrl($this->imageFloder.$str, 'common');
} | 通过产品图片的相对路径得到产品图片的url. | getUrl | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getDir($str)
{
return Yii::$service->image->GetImgDir($this->imageFloder.$str, 'common');
} | 通过产品图片的相对路径得到产品图片的绝对路径. | getDir | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function saveProductStreamImg($fileName, $fileStream, $imgSavedRelativePath='')
{
Yii::$service->image->imageFloder = $this->imageFloder;
Yii::$service->image->allowImgType = $this->allowImgType;
if ($this->maxUploadMSize) {
Yii::$service->image->setMaxUploadSize($this->maxUploadMSize);
}
return Yii::$service->image->saveStreamImg($fileName, $fileStream, $imgSavedRelativePath);
} | @param $fileName | string, 文件名称
@param $fileStream |string, 图片文件的二进制字符。
@param $imgSavedRelativePath | string, 图片存放的相对路径,设置该值后,图片将保存到这个相对路径,如果该路径下已经存在文件,则将会覆盖。 | saveProductStreamImg | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function defautImg()
{
if (!$this->_defaultImg) {
$this->_defaultImg = $this->getUrl($this->defaultImg);
}
return $this->_defaultImg;
} | 获取产品默认图片的完整URL | defautImg | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getResize($imageVal, $imgResize, $isWatered = false)
{
list($newPath, $newUrl) = $this->getNewPathAndUrl($imageVal, $imgResize, $isWatered);
return $newUrl;
} | @param $imageVal | String ,图片相对路径字符串。
@param $imgResize | Array or Int , 数组 [230,230] 代表生成的图片为230*230,如果宽度或者高度不够,则会用白色填充
如果 $imgResize设置为 230, 则宽度不变,高度按照原始图的比例计算出来。
@param $isWatered | Boolean , 产品图片是否打水印。
获取相应尺寸的产品图片。 | getResize | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getResizeDir($imageVal, $imgResize, $isWatered = false)
{
list($newPath, $newUrl) = $this->getNewPathAndUrl($imageVal, $imgResize, $isWatered);
return $newPath;
} | 和上面的方法 getResize 功能类似, getResize是得到按照图片尺寸resize后的图片的url。
本函数是得到resize后图片的 完整文件路径 (绝对文件地址) | getResizeDir | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getNewPathAndUrl($imageVal, $imgResize, $isWatered = false)
{
$originImgPath = $this->getDir($imageVal);
if (!file_exists($originImgPath)) {
$originImgPath = $this->getDir($this->defaultImg);
}
$waterImgPath = '';
if ($isWatered) {
$waterImgPath = $this->getDir('/'.$this->waterImg);
}
list($newPath, $newUrl) = $this->getProductNewPath($imageVal, $imgResize, $waterImgPath);
if ($newPath && $newUrl) {
if (!file_exists($newPath)) {
$options = [
'png_compression_level' => $this->pngCompressionLevel,
'jpeg_quality' => $this->jpegQuality,
];
\fec\helpers\CImage::saveResizeMiddleWaterImg($originImgPath, $newPath, $imgResize, $waterImgPath, $options);
}
return [$newPath, $newUrl];
}
} | @param $imageVal | String ,图片相对路径字符串。
@param $imgResize | Array or Int , 数组 [230,230] 代表生成的图片为230*230,如果宽度或者高度不够,则会用白色填充
如果 $imgResize设置为 230, 则宽度不变,高度按照原始图的比例计算出来。
@param $isWatered | Boolean , 产品图片是否打水印。
获取相应尺寸的产品图片。 | getNewPathAndUrl | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
protected function getProductNewPath($imageVal, $imgResize, $waterImgPath)
{
if (!$this->_md5WaterImgPath) {
if (!$waterImgPath) {
$waterImgPath = 'defaultWaterPath';
}
//echo $waterImgPath;exit;
$this->_md5WaterImgPath = md5($waterImgPath);
}
$baseDir = '/cache/'.$this->_md5WaterImgPath;
if (is_array($imgResize)) {
list($width, $height) = $imgResize;
} else {
$width = $imgResize;
$height = '0';
}
$imageArr = explode('/', $imageVal);
$dirArr = ['cache', $this->_md5WaterImgPath, $width, $height];
foreach ($imageArr as $igf) {
if ($igf !== '' && !strstr($igf, '.')) {
$dirArr[] = $igf;
}
}
$createDir = \fec\helpers\CDir::createFloder($this->getBaseDir(), $dirArr);
if ($createDir) {
$newPath = $this->getBaseDir().$baseDir .'/'.$width.'/'.$height.$imageVal;
$newUrl = $this->getBaseUrl().$baseDir .'/'.$width.'/'.$height.$imageVal;
return [$newPath, $newUrl];
} else {
return [];
}
} | @param $imageVal | String ,图片相对路径字符串。
@param $imgResize | Array or Int , 数组 [230,230] 代表生成的图片为230*230,如果宽度或者高度不够,则会用白色填充
如果 $imgResize设置为 230, 则宽度不变,高度按照原始图的比例计算出来。
@param $waterImgPath | String , 水印图片的路径
获取按照自定义尺寸获取的产品图片的文件绝对路径和完整url | getProductNewPath | php | fecshop/yii2_fecshop | services/product/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Image.php | BSD-3-Clause |
public function getHistory()
{
$history = Yii::$service->session->get($this->_sessionKey);
return $history ? $history : '';
} | get product history log. | getHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Session.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Session.php | BSD-3-Clause |
public function setHistory($productOb)
{
$logArr = [
'date_time' => CDate::getCurrentDateTime(),
'product_id'=> $productOb['id'],
'sku' => $productOb['sku'],
'image' => $productOb['image'],
'name' => is_array($productOb['name']) ? serialize($productOb['name']) : $productOb['name'],
];
if (isset($productOb['user_id']) && $productOb['user_id']) {
$logArr['user_id'] = $productOb['user_id'];
} else {
$logArr['user_id'] = CUser::getCurrentUserId();
}
if (!($session_history = Yii::$service->session->get($this->_sessionKey))) {
$session_history = [];
} elseif (($count = count($session_history)) >= $this->_maxProductCount) {
$unsetMaxKey = $count - $this->_maxProductCount;
for ($i = 0; $i <= $unsetMaxKey; $i++) {
array_shift($session_history);
}
}
$session_history[] = $logArr;
Yii::$service->session->set($this->_sessionKey, $session_history);
} | save product history log. | setHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Session.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Session.php | BSD-3-Clause |
public function init()
{
parent::init();
list($this->_logModelName, $this->_logModel) = \Yii::mapGet($this->_logModelName);
if (!$this->collection) {
$this->collection = $this->_defaultCollection;
}
$this->_logModel->setCurrentCollectionName($this->collection);
} | init | init | php | fecshop/yii2_fecshop | services/product/viewLog/Mongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Mongodb.php | BSD-3-Clause |
public function getHistory($user_id = '', $count = '')
{
if (!$count) {
$count = $this->_maxProductCount;
}
if (!$user_id) {
$user_id = CUser::getCurrentUserId();
}
if (!$user_id) {
return;
}
$coll = $this->_logModel->find()->where([
'user_id' => $user_id,
])
->asArray()
->orderBy(['date_time' => SORT_DESC])
->limit($count)
->all();
return $coll;
} | get product history log. | getHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Mongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Mongodb.php | BSD-3-Clause |
public function setHistory($productOb)
{
$arr = [
'date_time' => CDate::getCurrentDateTime(),
'product_id' => $productOb['id'],
'sku' => $productOb['sku'],
'image' => $productOb['image'],
'name' => $productOb['name'],
];
if (isset($productOb['user_id']) && $productOb['user_id']) {
$arr['user_id'] = $productOb['user_id'];
} elseif ($currentUser = CUser::getCurrentUserId()) {
$arr['user_id'] = $currentUser;
} else {
// if not give user_id, can not save history
return;
}
$mongodbViewLog = $this->_logModel->getCollection();
$mongodbViewLog->save($arr);
} | save product history log. | setHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Mongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Mongodb.php | BSD-3-Clause |
public function init()
{
parent::init();
list($this->_logModelName, $this->_logModel) = \Yii::mapGet($this->_logModelName);
if (!$this->table) {
$this->table = $this->_defaultTable;
}
$this->_logModel->setCurrentTableName($this->table);
} | init function | init | php | fecshop/yii2_fecshop | services/product/viewLog/Db.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Db.php | BSD-3-Clause |
public function getHistory($user_id = '', $count = '')
{
if (!$count) {
$count = $this->_maxProductCount;
}
if (!$user_id) {
$user_id = CUser::getCurrentUserId();
}
if (!$user_id) {
return;
}
$coll = $this->_logModel->find()->where([
'user_id' => $user_id,
])
->asArray()
->orderBy(['date_time' => SORT_DESC])
->limit($count)
->all();
return $coll;
} | get product history log. | getHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Db.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Db.php | BSD-3-Clause |
public function setHistory($productOb)
{
$dbViewLog = new $this->_logModelName();
if (isset($productOb['user_id']) && $productOb['user_id']) {
$dbViewLog->user_id = $productOb['user_id'];
} elseif ($currentUser = CUser::getCurrentUserId()) {
$dbViewLog->user_id = $currentUser;
} else {
// if not give user_id, can not save history
return;
}
$dbViewLog->date_time = CDate::getCurrentDateTime();
$dbViewLog->product_id = $productOb['id'];
$dbViewLog->sku = $productOb['sku'];
$dbViewLog->image = $productOb['image'];
$dbViewLog->name = $productOb['name'];
$dbViewLog->save();
} | save product visit log. | setHistory | php | fecshop/yii2_fecshop | services/product/viewLog/Db.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/viewLog/Db.php | BSD-3-Clause |
public function getEnableStatus()
{
$model = $this->_attrModel;
return $model::STATUS_ENABLE;
} | 得到分类激活状态的值 | getEnableStatus | php | fecshop/yii2_fecshop | services/product/attr/AttrMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/attr/AttrMysqldb.php | BSD-3-Clause |
public function save($one)
{
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
$remoteId = isset($one['remote_id']) ? $one['remote_id'] : '';
if ($primaryVal) {
$model = $this->_attrModel->findOne($primaryVal);
if (!$model) {
Yii::$service->helper->errors->add('Product attr {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]);
return;
}
} else if ($remoteId) {
$model = $this->_attrModel->findOne(['remote_id' => $remoteId]);
if (!$model) {
$model = new $this->_attrModelName();
$model->created_at = time();
}
} else {
$model = new $this->_attrModelName();
$model->created_at = time();
}
$model->updated_at = time();
$primaryKey = $this->getPrimaryKey();
$model = Yii::$service->helper->ar->save($model, $one);
$primaryVal = $model[$primaryKey];
return $model;
} | @param $one|array
save $data to cms model,then,add url rewrite info to system service urlrewrite. | save | php | fecshop/yii2_fecshop | services/product/attr/AttrMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/attr/AttrMysqldb.php | BSD-3-Clause |
public function getByProductIdAndUserId($product_id, $user_id = '')
{
if (!$user_id) {
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
}
if ($user_id) {
$one = $this->_favoriteModel->findOne([
'product_id' => $product_id,
'user_id' => $user_id,
]);
if ($one[$this->getPrimaryKey()]) {
return $one;
}
}
} | @param $product_id | String , 产品id
@param $user_id | Int ,用户id
@return $this->_favoriteModel ,如果用户在该产品收藏,则返回相应model。 | getByProductIdAndUserId | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
public function add($product_id, $user_id)
{
$user_id = (int) $user_id;
$productPrimaryKey = Yii::$service->product->getPrimaryKey();
$product = Yii::$service->product->getByPrimaryKey($product_id);
// 检查产品是否存在,如果不存在,输出报错信息。
if (!isset($product[$productPrimaryKey])) {
Yii::$service->helper->errors->add('product is not exist!');
return;
}
$favoritePrimaryKey = Yii::$service->product->favorite->getPrimaryKey();
$one = $this->_favoriteModel->findOne([
'product_id' => $product_id,
'user_id' => $user_id,
]);
if (isset($one[$favoritePrimaryKey])) {
$one->updated_at = time();
$one->store = Yii::$service->store->currentStore;
$one->save();
return true;
}
$one = new $this->_favoriteModelName();
$one->product_id = $product_id;
$one->user_id = $user_id;
$one->created_at = time();
$one->updated_at = time();
$one->store = Yii::$service->store->currentStore;
$one->save();
// 更新该用户总的收藏产品个数到用户表
$this->updateUserFavoriteCount($user_id);
$this->updateProductFavoriteCount($product_id);
return true;
} | @param $product_id | String , 产品id
@param $user_id | Int ,用户id
@return boolean,用户收藏该产品时,执行的操作。 | add | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
protected function updateProductFavoriteCount($product_id)
{
if ($product_id) {
$count = $this->_favoriteModel->find()->where(['product_id'=>$product_id])->count();
Yii::$service->product->updateProductFavoriteCount($product_id, $count);
}
} | @param $product_id | String
更新该产品被收藏的总次数。 | updateProductFavoriteCount | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
protected function updateUserFavoriteCount($user_id = '')
{
$identity = Yii::$app->user->identity;
if (!$user_id) {
$user_id = $identity['id'];
}
if ($user_id) {
$count = $this->_favoriteModel->find()->where(['user_id'=>$user_id])->count();
$identity->favorite_product_count = $count;
$identity->save();
}
} | @param $user_id | Int
更新该用户总的收藏产品个数到用户表 | updateUserFavoriteCount | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
public function removeByProductIdAndUserId($product_id, $user_id)
{
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
$favoritePrimaryKey = $this->getPrimaryKey();
$one = $this->_favoriteModel->findOne([
'user_id' => $user_id,
'product_id' => $product_id,
]);
if ($one[$favoritePrimaryKey]) {
$one->delete();
$this->updateUserFavoriteCount($user_id);
$product_id = (string) $one['product_id'];
$this->updateProductFavoriteCount($product_id);
return true;
}
} | @param $favorite_id | string
通过id删除favorite | removeByProductIdAndUserId | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
public function currentUserRemove($favorite_id)
{
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
$favoritePrimaryKey = $this->getPrimaryKey();
$one = $this->_favoriteModel->findOne([
$favoritePrimaryKey => $favorite_id,
'user_id' => $user_id,
]);
if ($one[$favoritePrimaryKey]) {
$one->delete();
$this->updateUserFavoriteCount($user_id);
$product_id = (string) $one['product_id'];
$this->updateProductFavoriteCount($product_id);
return true;
}
} | @param $favorite_id | string
通过id删除favorite | currentUserRemove | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMysqldb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMysqldb.php | BSD-3-Clause |
public function getByProductIdAndUserId($product_id, $user_id = '')
{
if (!$user_id) {
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
}
if ($user_id) {
$one = $this->_favoriteModel->findOne([
'product_id' => $product_id,
'user_id' => $user_id,
]);
if ($one[$this->getPrimaryKey()]) {
return $one;
}
}
} | @param $product_id | String , 产品id
@param $user_id | Int ,用户id
@return $this->_favoriteModel ,如果用户在该产品收藏,则返回相应model。 | getByProductIdAndUserId | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
public function add($product_id, $user_id)
{
$user_id = (int) $user_id;
$productPrimaryKey = Yii::$service->product->getPrimaryKey();
$product = Yii::$service->product->getByPrimaryKey($product_id);
// 检查产品是否存在,如果不存在,输出报错信息。
if (!isset($product[$productPrimaryKey])) {
Yii::$service->helper->errors->add('product is not exist!');
return;
}
$favoritePrimaryKey = Yii::$service->product->favorite->getPrimaryKey();
$one = $this->_favoriteModel->findOne([
'product_id' => $product_id,
'user_id' => $user_id,
]);
if (isset($one[$favoritePrimaryKey])) {
$one->updated_at = time();
$one->store = Yii::$service->store->currentStore;
$one->save();
return true;
}
$one = new $this->_favoriteModelName();
$one->product_id = $product_id;
$one->user_id = $user_id;
$one->created_at = time();
$one->updated_at = time();
$one->store = Yii::$service->store->currentStore;
$one->save();
// 更新该用户总的收藏产品个数到用户表
$this->updateUserFavoriteCount($user_id);
$this->updateProductFavoriteCount($product_id);
return true;
} | @param $product_id | String , 产品id
@param $user_id | Int ,用户id
@return boolean,用户收藏该产品时,执行的操作。 | add | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
protected function updateProductFavoriteCount($product_id)
{
if ($product_id) {
$count = $this->_favoriteModel->find()->where(['product_id'=>$product_id])->count();
Yii::$service->product->updateProductFavoriteCount($product_id, $count);
}
} | @param $product_id | String
更新该产品被收藏的总次数。 | updateProductFavoriteCount | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
protected function updateUserFavoriteCount($user_id = '')
{
$identity = Yii::$app->user->identity;
if (!$user_id) {
$user_id = $identity['id'];
}
if ($user_id) {
$count = $this->_favoriteModel->find()->where(['user_id'=>$user_id])->count();
$identity->favorite_product_count = $count;
$identity->save();
}
} | @param $user_id | Int
更新该用户总的收藏产品个数到用户表 | updateUserFavoriteCount | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
public function removeByProductIdAndUserId($product_id, $user_id)
{
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
$one = $this->_favoriteModel->findOne([
'user_id' => $user_id,
'product_id' => $product_id,
]);
if ($one['_id']) {
$one->delete();
$this->updateUserFavoriteCount($user_id);
$product_id = (string) $one['product_id'];
$this->updateProductFavoriteCount($product_id);
return true;
}
} | @param $favorite_id | string
通过id删除favorite | removeByProductIdAndUserId | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
public function currentUserRemove($favorite_id)
{
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
$one = $this->_favoriteModel->findOne([
'_id' => new \MongoDB\BSON\ObjectId($favorite_id),
'user_id' => $user_id,
]);
if ($one['_id']) {
$one->delete();
$this->updateUserFavoriteCount($user_id);
$product_id = (string) $one['product_id'];
$this->updateProductFavoriteCount($product_id);
return true;
}
} | @param $favorite_id | string
通过id删除favorite | currentUserRemove | php | fecshop/yii2_fecshop | services/product/favorite/FavoriteMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/favorite/FavoriteMongodb.php | BSD-3-Clause |
public function isReviewRole($product_id)
{
if (!$this->getReviewService()->reviewOnlyOrderedProduct) {
return true;
}
$itmes = Yii::$service->order->item->getByProductIdAndCustomerId($product_id, $this->getReviewService()->reviewMonth);
if ($itmes) {
return true;
} else {
return false;
}
} | @param $product_id | String, 产品id
是否有评论的权限,如果有,则返回true | isReviewRole | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function noActiveStatus()
{
$model = $this->_reviewModel;
return $model::NOACTIVE_STATUS;
} | 得到review noactive status,默认状态 | noActiveStatus | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function activeStatus()
{
$model = $this->_reviewModel;
return $model::ACTIVE_STATUS;
} | 得到review active status 审核通过的状态 | activeStatus | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function refuseStatus()
{
$model = $this->_reviewModel;
return $model::REFUSE_STATUS;
} | 得到review refuse status 审核拒绝的状态 | refuseStatus | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function getCountBySpu($spu)
{
$where = [
'product_spu' => $spu,
];
if ($this->getReviewService()->filterByLang && ($currentLangCode = Yii::$service->store->currentLangCode)) {
$where['lang_code'] = $currentLangCode;
}
$count = $this->_reviewModel->find()->asArray()->where($where)->count();
return $count ? $count : 0;
} | @param $spu | String.
通过spu找到评论总数。 | getCountBySpu | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function addReview($review_data)
{
//$this->initReviewAttr($review_data);
$model = new $this->_reviewModelName();
if (isset($review_data[$this->getPrimaryKey()])) {
unset($review_data[$this->getPrimaryKey()]);
}
$model = $this->_reviewModel;
$review_data['status'] = $model::NOACTIVE_STATUS;
$review_data['store'] = Yii::$service->store->currentStore;
$review_data['lang_code'] = Yii::$service->store->currentLangCode;
$review_data['review_date'] = time();
if (!Yii::$app->user->isGuest) {
$identity = Yii::$app->user->identity;
$user_id = $identity['id'];
$review_data['user_id'] = $user_id;
}
$review_data['ip'] = \fec\helpers\CFunc::get_real_ip();
$saveStatus = Yii::$service->helper->ar->save($model, $review_data);
return true;
} | @param $review_data | Array
增加评论 前台增加评论调用的函数。 | addReview | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
public function updateReview($review_data)
{
//$this->initReviewAttr($review_data);
$model = $this->_reviewModel->findOne([$this->getPrimaryKey()=> $review_data[$this->getPrimaryKey()]]);
unset($review_data[$this->getPrimaryKey()]);
$saveStatus = Yii::$service->helper->ar->save($model, $review_data);
return true;
} | @param $review_data | Array
保存评论 | updateReview | php | fecshop/yii2_fecshop | services/product/review/ReviewMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.