当前位置: 首页>>代码示例>>PHP>>正文


PHP product::create_good_sku方法代码示例

本文整理汇总了PHP中product::create_good_sku方法的典型用法代码示例。如果您正苦于以下问题:PHP product::create_good_sku方法的具体用法?PHP product::create_good_sku怎么用?PHP product::create_good_sku使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在product的用法示例。


在下文中一共展示了product::create_good_sku方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse_attributes

 protected function parse_attributes($l, &$product)
 {
     $attributes = $this->get($l, 'attributes');
     if ($attributes !== '') {
         $return_assoc = array();
         $sign = '规格:';
         if ($sign === substr($attributes, 0, strlen($sign))) {
             $attributes = explode('|', str_replace('/\\|+/', '|', substr($attributes, strlen($sign))));
             foreach ($attributes as $index => $item) {
                 $attributes[$index] = trim($item);
             }
             $records = AttributeService::get_instance()->get_attribute_options(array('where' => array('name_manage' => $attributes)));
             foreach ($attributes as $item) {
                 $upper = strtoupper($item);
                 $search = FALSE;
                 foreach ($records as $record) {
                     if (strtoupper($record['name_manage']) === $upper) {
                         $return_assoc[] = $record;
                         $search = TRUE;
                         break;
                     }
                 }
                 if ($search === FALSE) {
                     $this->set_error(new MyRuntimeException(sprintf('站点 "%s" 下未找到名称为 "%s" 的规格', $this->site_name, $item)));
                 }
             }
         } else {
             $num = 1;
             $attributes = explode('|', $attributes);
             $relations = array();
             foreach ($attributes as $index => $item) {
                 $item = explode('/', trim($item));
                 if (empty($item)) {
                     $this->set_error(new MyRuntimeException(sprintf('规格 "%s" 的值不可为空', $this->attributes[$index]['name_manage'])));
                 } else {
                     if (isset($this->attributes[$index])) {
                         foreach ($item as $option_name) {
                             $uppercase = strtoupper(trim($option_name));
                             foreach ($this->attributes[$index]['options'] as $option) {
                                 if ($uppercase === strtoupper($option['name_manage'])) {
                                     if (!isset($relations[$this->attributes[$index]['id']])) {
                                         $relations[$this->attributes[$index]['id']] = array();
                                     }
                                     $relations[$this->attributes[$index]['id']][] = $option['id'];
                                 }
                             }
                         }
                         if (isset($relations[$this->attributes[$index]['id']]) and count($relations[$this->attributes[$index]['id']] === count($item))) {
                             $num *= count($item);
                         } else {
                             $this->set_error(new MyRuntimeException(sprintf('规格 "%s" 的值填写错误:"%s"', $this->attributes[$index]['name_manage'], $item)));
                         }
                     }
                 }
             }
             if (!empty($relations)) {
                 if (!function_exists('array_assembly')) {
                     function array_assembly($arrays)
                     {
                         $result = array();
                         $array = array_shift($arrays);
                         if (empty($arrays)) {
                             foreach ($array as $key => $val) {
                                 $array[$key] = array($val);
                             }
                             return $array;
                         } else {
                             foreach ($array as $val) {
                                 foreach (array_assembly($arrays) as $item) {
                                     array_unshift($item, $val);
                                     $result[] = $item;
                                 }
                             }
                             return $result;
                         }
                     }
                 }
                 $struct = array();
                 $index = 0;
                 foreach ($relations as $aid => $oids) {
                     if (!isset($struct[$index])) {
                         $struct[$index] = array();
                     }
                     foreach ($oids as $oid) {
                         $struct[$index][] = array($aid, $oid);
                     }
                     $index++;
                 }
                 $struct = array_assembly($struct);
                 foreach ($struct as $item) {
                     $good = array('sku' => product::create_good_sku($product['sku']), 'store' => '-1', 'on_sale' => $product['on_sale'], 'price' => $product['goods_price'], 'market_price' => $product['goods_market_price'], 'cost' => $product['goods_cost'], 'weight' => $product['weight'], 'update_timestamp' => time(), 'create_timestamp' => time());
                     if (!isset($product['goods'])) {
                         $product['store'] = '-1';
                         $product['goods'] = array();
                         $good['is_default'] = '1';
                     } else {
                         $good['is_default'] = '0';
                     }
                     $good['goods_attributeoption_relation_struct'] = array('items' => array());
                     foreach ($item as $aoid) {
//.........这里部分代码省略.........
开发者ID:RenzcPHP,项目名称:3dproduct,代码行数:101,代码来源:ImportService.php

示例2: save

 /**
  * 保存组合商品类型相关数据
  *
  * @param array $product
  * @return boolean
  */
 public static function save(&$product)
 {
     //先创建商品数据ID
     if (empty($product['id'])) {
         $pdata = array('create_time' => time());
         $product['id'] = ProductService::get_instance()->add($pdata);
     }
     $product['pdt_category_additional_id'] = isset($product['pdt_category_additional_id']) ? implode(',', $product['pdt_category_additional_id']) : '';
     // 将商品类型设置为 0 简单商品处理
     if (!empty($product['pdt_goods'])) {
         $attroptrs = array();
         $product['store'] = 0;
         $product['on_sale'] = 0;
         $product['default_goods'] = 0;
         foreach ($product['pdt_goods'] as $index => $good) {
             $good['type'] = ProductService::PRODUCT_TYPE_GOODS;
             $good['product_id'] = $product['id'];
             $good['classify_id'] = $product['classify_id'];
             $good['brand_id'] = $product['brand_id'];
             $good['category_id'] = $product['category_id'];
             $good['is_wholesale'] = $product['is_wholesale'];
             $good['category_ids'] = $product['pdt_category_additional_id'];
             $good['unit'] = $product['unit'];
             $good['name_manage'] = $product['name_manage'];
             $good['uri_name'] = $product['uri_name'] . $index;
             $good['meta_title'] = $product['meta_title'];
             $good['meta_keywords'] = $product['meta_keywords'];
             $good['meta_description'] = $product['meta_description'];
             $good['brief'] = $product['brief'];
             $good['made_date'] = $product['made_date'];
             $good['quality_date'] = $product['quality_date'];
             $good['quality_percent'] = $product['quality_percent'];
             isset($good['default_goods']) || ($good['default_goods'] = 0);
             isset($good['front_visible']) || ($good['front_visible'] = 0);
             isset($good['on_sale']) || ($good['on_sale'] = 0);
             empty($good['sku']) and $good['sku'] = product::create_good_sku($product['sku']);
             empty($good['title']) and $good['title'] = product::create_good_title($product['title'], $good['attroptrs']);
             $good['attribute_struct'] = array('items' => array_keys($good['attroptrs']));
             $good['attribute_struct_default'] = array('items' => $good['attroptrs']);
             // 获取商品与规格值的关联
             foreach ($good['attroptrs'] as $aid => $oid) {
                 $aid = (string) $aid;
                 $oid = (string) $oid;
                 isset($attroptrs[$aid]) or $attroptrs[$aid] = array();
                 in_array($oid, $attroptrs[$aid]) or $attroptrs[$aid][] = $oid;
             }
             // 商品价格等信息从默认货品获取
             if ($good['default_goods'] == 1) {
                 $product['price'] = $good['price'];
                 $product['market_price'] = $good['market_price'];
                 $product['cost'] = $good['cost'];
                 $product['weight'] = $good['weight'];
             }
             // 判断商品的上下架
             if ($product['on_sale'] == 0 && $good['on_sale'] == 1) {
                 $product['on_sale'] = 1;
             }
             // 计算商品的库存
             if ($good['store'] > 0) {
                 $product['store'] += $good['store'];
             }
             // 处理货品的关联商品图片
             if (!empty($good['picrels'])) {
                 is_array($good['picrels']) or $good['picrels'] = explode(',', $good['picrels']);
                 /*foreach ($good['picrels'] as $i => $picrel)
                 		{
                 			if (!isset($product['pictures'][$picrel]))
                 			{
                 				unset($good['picrels'][$i]);
                 			}
                 		}*/
                 if (!empty($good['picrels'])) {
                     $good['goods_productpic_relation_struct'] = array('items' => $good['picrels']);
                 }
             } else {
                 $good['goods_productpic_relation_struct'] = array();
             }
             $product['pdt_goods'][$index] = $good;
         }
         // 商品价格等信息从默认货品获取
         if (!isset($product['price']) || $product['price'] == 0) {
             $product['price'] = $product['pdt_goods'][$index]['price'];
             $product['market_price'] = $product['pdt_goods'][$index]['market_price'];
             $product['cost'] = $product['pdt_goods'][$index]['cost'];
             $product['weight'] = $product['pdt_goods'][$index]['weight'];
         }
         //dump($product['pdt_goods']);
         //删除组合商品、所有被关联的简单商品旧属性,然后保存新的属性
         ORM::factory('product_attributeoption_relation')->where('product_id', $product['id'])->delete_all();
         ORM::factory('product_attributeoption_relation')->where('assembly_id', $product['id'])->delete_all();
         foreach ($attroptrs as $aid => $oids) {
             foreach ($oids as $oid) {
                 Product_attributeoption_relationService::get_instance()->add(array('apply' => AttributeService::ATTRIBUTE_SPEC, 'product_id' => $product['id'], 'attribute_id' => $aid, 'attributeoption_id' => $oid));
             }
//.........这里部分代码省略.........
开发者ID:RenzcPHP,项目名称:3dproduct,代码行数:101,代码来源:assembly.php

示例3: save

 /**
  * 保存可配置商品类型相关数据
  *
  * @param array $product
  * @return boolean
  */
 public static function save(&$product)
 {
     //先创建商品数据ID
     if (empty($product['id'])) {
         $pdata = array('create_time' => time());
         $product['id'] = ProductService::get_instance()->add($pdata);
     }
     $product['pdt_category_additional_id'] = isset($product['pdt_category_additional_id']) ? implode(',', $product['pdt_category_additional_id']) : '';
     //简单商品处理
     if (!empty($product['pdt_goods'])) {
         $attroptrs = array();
         $is_default = false;
         $product['price'] = 0;
         $product['store'] = 0;
         $product['on_sale'] = 0;
         $product['default_goods'] = 0;
         foreach ($product['pdt_goods'] as $index => $good) {
             //简单商品基本信息初始从可配置商品中获得
             if (empty($good['id'])) {
                 $good['type'] = ProductService::PRODUCT_TYPE_GOODS;
                 $good['classify_id'] = $product['classify_id'];
                 $good['brand_id'] = $product['brand_id'];
                 $good['category_id'] = $product['category_id'];
                 $good['is_wholesale'] = $product['is_wholesale'];
                 $good['category_ids'] = $product['pdt_category_additional_id'];
                 $good['unit'] = $product['unit'];
                 $good['name_manage'] = $product['name_manage'];
                 $good['uri_name'] = $product['uri_name'] . $index;
                 $good['meta_title'] = $product['meta_title'];
                 $good['meta_keywords'] = $product['meta_keywords'];
                 $good['meta_description'] = $product['meta_description'];
                 $good['brief'] = $product['brief'];
             } else {
                 if ($good['id'] > 0) {
                     //更新简单商品一部分基本信息
                     $good_org = ProductService::get_instance()->get($good['id']);
                     $good_org['is_wholesale'] == 0 && ($good['is_wholesale'] = $product['is_wholesale']);
                     empty($good_org['category_ids']) && ($good['category_ids'] = $product['pdt_category_additional_id']);
                     empty($good_org['meta_title']) && ($good['meta_title'] = $product['meta_title']);
                     empty($good_org['meta_keywords']) && ($good['meta_keywords'] = $product['meta_keywords']);
                     empty($good_org['meta_description']) && ($good['meta_description'] = $product['meta_description']);
                     empty($good_org['brief']) && ($good['brief'] = $product['brief']);
                     unset($good_org);
                 }
             }
             isset($good['default_goods']) || ($good['default_goods'] = 0);
             isset($good['front_visible']) || ($good['front_visible'] = 0);
             isset($good['on_sale']) || ($good['on_sale'] = 0);
             empty($good['sku']) && ($good['sku'] = product::create_good_sku($product['sku']));
             empty($good['title']) && ($good['title'] = product::create_good_title($product['title'], $good['attroptrs']));
             $g_attroptrs = array();
             foreach ($good['attroptrs'] as $aid => $avid) {
                 $g_attroptrs[$aid] = array($avid);
             }
             $good['attribute_struct'] = array('items' => array_keys($good['attroptrs']));
             $good['attribute_struct_default'] = array('items' => $g_attroptrs);
             unset($g_attroptrs);
             // 获取商品与规格值的关联
             foreach ($good['attroptrs'] as $aid => $oid) {
                 $aid = (string) $aid;
                 $oid = (string) $oid;
                 isset($attroptrs[$aid]) or $attroptrs[$aid] = array();
                 in_array($oid, $attroptrs[$aid]) or $attroptrs[$aid][] = $oid;
             }
             // 商品价格等信息从默认货品获取
             if ($good['default_goods'] == 1) {
                 $product['price'] = $good['price'];
                 $product['market_price'] = $good['market_price'];
                 $product['cost'] = $good['cost'];
                 $product['weight'] = $good['weight'];
                 $is_default = true;
             }
             // 判断商品的上下架
             if ($product['on_sale'] == 0 && $good['on_sale'] == 1) {
                 $product['on_sale'] = 1;
             }
             // 计算商品的库存
             if ($good['store'] > 0) {
                 $product['store'] += $good['store'];
             }
             // 处理货品的关联商品图片
             if (!empty($good['picrels'])) {
                 is_array($good['picrels']) or $good['picrels'] = explode(',', $good['picrels']);
                 /*foreach ($good['picrels'] as $i => $picrel)
                 		{
                 			if (!isset($product['pictures'][$picrel]))
                 			{
                 				unset($good['picrels'][$i]);
                 			}
                 		}*/
                 if (!empty($good['picrels'])) {
                     $good['goods_productpic_relation_struct'] = array('items' => $good['picrels']);
                 }
             } else {
//.........这里部分代码省略.........
开发者ID:RenzcPHP,项目名称:3dproduct,代码行数:101,代码来源:configurable.php


注:本文中的product::create_good_sku方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。