Example #1
0
 /**
  * 加载基本商品类型相关数据
  *
  * @param array $product
  * @return boolean
  */
 public static function load(&$product)
 {
     $product['classify_id'] && ($product['attributes'] = BLL_Product_Attribute::get_clsattrrs($product['classify_id']));
     //处理简单商品是否属于可配置商品或者组合商品的一项
     $p_configurable = Product_assemblyService::get_instance()->query_assoc(array('where' => array('product_id' => $product['id'], 'assembly_type' => ProductService::PRODUCT_TYPE_CONFIGURABLE), 'orderby' => array('id' => 'asc'), 'limit' => array('per_page' => 1)));
     $configurable_id = isset($p_configurable[0]['assembly_id']) && $p_configurable[0]['assembly_id'] > 0 ? $p_configurable[0]['assembly_id'] : 0;
     if ($configurable_id > 0) {
         $product['configurable_id'] = $configurable_id;
         !$product['descsections'] && ($product['descsections'] = BLL_Product_Detail::get($configurable_id));
         !$product['fetuoptrs'] && ($product['fetuoptrs'] = BLL_Product_Feature::get_fetuoptrs($configurable_id));
         !$product['relations'] && ($product['relations'] = BLL_Product_Relation::get($configurable_id));
         !$product['wholesales'] && ($product['wholesales'] = BLL_Product_Wholesale::get($configurable_id));
         //可配置商品的关联图片更新检查
         if (!empty($product['goods_productpic_relation_struct'])) {
             $configurable_pictures = BLL_Product_Picture::get($configurable_id);
             $productpicService = ProductpicService::get_instance();
             $product = coding::decode_attribute($product, 'goods_productpic_relation_struct');
             foreach ($product['goods_productpic_relation_struct']['items'] as $pic_id) {
                 if (isset($configurable_pictures[$pic_id])) {
                     $query_struct = array('where' => array('product_id' => $product['id'], 'image_id' => $configurable_pictures[$pic_id]['image_id']));
                     if (!$productpicService->count($query_struct) > 0) {
                         $productpic_data = array('product_id' => $product['id'], 'is_default' => ProductpicService::PRODUCTPIC_IS_DEFAULT_FALSE, 'title' => $configurable_pictures[$pic_id]['title'], 'image_id' => $configurable_pictures[$pic_id]['image_id']);
                         $productpic_row_id = $productpicService->add($productpic_data);
                         $product['pictures'][$pic_id] = $configurable_pictures[$pic_id];
                     }
                 }
             }
         }
     }
     //获取商品规格
     $attroptrs = array();
     if ($product['attribute_struct_default']) {
         $attroptrs = json_decode($product['attribute_struct_default'], TRUE);
         $attroptrs = $attroptrs['items'];
         if (is_array($attroptrs)) {
             foreach ($attroptrs as $aid => $oid) {
                 $attroptrs[$aid] = $oid[0];
             }
         }
         unset($product['attribute_struct_default']);
     } else {
         $attroptrs = self::get_pdt_attroptrs($product['id']);
     }
     if (!empty($attroptrs)) {
         $product['attroptrs'] = $attroptrs;
         $product['attrrs'] = array_keys($attroptrs);
     }
     return TRUE;
 }
Example #2
0
 /**
  * 通过商品ID删除商品
  *
  * @param integer $product_id
  * @return boolean
  */
 public static function delete($product_id)
 {
     $product = ProductService::get_instance()->get($product_id);
     if (!$product['id'] > 0) {
         throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400);
     }
     switch ($product['type']) {
         case ProductService::PRODUCT_TYPE_ASSEMBLY:
         case ProductService::PRODUCT_TYPE_CONFIGURABLE:
             self::delete_goods($product_id);
             break;
         case ProductService::PRODUCT_TYPE_GOODS:
             BLL_Product_Type_Simple::delete($product_id);
             break;
     }
     BLL_Product_Picture::delete($product_id);
     BLL_Product_Wholesale::delete($product_id);
     BLL_Product_Relation::delete($product_id);
     BLL_Product_Detail::delete($product_id);
     //BLL_Product_Point::delete($product_id);
     BLL_Product_Search::delete($product_id);
     //BLL_Product_Argument::rmv_arguments($product_id);
     ORM::factory('productcomment')->where('product_id', $product_id)->delete_all();
     ORM::factory('productinquiry')->where('product_id', $product_id)->delete_all();
     ProductService::get_instance()->remove($product_id);
     //Cache::remove(self::$cache_key.$product_id);
     //Cache::remove('product_inquiries.'.$product_id);
     //Cache::remove('product_comments.'.$product_id);
     return TRUE;
 }