Пример #1
0
 public function __construct($productId)
 {
     $attributeValueDa = new AttributeValueDa();
     $this->listAttributes = $attributeValueDa->getListAttributes();
     $listAttrValues = $attributeValueDa->getListByProductId($productId);
     if (count($this->listAttributes) > 0 && count($listAttrValues) > 0) {
         foreach ($this->listAttributes as $attr) {
             $attr->listAttrValues = array();
             foreach ($listAttrValues as $attrValue) {
                 if ($attr->Id == $attrValue->AttributeId) {
                     $attrValue->Checked = $attrValue->Checked == 1 ? true : false;
                     array_push($attr->listAttrValues, $attrValue);
                 }
             }
         }
     }
 }
Пример #2
0
 public function init()
 {
     if (isset($this->productId)) {
         $productDa = new ProductDa();
         $this->detail = $productDa->getProductDetail($this->productId);
         $imageDa = new ImageDa();
         $this->imgs = $imageDa->GetImgListByProduct($this->productId);
         $this->load->helper('url');
         foreach ($this->imgs as $img) {
             $img->Path = base_url($img->Path);
         }
         $relateProducts = $productDa->getRelateProduct($this->productId, $this->categoryId);
         foreach ($relateProducts as $product) {
             $productItem = new ProductItemModel();
             $productItem->init($product);
             array_push($this->relateProducts, $productItem);
         }
         $attributeValuesDa = new AttributeValueDa();
         $attrs = $attributeValuesDa->getListMappingProduct($this->productId);
         $stdAttrs = array();
         if (isset($attrs) && count($attrs) > 0) {
             foreach ($attrs as $attr) {
                 if (isset($stdAttrs[$attr->AttributeId])) {
                     $stdAttr = $stdAttrs[$attr->AttributeId];
                     $stdAttr->Value += ";" + $attr->Value;
                 } else {
                     $stdAttrs[$attr->AttributeId] = $attr;
                 }
             }
         }
         if (count($stdAttrs) > 0) {
             foreach ($stdAttrs as $attr) {
                 array_push($this->attrs, $attr);
             }
         }
     }
 }
Пример #3
0
 public function listImgsGetTest()
 {
     $productId = '5';
     $data = '["1","3","4"]';
     $attr = json_decode($data);
     $da = new AttributeValueDa();
     $result = $da->updateAttributeValues($productId, $attr);
     echo $result;
 }
Пример #4
0
 public function updateAttributeTest()
 {
     $productId = '16';
     $attrData = '["1","16","6","7"]';
     $imgData = '{"tempImgIds":["90"],"defaultImgId":"90"}';
     try {
         $attr = json_decode($attrData);
         $img = json_decode($imgData);
         $attrValueDa = new AttributeValueDa();
         $attrResult = $attrValueDa->updateAttributeValues($productId, $attr);
         $imageDa = new ImageDa();
         $imageResult = $imageDa->updateProductImage($productId, $img);
         $result = $attrResult + $imageResult;
         echo $result;
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
 }