Example #1
0
 function addImageURL(Product $Product)
 {
     if (isset($_FILES['fileImageURL']) && $_FILES['fileImageURL']['size'] > 0) {
         $errors = array();
         $fileName = $_FILES['fileImageURL']['name'];
         $tmpName = $_FILES['fileImageURL']['tmp_name'];
         $fileSize = $_FILES['fileImageURL']['size'];
         $fileType = $_FILES['fileImageURL']['type'];
         $File = new File($fileName, $tmpName, $fileSize, $fileType);
         if ($fileSize > 2097152) {
             $errors[] = 'File phải nhỏ hơn 2 MB';
         }
         if (!$File->isImageType()) {
             $errors[] = "";
         }
         if (empty($errors) == true) {
             $logo_Old = trim($Product->getImageURL(), '"');
             if (file_exists($logo_Old)) {
                 unlink($logo_Old);
             }
             $path = '../assets/images/productImages/' . $Product->getProID();
             if (!file_exists($path)) {
                 // neu k ton tai duong dan thu muc cua id nay thi tạo mới
                 File::createDirectory($path);
             }
             $type = explode("/", $File->getFileType())[1];
             $find = array(" ", "\\", "/", ":", "*", "?", "\"", "<", ">", "|");
             $name = File::utf8convert(str_replace($find, '', $Product->getProName()));
             $pathNew = $path . '/' . $name . "_main." . $type;
             $File->moveFile($pathNew);
             $Product->setImageURL($pathNew);
             $Product->updateImageURL();
         } else {
             // print_r($errors);
         }
         if (empty($error)) {
             // echo "Success";
         }
     }
 }
Example #2
0
 /**
  * Populate product object 
  *
  * @param array $product
  * @return object 
  */
 protected function getProductObject($product)
 {
     if (empty($product)) {
         throw new BuyatException('Malformed response from server');
     }
     $productObject = new Product();
     $productObject->setProductID($product['product_id']);
     $productObject->setProductSKU($product['product_sku']);
     $productObject->setProductURL($product['product_url']);
     $productObject->setProductName($product['product_name']);
     $productObject->setBrandName($product['brand_name']);
     $productObject->setDescription($product['description']);
     $productObject->setOnlinePrice($product['online_price']);
     $productObject->setCurrency($product['currency']);
     $productObject->setCurrencySymbol($product['currency_symbol']);
     $productObject->setImageURL($product['image_url']);
     $productObject->setProgrammeName($product['programme_name']);
     $productObject->setProgrammeURL($product['programme_url']);
     $productObject->setProgrammeID($product['programme_id']);
     $productObject->setLevel1CategoryID($product['level1_category_id']);
     $productObject->setLevel1CategoryName($product['level1_category_name']);
     $productObject->setLevel2CategoryID($product['level2_category_id']);
     $productObject->setLevel2CategoryName($product['level2_category_name']);
     $productObject->setFeedID($product['feed_id']);
     $productObject->setFeedName($product['feed_name']);
     return $productObject;
 }