public static function GetValuesByAttributeId($attributeId)
 {
     $attributeslist = AttributeListService::GetByAttributeId($attributeId);
     for ($i = 0; $i < count($attributeslist); $i++) {
         $values[$i] = $attributeslist[$i]->name;
     }
     return $values;
 }
 public static function PopulateAttributeValueListViewModel($attribute)
 {
     $model = new AttributeValueListViewModel();
     $model->id = $attribute->id;
     //$model->product =ProductHelper::PopulateProductViewModel(ProductService::GetById($attribute->product_id));
     $model->attribute = AttributeHelper::PopulateAttributeViewModel(AttributeService::GetById($attribute->attribute_id));
     $model->value = AttributeListHelper::PopulateAttributeListViewModel(AttributeListService::GetById($attribute->value))->value;
     return $model;
 }
Example #3
0
 public static function PopulateAttributeListEditViewModel($attribute)
 {
     $model = new AttributeListEditViewModel();
     $model->id = $attribute->attribute_id;
     $model->attributeGroups = AttributeGroupHelper::PopulateAttributeGroupViewModelList(AttributeGroupService::GetAll());
     $model->units = UnitService::GetAll();
     $model->name = $attribute->name;
     $model->attributeGroupName = AttributeGroupService::GetById($attribute->attributegroup_id)->name;
     $model->unitName = UnitService::GetById($attribute->unit_id)->name;
     $model->values = AttributeListService::GetValuesByAttributeId($model->id);
     return $model;
 }
Example #4
0
 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;
 }
 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");
 }
 public function action_UpdateList()
 {
     PermissionHelper::Verification('Editor');
     $id = $_POST['id'];
     $attributeValue = explode("\r\n", $_POST['inputValue']);
     $attribute = AttributeHelper::PopulateAttributeFromEditModel($id, $_POST['inputName'], $_POST['inputGroup'], $_POST['inputUnit']);
     AttributeService::Save($attribute);
     $attributesList = AttributeListService::GetByAttributeId($id);
     for ($i = 0; $i < count($attributesList); $i++) {
         if (($index = $this->GetIndexFromArray($attributesList[$i]->name, $attributeValue)) < 0) {
             AttributeListService::Delete($attributesList[$i]);
         } else {
             array_splice($attributeValue, $index, 1);
         }
     }
     for ($i = 0; $i < count($attributeValue); $i++) {
         $attributeList = new AttributeList();
         $attributeList->attribute_id = $id;
         $attributeList->name = $attributeValue[$i];
         AttributeListService::Create($attributeList);
     }
     header("Location: /Attribute/Item");
 }