/** * 根据规格ID获取商品规格 * * @param integer $attribute_id * @return array */ public static function get($attribute_id) { $attribute = AttributeService::get_instance()->get($attribute_id); $attribute = coding::decode_attribute($attribute); $options = Attribute_valueService::get_instance()->index(array('where' => array('attribute_id' => $attribute['id']), 'orderby' => 'order')); $attribute['options'] = array(); foreach ($options as $option) { unset($option['attribute_id']); unset($option['order']); $attribute['options'][$option['id']] = $option; } return $attribute; }
/** * 加载基本商品类型相关数据 * * @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; }
/** * 获取规格数组 * @param array $request_struct 请求结构体 * @return array * @throws MyRuntimeException */ public function get_attributes($request_struct = array(), $k = 'meta_struct') { $return_array = array(); try { $attributes = $this->query_assoc($request_struct); if (!empty($attributes)) { foreach ($attributes as $attribute) { $attribute = coding::decode_attribute($attribute, $k); $return_array[$attribute['id']] = $attribute; } } return $return_array; } catch (MyRuntimeException $ex) { throw $ex; } }