当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::add方法代码示例

本文整理汇总了PHP中Image::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::add方法的具体用法?PHP Image::add怎么用?PHP Image::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadImage

 public function loadImage($id_product, $images)
 {
     $images_array = $this->imagesToArray($images);
     $images_id = array();
     $product = new Product($id_product);
     $image_types = ImageType::getImagesTypes('product');
     if ($images_array) {
         foreach ($images_array as $img) {
             if (file_exists(_TM_ROOT_DIR_ . $img['url'])) {
                 //ajout de l'image au produit
                 $image = new Image();
                 $image->id_product = intval($product->id);
                 $image->position = Image::getHighestPosition($product->id) + 1;
                 if (!intval($product->id_image_default)) {
                     $image->cover = 1;
                 } else {
                     $image->cover = 0;
                 }
                 $image->legend = 0;
                 $image->add();
                 if ($image->cover) {
                     $product->id_image_default = (int) $image->id;
                 }
                 $id_image = $image->id;
                 $images_id[] = $id_image;
                 $path = $image->getPathForCreation();
                 //echo $imgDir.$img['url'];
                 @copy(_TM_ROOT_DIR_ . $img['url'], $path . '.jpg');
                 foreach ($image_types as $k => $image_type) {
                     ImageManager::resize(_TM_ROOT_DIR_ . $img['url'], $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                 }
                 //@unlink($tmpName);
             } else {
                 $this->_output .= '<div class="alert error">Image not exists!</div>';
             }
             $product->update();
         }
     }
     return $images_id;
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:40,代码来源:Import.php

示例2: duplicateProductImages

    /**
     * Copy images from a product to another
     *
     * @param integer $id_product_old Source product ID
     * @param boolean $id_product_new Destination product ID
     */
    public static function duplicateProductImages($id_product_old, $id_product_new, $combinationImages)
    {
        $imagesTypes = ImageType::getImagesTypes('products');
        $result = Db::getInstance()->ExecuteS('
		SELECT `id_image`
		FROM `' . _DB_PREFIX_ . 'image`
		WHERE `id_product` = ' . intval($id_product_old));
        foreach ($result as $row) {
            $image = new Image($row['id_image']);
            $saved_id = $image->id_image;
            unset($image->id);
            unset($image->id_image);
            $image->id_product = intval($id_product_new);
            if ($image->add()) {
                foreach ($imagesTypes as $k => $imageType) {
                    if (file_exists(_PS_PROD_IMG_DIR_ . intval($id_product_old) . '-' . intval($row['id_image']) . '-' . $imageType['name'] . '.jpg')) {
                        copy(_PS_PROD_IMG_DIR_ . intval($id_product_old) . '-' . intval($row['id_image']) . '-' . $imageType['name'] . '.jpg', _PS_PROD_IMG_DIR_ . intval($id_product_new) . '-' . intval($image->id) . '-' . $imageType['name'] . '.jpg');
                    }
                }
                if (file_exists(_PS_PROD_IMG_DIR_ . intval($id_product_old) . '-' . intval($row['id_image']) . '.jpg')) {
                    copy(_PS_PROD_IMG_DIR_ . intval($id_product_old) . '-' . intval($row['id_image']) . '.jpg', _PS_PROD_IMG_DIR_ . intval($id_product_new) . '-' . intval($image->id) . '.jpg');
                }
                Db::getInstance()->Execute('
				UPDATE `' . _DB_PREFIX_ . 'product_attribute`
				SET id_image = ' . intval($image->id) . '
				WHERE id_image = ' . intval($saved_id) . '
				AND id_product = ' . intval($id_product_new));
                self::replaceAttributeImageAssociationId($combinationImages, intval($saved_id), intval($image->id));
            } else {
                return false;
            }
        }
        return self::duplicateAttributeImageAssociations($combinationImages);
    }
开发者ID:redb,项目名称:prestashop,代码行数:40,代码来源:Image.php

示例3: explode

 $multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator : ',';
 if (isset($prd['images']) && $prd['images']) {
     $image_url = explode('/', $prd['images']);
     $url = _PS_IMG_MGT_DIR_ . end($image_url);
     $product_has_images = (bool) Image::getImages($id_lang, $product->id);
     $image = new Image();
     $image->id_product = (int) $product->id;
     $image->position = Image::getHighestPosition($product->id) + 1;
     $image->cover = !$product_has_images ? true : false;
     $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
     $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
     $id_shop_list = array();
     $errors = array();
     $warnings = array();
     $id_shop_list[] = $product->id_shop_default;
     if ($image->add()) {
         $image->associateTo($id_shop_list);
         $image->getPathForCreation();
         $image_final = $image->getPathForCreation() . '.jpg';
         if (Tools::copy($url, $image_final)) {
             $tgt_width = $tgt_height = 0;
             $src_width = $src_height = 0;
             $previous_path = null;
             $path_infos = array();
             $images_types = ImageType::getImagesTypes('products', true);
             foreach ($images_types as $image_type) {
                 if (ImageManager::resize($image_final, $image->getPathForCreation() . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'], 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height)) {
                     if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '.jpg')) {
                         unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '.jpg');
                     }
                     if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '_' . (int) Context::getContext()->shop->id . '.jpg')) {
开发者ID:abdoumej,项目名称:libsamy,代码行数:31,代码来源:import.php

示例4: productImport

 public function productImport()
 {
     global $cookie;
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         if (array_key_exists('id', $info) and (int) $info['id'] and Product::existsInDatabase((int) $info['id'])) {
             $product = new Product((int) $info['id']);
             $categoryData = Product::getIndexedCategories((int) $product->id);
             foreach ($categoryData as $tmp) {
                 $product->category[] = $tmp['id_category'];
             }
         } else {
             $product = new Product();
         }
         self::setEntityDefaultValues($product);
         self::array_walk($info, array('AdminImport', 'fillInfo'), $product);
         $trg_id = (int) $product->id_tax_rules_group;
         if ($product->id_tax_rules_group == 0 || !Validate::isLoadedObject(new TaxRulesGroup($trg_id))) {
             $this->_addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID, you first need a group with this ID.'));
         } else {
             $product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
         }
         if (isset($product->manufacturer) and is_numeric($product->manufacturer) and Manufacturer::manufacturerExists((int) $product->manufacturer)) {
             $product->id_manufacturer = (int) $product->manufacturer;
         } elseif (isset($product->manufacturer) and is_string($product->manufacturer) and !empty($product->manufacturer)) {
             if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                 $product->id_manufacturer = (int) $manufacturer;
             } else {
                 $manufacturer = new Manufacturer();
                 $manufacturer->name = $product->manufacturer;
                 if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
                     $product->id_manufacturer = (int) $manufacturer->id;
                 } else {
                     $this->_errors[] = $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($product->supplier) and is_numeric($product->supplier) and Supplier::supplierExists((int) $product->supplier)) {
             $product->id_supplier = (int) $product->supplier;
         } elseif (isset($product->supplier) and is_string($product->supplier) and !empty($product->supplier)) {
             if ($supplier = Supplier::getIdByName($product->supplier)) {
                 $product->id_supplier = (int) $supplier;
             } else {
                 $supplier = new Supplier();
                 $supplier->name = $product->supplier;
                 if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
                     $product->id_supplier = (int) $supplier->id;
                 } else {
                     $this->_errors[] = $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($product->price_tex) and !isset($product->price_tin)) {
             $product->price = $product->price_tex;
         } elseif (isset($product->price_tin) and !isset($product->price_tex)) {
             $product->price = $product->price_tin;
             // If a tax is already included in price, withdraw it from price
             if ($product->tax_rate) {
                 $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6);
             }
         } elseif (isset($product->price_tin) and isset($product->price_tex)) {
             $product->price = $product->price_tex;
         }
         if (isset($product->category) and is_array($product->category) and sizeof($product->category)) {
             $product->id_category = array();
             // Reset default values array
             foreach ($product->category as $value) {
                 if (is_numeric($value)) {
                     if (Category::categoryExists((int) $value)) {
                         $product->id_category[] = (int) $value;
                     } else {
                         $categoryToCreate = new Category();
                         $categoryToCreate->id = (int) $value;
                         $categoryToCreate->name = self::createMultiLangField($value);
                         $categoryToCreate->active = 1;
                         $categoryToCreate->id_parent = 1;
                         // Default parent is home for unknown category to create
                         if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) {
                             $product->id_category[] = (int) $categoryToCreate->id;
                         } else {
                             $this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                             $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                         }
                     }
                 } elseif (is_string($value) and !empty($value)) {
                     $category = Category::searchByName($defaultLanguageId, $value, true);
                     if ($category['id_category']) {
                         $product->id_category[] = (int) $category['id_category'];
                     } else {
                         $categoryToCreate = new Category();
                         $categoryToCreate->name = self::createMultiLangField($value);
//.........这里部分代码省略.........
开发者ID:hecbuma,项目名称:quali-fisioterapia,代码行数:101,代码来源:AdminImport.php

示例5: importImages

 protected function importImages()
 {
     $this->truncateTables(array('image', 'image_lang', 'image_shop'));
     $handle = $this->openCsvFile('images.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('Image', $this->image_fields, $line);
         if (!isset($fields['id_image'])) {
             $img = new Image($line[0]);
         } else {
             $img = new Image($fields['id_image']);
         }
         $img->id = $line[0];
         foreach ($fields as $key => $field) {
             if ($key == 'legend') {
                 $img->{$key} = $this->multilFild($field);
             } else {
                 $img->{$key} = $field;
             }
         }
         $img->force_id = true;
         if (!$res) {
             $res = $img->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }
开发者ID:evgrishin,项目名称:se1614,代码行数:28,代码来源:AdminSampleDataInstallImport.php

示例6: writePostedImageOnDisk

 /**
  * Write the posted image on disk
  *
  * @param string $sreceptionPath
  * @param int $destWidth
  * @param int $destHeight
  * @param array $imageTypes
  * @param string $parentPath
  * @return boolean
  */
 protected function writePostedImageOnDisk($receptionPath, $destWidth = null, $destHeight = null, $imageTypes = null, $parentPath = null)
 {
     if ($this->wsObject->method == 'PUT') {
         if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
             $file = $_FILES['image'];
             if ($file['size'] > $this->imgMaxUploadSize) {
                 throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400));
             }
             // Get mime content type
             $mime_type = false;
             if (Tools::isCallable('finfo_open')) {
                 $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                 $finfo = finfo_open($const);
                 $mime_type = finfo_file($finfo, $file['tmp_name']);
                 finfo_close($finfo);
             } elseif (Tools::isCallable('mime_content_type')) {
                 $mime_type = mime_content_type($file['tmp_name']);
             } elseif (Tools::isCallable('exec')) {
                 $mime_type = trim(exec('file -b --mime-type ' . escapeshellarg($file['tmp_name'])));
             }
             if (empty($mime_type) || $mime_type == 'regular file') {
                 $mime_type = $file['type'];
             }
             if (($pos = strpos($mime_type, ';')) !== false) {
                 $mime_type = substr($mime_type, 0, $pos);
             }
             // Check mime content type
             if (!$mime_type || !in_array($mime_type, $this->acceptedImgMimeTypes)) {
                 throw new WebserviceException('This type of image format not recognized, allowed formats are: ' . implode('", "', $this->acceptedImgMimeTypes), array(73, 400));
             } elseif ($file['error']) {
                 throw new WebserviceException('Error while uploading image. Please change your server\'s settings', array(74, 400));
             }
             // Try to copy image file to a temporary file
             if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) {
                 throw new WebserviceException('Error while copying image to the temporary directory', array(75, 400));
             } else {
                 $result = $this->writeImageOnDisk($tmpName, $receptionPath, $destWidth, $destHeight, $imageTypes, $parentPath);
             }
             @unlink($tmpName);
             return $result;
         } else {
             throw new WebserviceException('Please set an "image" parameter with image data for value', array(76, 400));
         }
     } elseif ($this->wsObject->method == 'POST') {
         if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
             $file = $_FILES['image'];
             if ($file['size'] > $this->imgMaxUploadSize) {
                 throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400));
             }
             require_once _PS_ROOT_DIR_ . '/images.inc.php';
             if ($error = ImageManager::validateUpload($file)) {
                 throw new WebserviceException('Image upload error : ' . $error, array(76, 400));
             }
             if (isset($file['tmp_name']) && $file['tmp_name'] != null) {
                 if ($this->imageType == 'products') {
                     $product = new Product((int) $this->wsObject->urlSegment[2]);
                     if (!Validate::isLoadedObject($product)) {
                         throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400));
                     }
                     $image = new Image();
                     $image->id_product = (int) $product->id;
                     $image->position = Image::getHighestPosition($product->id) + 1;
                     if (!Image::getCover((int) $product->id)) {
                         $image->cover = 1;
                     } else {
                         $image->cover = 0;
                     }
                     if (!$image->add()) {
                         throw new WebserviceException('Error while creating image', array(76, 400));
                     }
                     if (!Validate::isLoadedObject($product)) {
                         throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400));
                     }
                 }
                 // copy image
                 if (!isset($file['tmp_name'])) {
                     return false;
                 }
                 if ($error = ImageManager::validateUpload($file, $this->imgMaxUploadSize)) {
                     throw new WebserviceException('Bad image : ' . $error, array(76, 400));
                 }
                 if ($this->imageType == 'products') {
                     $image = new Image($image->id);
                     if (!(Configuration::get('PS_OLD_FILESYSTEM') && file_exists(_PS_PROD_IMG_DIR_ . $product->id . '-' . $image->id . '.jpg'))) {
                         $image->createImgFolder();
                     }
                     if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) {
                         throw new WebserviceException('An error occurred during the image upload', array(76, 400));
                     } elseif (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format)) {
                         throw new WebserviceException('An error occurred while copying image', array(76, 400));
//.........这里部分代码省略.........
开发者ID:toufikadfab,项目名称:PrestaShop-1.5,代码行数:101,代码来源:WebserviceSpecificManagementImages.php

示例7: save

 public function save()
 {
     $product = new Product($_GET['id_product']);
     if (!Validate::isLoadedObject($product)) {
         return array('error' => Tools::displayError('Cannot add image because product creation failed.'));
     } else {
         $image = new Image();
         $image->id_product = (int) $product->id;
         $image->position = Image::getHighestPosition($product->id) + 1;
         $legends = Tools::getValue('legend');
         if (is_array($legends)) {
             foreach ($legends as $key => $legend) {
                 if (Validate::isGenericName($legend)) {
                     $image->legend[(int) $key] = $legend;
                 } else {
                     return array('error' => sprintf(Tools::displayError('Error on image caption: "%1s" is not a valid caption.'), Tools::safeOutput($legend)));
                 }
             }
         }
         if (!Image::getCover($image->id_product)) {
             $image->cover = 1;
         } else {
             $image->cover = 0;
         }
         if (($validate = $image->validateFieldsLang(false, true)) !== true) {
             return array('error' => Tools::displayError($validate));
         }
         if (!$image->add()) {
             return array('error' => Tools::displayError('Error while creating additional image'));
         } else {
             return $this->copyImage($product->id, $image->id);
         }
     }
 }
开发者ID:bravoman,项目名称:PrestaShop,代码行数:34,代码来源:FileUploader.php

示例8: AddImage

 private function AddImage($object, $url)
 {
     $shops = Shop::getShops(true, null, true);
     $url = str_replace(' ', '%20', $url);
     $image = new Image();
     $image->id_product = (int) $object->id;
     $image->position = Image::getHighestPosition($object->id) + 1;
     $image->cover = 1;
     // file_exists doesn't work with HTTP protocol
     if (@fopen($url, 'r') == false) {
         $error = true;
     } else {
         if (($field_error = $image->validateFields(false, true)) === true && ($lang_field_error = $image->validateFieldsLang(false, true)) === true && $image->add()) {
             // associate image to selected shops
             $image->associateTo($shops);
             if (!self::copyImg($object->id, $image->id, $url)) {
                 $image->delete();
                 $this->errors[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
             }
         } else {
             $error = true;
         }
     }
 }
开发者ID:blaz1988,项目名称:presta,代码行数:24,代码来源:uploadxml.php

示例9: handleImageUpload

 /**
  * handleImageUpload
  * @author Cornelius Hansjakob <cha@massiveart.at>
  * @version 1.0
  */
 private function handleImageUpload()
 {
     $this->core->logger->debug('media->controllers->UploadController->handleImageUpload()');
     $objImage = new Image();
     $objImage->setUpload($this->objUpload);
     $objImage->setParentId($this->intParentId);
     $objImage->setParentTypeId($this->core->sysConfig->parent_types->folder);
     $objImage->setUploadPath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->images->path->local->private);
     $objImage->setPublicFilePath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->images->path->local->public);
     $objImage->setDefaultImageSizes($this->core->sysConfig->upload->images->default_sizes->default_size->toArray());
     $objImage->add('Filedata');
     $this->writeViewData($objImage);
 }
开发者ID:BGCX261,项目名称:zoolu-svn-to-git,代码行数:18,代码来源:UploadController.php

示例10: productImport

    public function productImport()
    {
        // do standard stuff; need to copy/paste
        // because silly PS does not allow to hook inside of the import loop...
        $this->receiveTab();
        $handle = $this->openCsvFile();
        $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
        $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
        if (!Validate::isUnsignedId($id_lang)) {
            $id_lang = $default_language_id;
        }
        AdminImportController::setLocale();
        $shop_ids = Shop::getCompleteListOfShopsID();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
                $product = new Product((int) $info['id']);
            } elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
                $datas = Db::getInstance()->getRow('
					SELECT p.`id_product`
					FROM `' . _DB_PREFIX_ . 'product` p
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE p.`reference` = "' . pSQL($info['reference']) . '"
				');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $product = new Product((int) $datas['id_product']);
                } else {
                    $product = new Product();
                }
            } elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
                $product = new Product((int) $info['id']);
            } else {
                $product = new Product();
            }
            if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) {
                $product->loadStockData();
                $category_data = Product::getProductCategories((int) $product->id);
                if (is_array($category_data)) {
                    foreach ($category_data as $tmp) {
                        if (!isset($product->category) || !$product->category || is_array($product->category)) {
                            $product->category[] = $tmp;
                        }
                    }
                }
            }
            AdminImportController::setEntityDefaultValues($product);
            AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
            /*
             * 2015-03-26 - JLE SPECIFIC :
             * Import language specific infos
             */
            foreach ($this->csv_translated_fields as $field) {
                foreach ($this->csv_languages as $lang) {
                    if (isset($info[$field . "_" . $lang])) {
                        $lang_id = Language::getIdByIso($lang);
                        $product->{$field}[$lang_id] = $info[$field . "_" . $lang];
                    }
                }
            }
            /*
             * END SPECIFIC
             */
            if (!Shop::isFeatureActive()) {
                $product->shop = 1;
            } elseif (!isset($product->shop) || empty($product->shop)) {
                $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            if (!Shop::isFeatureActive()) {
                $product->id_shop_default = 1;
            } else {
                $product->id_shop_default = (int) Context::getContext()->shop->id;
            }
            // link product to shops
            $product->id_shop_list = array();
            foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
                if (!empty($shop) && !is_numeric($shop)) {
                    $product->id_shop_list[] = Shop::getIdByName($shop);
                } elseif (!empty($shop)) {
                    $product->id_shop_list[] = $shop;
                }
            }
            if ((int) $product->id_tax_rules_group != 0) {
                if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                    $address = $this->context->shop->getAddress();
                    $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
                    $product_tax_calculator = $tax_manager->getTaxCalculator();
                    $product->tax_rate = $product_tax_calculator->getTotalRate();
                } else {
                    $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
                }
            }
            if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
                $product->id_manufacturer = (int) $product->manufacturer;
            } elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
                if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                    $product->id_manufacturer = (int) $manufacturer;
                } else {
//.........这里部分代码省略.........
开发者ID:julienlerch,项目名称:xburning,代码行数:101,代码来源:AdminImportController.php

示例11: save

 public function save($type)
 {
     $image = new Image();
     $image->copyFromPost();
     if (!$image->add()) {
         return array('error' => Tools::displayError('Error while creating additional image'));
     } else {
         return $this->copyImage($image->id, $type);
     }
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:10,代码来源:FileUploader.php

示例12: handleImageUpload

 /**
  * handleImageUpload
  * @author Cornelius Hansjakob <cha@massiveart.at>
  * @version 1.0
  */
 private function handleImageUpload()
 {
     $this->core->logger->debug('media->controllers->UploadController->handleImageUpload()');
     $objImage = new Image();
     $objImage->setUpload($this->objUpload);
     $objImage->setParentId($this->intParentId);
     $objImage->setParentTypeId($this->core->sysConfig->parent_types->folder);
     $objImage->setSegmenting($this->core->sysConfig->upload->images->segmenting->enabled == 'true' ? true : false);
     $objImage->setNumberOfSegments($this->core->sysConfig->upload->images->segmenting->number_of_segments);
     $objImage->setUploadPath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->images->path->local->private);
     $objImage->setPublicFilePath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->images->path->local->public);
     $objImage->setTmpFilePath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->images->path->local->tmp);
     $objImage->setDefaultImageSizes($this->core->sysConfig->upload->images->default_sizes->default_size->toArray());
     $objImage->setLanguageId($this->intLanguageId);
     $objImage->add(self::UPLOAD_FIELD);
     $this->writeViewData($objImage);
 }
开发者ID:BGCX261,项目名称:zoolu-svn-to-git,代码行数:22,代码来源:UploadController.php

示例13: execImages

 public static function execImages($pdt, $product)
 {
     $images = array();
     if (isset($pdt->images)) {
         $images = (array) $pdt->images->url;
     } else {
         return;
     }
     foreach ($images as &$img) {
         if (preg_match('/:\\/\\//', $img)) {
             continue;
         }
         $img = _PS_ROOT_DIR_ . $img;
         if (!file_exists($img)) {
             Log::notice($pdt->supplier_reference, 'File $img not found.');
         }
     }
     $product->deleteImages();
     $productHasImages = (bool) Image::getImages(self::getInfoEco('ID_LANG'), (int) $product->id);
     foreach ($images as $key => $url) {
         $url = str_replace(' ', '%20', $url);
         $image = new Image();
         $image->id_product = $product->id;
         $image->position = Image::getHighestPosition($product->id) + 1;
         $image->cover = !$key && !$productHasImages ? true : false;
         if ($image->add()) {
             if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                 $image->associateTo($pdt->id_shop_default);
             }
             if (!self::copyImg($product->id, $image->id, $url)) {
                 Log::notice($pdt->supplier_reference, 'Error copying image: $url');
             }
         } else {
             Log::notice($pdt->supplier_reference, 'Cannot save image $url');
         }
     }
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:37,代码来源:importProduct.class.php

示例14: attributeImport

    public function attributeImport()
    {
        $default_language = Configuration::get('PS_LANG_DEFAULT');
        $groups = array();
        foreach (AttributeGroup::getAttributesGroups($default_language) as $group) {
            $groups[$group['name']] = (int) $group['id_attribute_group'];
        }
        $attributes = array();
        foreach (Attribute::getAttributes($default_language) as $attribute) {
            $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
        }
        $this->receiveTab();
        $handle = $this->openCsvFile();
        AdminImportController::setLocale();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (count($line) == 1 && empty($line[0])) {
                continue;
            }
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            $info = array_map('trim', $info);
            if (self::ignoreRow($info)) {
                continue;
            }
            AdminImportController::setDefaultValues($info);
            if (!Shop::isFeatureActive()) {
                $info['shop'] = 1;
            } elseif (!isset($info['shop']) || empty($info['shop'])) {
                $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
            $id_shop_list = array();
            if (is_array($info['shop']) && count($info['shop'])) {
                foreach ($info['shop'] as $shop) {
                    if (!empty($shop) && !is_numeric($shop)) {
                        $id_shop_list[] = Shop::getIdByName($shop);
                    } elseif (!empty($shop)) {
                        $id_shop_list[] = $shop;
                    }
                }
            }
            if (isset($info['id_product']) && is_string($info['id_product'])) {
                $prod = self::findProductByName($default_language, $info['id_product']);
                if ($prod['id_product']) {
                    $info['id_product'] = $prod['id_product'];
                } else {
                    unset($info['id_product']);
                }
            }
            if (!isset($info['id_product']) && Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) {
                $datas = Db::getInstance()->getRow('
					SELECT p.`id_product`
					FROM `' . _DB_PREFIX_ . 'product` p
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE p.`reference` = "' . pSQL($info['product_reference']) . '"
				');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $info['id_product'] = $datas['id_product'];
                }
            }
            if (isset($info['id_product'])) {
                $product = new Product((int) $info['id_product'], false, $default_language);
            } else {
                continue;
            }
            $id_image = array();
            if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) {
                $product->deleteImages();
                $this->cache_image_deleted[(int) $product->id] = true;
            }
            if (isset($info['image_url']) && $info['image_url']) {
                $info['image_url'] = explode(',', $info['image_url']);
                if (is_array($info['image_url']) && count($info['image_url'])) {
                    foreach ($info['image_url'] as $url) {
                        $url = trim($url);
                        $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
                        $image = new Image();
                        $image->id_product = (int) $product->id;
                        $image->position = Image::getHighestPosition($product->id) + 1;
                        $image->cover = !$product_has_images ? true : false;
                        $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
                        $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
                        if ($field_error === true && $lang_field_error === true && $image->add()) {
                            $image->associateTo($id_shop_list);
                            if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !Tools::getValue('regenerate'))) {
                                $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
                                $image->delete();
                            } else {
                                $id_image[] = (int) $image->id;
                            }
                        } else {
                            $this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
                        }
                    }
                }
            } elseif (isset($info['image_position']) && $info['image_position']) {
                $info['image_position'] = explode(',', $info['image_position']);
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:AdminImportController.php

示例15: foreach

     echo "Invalid Product Id {$id_product}";
     exit;
 }
 $product->deleteImages();
 $first_image = true;
 $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
 foreach ($images as $image_name) {
     $image_name = trim($image_name);
     $image_path = IMAGE_UPLOAD_PATH . $image_name;
     if (!empty($image_name)) {
         $image = new Image();
         $image->id_product = (int) $product->id;
         $image->position = Image::getHighestPosition($product->id) + 1;
         $image->cover = $first_image;
         $image->legend[$defaultLanguageId] = $product->name[$defaultLanguageId];
         if (($fieldError = $image->validateFields(false, true)) === true and ($langFieldError = $image->validateFieldsLang(false, true)) === true and $image->add()) {
             if (!Tools::copyImg($product->id, $image->id, $image_path)) {
                 echo "Error copying image:" . $image_path;
                 exit;
             } else {
                 //delete the original image
                 @unlink($image_path);
             }
         } else {
             print_r($fieldError);
             print_r($langFieldError);
             exit;
         }
     }
     $first_image = false;
 }
开发者ID:priyankajsr19,项目名称:shalu,代码行数:31,代码来源:OMS_bkp_new.php


注:本文中的Image::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。