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 PopulateProductCreateViewModel($catalogue) { $model = new ProductCreateViewModel(); $attributes = CatalogueAttributeService::GetAttributesByCatalogueId($catalogue->catalogue_id); foreach ($attributes as $value) { if ($value->type == 1) { $model->attributesFloat[count($model->attributesFloat)] = $value; } else { $model->ListName[count($model->attributesList)] = $value->name; $model->attributesList[count($model->attributesList)] = AttributeListService::GetByAttributeId($value->attribute_id); } } return $model; }
public static function PopulateCatalogueEditViewModel($catalogue) { $model = new CatalogEditViewModel(); $model->id = $catalogue->catalogue_id; $model->name = $catalogue->name; $model->section_name = $catalogue->section->section_name; $attributes = AttributeHelper::PopulateAttributeViewModelList(CatalogueAttributeService::GetAttributesByCatalogueId($catalogue->catalogue_id)); $model->attributes = AttributeGroupHelper::PopulateAttributeGroupViewModelList(AttributeGroupService::GetAll()); $model->group[][] = ""; for ($i = 0; $i < count($model->attributes); $i++) { for ($j = 0; $j < count($model->attributes[$i]->attributes); $j++) { if (($index = CatalogEditHelper::GetIndexFromArray($model->attributes[$i]->attributes[$j], $attributes)) >= 0) { $model->group[$i][$j] = 'checked'; } else { $model->group[$i][$j] = ''; } } } return $model; }
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"); }