public function ShowUserAttributes() { // User attributes on Dashboard, Added by Burak C. $userId = ServiceLocator::GetServer()->GetUserSession()->UserId; $userRepository = new UserRepository(); $this->user = $userRepository->LoadById($userId); $attributeService = new AttributeService(new AttributeRepository()); $attributes = $attributeService->GetByCategory(CustomAttributeCategory::USER); $reservationViewRepository = new ReservationViewRepository(); $startDate = Date::Now(); $endDate = $startDate->AddDays(30); $reservations = $reservationViewRepository->GetReservationList($startDate, $endDate, $userId, ReservationUserLevel::INVITEE); $this->_page->Set("invitations", $reservations); $this->_page->Set("user", $this->user); $this->_page->Set("attributes", $attributes); }
public static function create_good_title($product_title, $options) { static $attributes = array(); $attribute_ids = array(); foreach ($options as $attribute_id => $option_id) { if (!isset($attributes[$attribute_id])) { $attribute_ids[] = $attribute_id; } } if (!empty($attribute_ids)) { $query_struct = array('where' => array('id' => $attribute_ids)); foreach (AttributeService::get_instance()->get_attribute_options($query_struct) as $attribute) { $attributes[$attribute['id']] = $attribute; } } $title = ''; foreach ($options as $attribute_id => $option_id) { if (isset($attributes[$attribute_id]['options'][$option_id])) { if ($title != '') { $title .= ','; } $title .= $attributes[$attribute_id]['options'][$option_id]['name']; } } return $product_title . ' - ' . $title; }
public static function GetAttributesByCatalogueId($catalogueId) { $cas = CatalogueAttribute::find('all', array('catalogue_id' => $catalogueId)); for ($i = 0; $i < count($cas); $i++) { $attributes[$i] = AttributeService::GetById($cas[$i]->attribute_id); } return $attributes; }
public static function PopulateAttributeListViewModel($attribute) { $model = new AttributeListViewModel(); $model->id = $attribute->id; $model->attribute = AttributeHelper::PopulateAttributeViewModel(AttributeService::GetById($attribute->attribute_id)); $model->value = $attribute->name; return $model; }
public static function PopulateAttributeValueFloatViewModel($attribute) { $model = new AttributeFloatViewModel(); $model->id = $attribute->attributevaluefloat_id; $model->attribute = AttributeHelper::PopulateAttributeViewModel(AttributeService::GetById($attribute->attribute_id)); //$model->product = ProductHelper::PopulateProductViewModel(ProductService::GetById($attribute->product_id)); $model->value = $attribute->value; return $model; }
public static function PopulateCatalogueDetailViewModel($catalogue) { $model = new CatalogDetailViewModel(); $model->name = $catalogue->name; $model->section_name = $catalogue->section->section_name; $attributes = CatalogueAttributeService::GetByCatalogueId($catalogue->catalogue_id); for ($i = 0; $i < count($attributes); $i++) { $model->attributes[$i] = AttributeHelper::PopulateAttributeViewModel(AttributeService::GetById($attributes[$i]->attribute_id)); } return $model; }
public static function PopulateAttributeFromEditModel($id, $name, $attributeGroupName, $attributeUnitName) { $attribute = AttributeService::GetById($id); $attribute->attributegroup_id = AttributeGroupService::GetByName($attributeGroupName)->attributegroup_id; $attribute->name = $name; if ($attributeUnitName != "-") { $attribute->unit_id = UnitService::GetByName($attributeUnitName)->unit_id; } else { $attribute->unit_id = null; } return $attribute; }
/** * 根据规格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; }
/** * 根据 attributeoption_id 获取该 attributeoption 的兄弟记录 * * @param int $attributeoption_id 规格项ID * @param bool $clear_self 是否清除自身 * @return array * @throws MyRuntimeException */ public function get_brothers_by_attributeoption_id($attributeoption_id, $clear_self = FALSE) { try { $attributeoption = $this->get($attributeoption_id); $attribute_id = $attributeoption['attribute_id']; $attributeoptions = AttributeService::get_instance()->get_attributeoptions_by_attribute_id($attribute_id); if ($clear_self == TRUE) { foreach ($attributeoptions as $index => $attributeoption) { if ($attributeoption['id'] == $attributeoption_id) { unset($attributeoptions[$index]); } } } return $attributeoptions; } catch (MyRuntimeException $ex) { throw $ex; } }
/** * @expectedException \Magento\Framework\Exception\StateException * @expectedExceptionMessage System attribute can not be deleted */ public function testDeleteSystemAttribute() { $entityCode = \Magento\Catalog\Model\Product::ENTITY; $methods = array('__wakeup', 'setAttributeSetId', 'loadEntityAttributeIdBySet', 'getEntityAttributeId', 'deleteEntity', 'getId', 'getIsUserDefined'); $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); $this->entityTypeConfigMock->expects($this->once())->method('getEntityTypeCode')->will($this->returnValue($entityCode)); $objectMock = $this->getMock('\\Magento\\Framework\\Object', array(), array(), '', false); $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->attributeSetMock->expects($this->once())->method('load')->with(1)->will($this->returnValue($objectMock)); $attributeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', $methods, array(), '', false); $this->attributeMock->expects($this->once())->method('load')->with(10)->will($this->returnValue($attributeMock)); $attributeMock->expects($this->any())->method('getId')->will($this->returnValue(2)); $attributeMock->expects($this->once())->method('setAttributeSetId')->with(1)->will($this->returnSelf()); $attributeMock->expects($this->once())->method('loadEntityAttributeIdBySet')->will($this->returnSelf()); $attributeMock->expects($this->once())->method('getEntityAttributeId')->will($this->returnValue(10)); $attributeMock->expects($this->once())->method('getIsUserDefined')->will($this->returnValue(false)); $attributeMock->expects($this->never())->method('deleteEntity'); $this->service->deleteAttribute(1, 10); }
/** * 根据 WHERE 条件获取商品特性列表 * * @param array $where * @return array */ public static function index($where) { $features = array(); $feature_arr = AttributeService::get_instance()->index(array('where' => $where, 'orderby' => 'order')); foreach ($feature_arr as $feature) { $feature = coding::decode_feature($feature); $feature['options'] = array(); $features[$feature['id']] = $feature; } if (!empty($features)) { $options = Attribute_valueService::get_instance()->index(array('where' => array('attribute_id' => array_keys($features)), 'orderby' => 'order')); foreach ($options as $option) { //$option = coding::decode_featureoption($option); $featid = $option['attribute_id']; unset($option['attribute_id']); unset($option['order']); $features[$featid]['options'][$option['id']] = $option; } } return $features; }
/** * 根据 classify_id 获取关联的规格及规格项 * * @param int $classify_id * @return array * @throws MyRuntimeException */ public function get_attribute_options_by_classify_id($classify_id, $apply = NULL) { $return_array = array(); try { /* 判断 classify 是否存在 $classify = $this->get($classify_id); if(!$classify){ throw new MyRuntimeException('Object not found.', 500); }*/ // 获取关联表数据 $attribute_ids = $this->get_attribute_ids_by_classify_id($classify_id, $apply); if ($attribute_ids) { // 获取所有关联的attribute $query_struct = array('where' => array('id' => $attribute_ids), 'orderby' => array('id' => 'ASC')); $attributes = AttributeService::get_instance()->query_assoc($query_struct); // 每个ID必须都是有效的 if (count($attributes) != count($attribute_ids)) { throw new MyRuntimeException('Internal error.', 500); } // 组装返回数组 foreach ($attributes as $attribute) { //$attribute = coding::decode_attribute($attribute); $attribute['options'] = array(); $return_array[$attribute['id']] = $attribute; } // 获取关联项 $query_struct = array('where' => array('attribute_id' => $attribute_ids)); $attributeoptions = Attribute_valueService::get_instance()->query_assoc($query_struct); foreach ($attributeoptions as $attributeoption) { //$attributeoption = coding::decode_attributeoption($attributeoption); $attribute_id = $attributeoption['attribute_id']; $return_array[$attribute_id]['options'][$attributeoption['id']] = $attributeoption; } } return $return_array; } catch (MyRuntimeException $ex) { throw $ex; } }
?> </a></li> <?php } ?> </ul> </div> </div> <?php if (!empty($company->customAttributes)) { ?> <div class="clear"></div> <div class="custom-fields"> <?php $renderedContent = AttributeService::renderAttributesFront($company->customAttributes, $enablePackages, $company->packageFeatures); echo $renderedContent; ?> </div> <?php } ?> </div> </div> <?php if (isset($company->featured) && $company->featured == 1) { ?> <div class="featured-text"> <?php echo JText::_("LNG_FEATURED"); ?>
public function testPassThroughForAttribute() { $attributeId = 123; $this->attributeRepository->expects($this->once())->method('LoadById')->with($this->equalTo($attributeId))->will($this->returnValue(new TestCustomAttribute(1, 'l'))); $this->attributeService->GetById($attributeId); }
public function action_Remove() { PermissionHelper::Verification('Editor'); $id = $_GET['id']; AttributeService::Delete(AttributeService::GetById($id)); header("Location: /Attribute/Item"); }
function action_new() { PermissionHelper::Verification('Editor'); $name = $_POST['inputName']; $price = $_POST['inputPrice']; $Description = $_POST['inputDescription']; $names = explode(',', $_POST['names']); $values = explode(',', $_POST['values']); $catalog = $_POST['catalog']; $product = new Product(); $product->name = $name; $product->price = $price; $product->catalogue_id = CatalogueService::GetByName($catalog)->catalogue_id; $product->description = $Description; ProductService::Create($product); $product_id = ProductService::GetByName($name)->product_id; for ($i = 0; $i < count($names); $i++) { $attribute = AttributeService::GetByName($names[$i]); if ($attribute->type == 1) { $attributeFloat = new AttributeValueFloat(); $attributeFloat->attribute_id = $attribute->attribute_id; $attributeFloat->product_id = $product_id; $attributeFloat->value = $values[$i]; AttributeValueFloatService::Create($attributeFloat); } else { $attributeList = new AttributeValueList(); $attributeList->product_id = $product_id; $attributeList->attribute_id = $attribute->attribute_id; $attributeList->value = AttributeListService::GetByAttributeIdAndName($attribute->attribute_id, $values[$i])->attributelist_id; AttributeValueListService::Create($attributeList); } } $fr = fopen($_FILES['file-0']['tmp_name'], 'r'); $fw = fopen(__ROOT__ . '/images/items/item_' . $product_id . '.jpg', "w"); while (!feof($fr)) { $buff = fread($fr, 1000); fwrite($fw, $buff); } fclose($fr); fclose($fw); header("Location: /Product/itemAdmin"); }
function action_new() { PermissionHelper::Verification('Editor'); $name = $_POST['inputName']; $sectionName = $_POST['inputSection']; $attribute = $_POST['attributes']; $catalogue = new Catalogue(); $catalogue->name = $name; $catalogue->section_id = SectionService::GetByName($sectionName)->section_id; CatalogueService::Create($catalogue); $catalogue = CatalogueService::GetByName($name); for ($i = 0; $i < count($attribute); $i++) { $value = new CatalogueAttribute(); $value->catalogue_id = $catalogue->catalogue_id; $value->attribute_id = AttributeService::GetByName(trim($attribute[$i]))->attribute_id; CatalogueAttributeService::Create($value); } header("Location: /Catalog/Item"); }
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) { $good['goods_attributeoption_relation_struct']['items'][$aoid[0]] = $aoid[1]; } $good['title'] = product::create_good_title($product['title'], $good['goods_attributeoption_relation_struct']['items']); $product['goods'][] = $good; } } } return $return_assoc; } else { return array(); } }
function get_category_data() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array('classify' => array(), 'brand_list' => array(), 'attribute_list' => array(), 'feature_list' => array()); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //必须为ajax请求 if (!$this->is_ajax_request()) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404); } //数据验证 if (!isset($request_data['category_id']) || !is_numeric($request_data['category_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.input_error'), 404); } if ($request_data['category_id'] == 0) { //当前站点品牌 $return_data['brand_list'] = BrandService::get_instance()->get_brands(); //当前站点规格 $return_data['attribute_list'] = AttributeService::get_instance()->get_attribute_spec_options(); //当前站点品牌 $return_data['feature_list'] = AttributeService::get_instance()->get_attribute_feature_options(); } else { // 调用底层服务 $category_service = CategoryService::get_instance(); $classify_service = ClassifyService::get_instance(); //获取数据 $category = $category_service->get($request_data['category_id']); if ($category['classify_id']) { $return_data['classify'] = $classify_service->get($category['classify_id']); //获取关联品牌数组 $return_data['brand_list'] = $classify_service->get_brands_by_classify_id($category['classify_id']); //获取关联规格及规格项数组 $return_data['attribute_list'] = $classify_service->get_attribute_options_by_classify_id($category['classify_id'], AttributeService::ATTRIBUTE_SPEC); //获取关联特性及特性值数组 $return_data['feature_list'] = $classify_service->get_attribute_options_by_classify_id($category['classify_id'], AttributeService::ATTRIBUTE_FEATURE); } } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $return_data; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404); } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
"><?php echo $categoryNames[$i]; echo $i < count($categoryIds) - 1 ? ', ' : ''; ?> </a> </li> <?php } ?> </ul> </div> </div> <div class="clear"></div> <div class="custom-fields"> <?php // to do fix warning $renderedContent = AttributeService::renderAttributesFront($this->companyAttributes, $appSettings->enable_packages, $this->package->features); echo $renderedContent; ?> </div> <?php require_once 'listing_social_networks.php'; ?> <?php if (($showData && isset($this->package->features) && in_array(CONTACT_FORM, $this->package->features) || !$appSettings->enable_packages) && !empty($company->email)) { ?> <button type="button" class="ui-dir-button" onclick="showContactCompany()"> <span class="ui-button-text"><i class="dir-icon-edit"></i><?php echo JText::_("LNG_CONTACT_COMPANY"); ?> </span>
/** * 设定菜单的排序 */ public function set_order() { //初始化返回数组 $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); /* 验证是否可以操作 */ if (!role::verify('product_feature')) { $return_struct['msg'] = Kohana::lang('o_global.permission_enough'); exit(json_encode($return_struct)); } $request_data = $this->input->get(); $id = isset($request_data['id']) ? $request_data['id'] : ''; $order = isset($request_data['order']) ? $request_data['order'] : ''; if (empty($id) || empty($order) && $order != 0) { $return_struct['msg'] = Kohana::lang('o_global.bad_request'); exit(json_encode($return_struct)); } if (!is_numeric($order) || $order < 0) { $return_struct['msg'] = Kohana::lang('o_global.position_rule'); exit(json_encode($return_struct)); } $attribute_service = AttributeService::get_instance(); $attribute_service->set($id, array('order' => $order)); $return_struct = array('status' => 1, 'code' => 200, 'msg' => Kohana::lang('o_global.position_success'), 'content' => array('order' => $order)); exit(json_encode($return_struct)); }
function get_site_data() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array('brand_list' => NULL, 'attribute_list' => NULL, 'feature_list' => NULL); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //* 实现功能后屏蔽此异常抛出 */ //throw new MyRuntimeException('Not Implemented',501); //必须为ajax请求 if (!$this->is_ajax_request()) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404); } //* 权限验证 */ $site_id_list = role::check('product_classify', 0, 0); if (empty($site_id_list)) { throw new MyRuntimeException('Access Denied', 403); } if (isset($request_data['site_id']) && is_numeric($request_data['site_id'])) { if (!in_array($request_data['site_id'], $site_id_list)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } } //数据验证 if (!isset($request_data['site_id']) || !is_numeric($request_data['site_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404); } // 调用底层服务 $classify_service = ClassifyService::get_instance(); //请求站点品牌列表 $brands = BrandService::get_instance()->get_brands_by_site_id($request_data['site_id']); foreach ($brands as $val) { $return_data['brand_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>'; } //请求站点规格列表 $attributes = AttributeService::get_instance()->get_attributes_by_site_id($request_data['site_id']); foreach ($attributes as $val) { $return_data['attribute_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>'; } //请求站点规格列表 $features = FeatureService::get_instance()->get_features_by_site_id($request_data['site_id']); foreach ($features as $val) { $return_data['feature_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>'; } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $return_data; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { // html 输出 //* 模板输出 */ $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__); //* 变量绑定 */ $this->template->title = Kohana::config('site.name'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }