本文整理汇总了PHP中Product::getImages方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getImages方法的具体用法?PHP Product::getImages怎么用?PHP Product::getImages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::getImages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImages
private function getImages()
{
$images = $this->product->getImages((int) $this->context->language->id);
$link = $this->context->link;
$jsonImages = array();
if ($images && count($images)) {
foreach ($images as $image) {
$jsonImages[] = array('name' => $image['legend'], 'url' => $link->getImageLink($this->product->link_rewrite, $this->product->id . '-' . $image['id_image']));
}
}
return $jsonImages;
}
示例2: assignImages
/**
* Assign template vars related to images
*/
protected function assignImages()
{
$images = $this->product->getImages((int) $this->context->cookie->id_lang);
$product_images = array();
if (isset($images[0])) {
$this->context->smarty->assign('mainImage', $images[0]);
}
foreach ($images as $k => $image) {
if ($image['cover']) {
$this->context->smarty->assign('mainImage', $image);
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
$cover['id_image_only'] = (int) $image['id_image'];
}
$product_images[(int) $image['id_image']] = $image;
}
if (!isset($cover)) {
if (isset($images[0])) {
$cover = $images[0];
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $images[0]['id_image'] : $images[0]['id_image'];
$cover['id_image_only'] = (int) $images[0]['id_image'];
} else {
$cover = array('id_image' => $this->context->language->iso_code . '-default', 'legend' => 'No picture', 'title' => 'No picture');
}
}
$size = Image::getSize(ImageType::getFormatedName('large'));
$this->context->smarty->assign(array('have_image' => isset($cover['id_image']) && (int) $cover['id_image'] ? array((int) $cover['id_image']) : Product::getCover((int) Tools::getValue('id_product')), 'cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'largeSize' => Image::getSize(ImageType::getFormatedName('large')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'cartSize' => Image::getSize(ImageType::getFormatedName('cart')), 'col_img_dir' => _PS_COL_IMG_DIR_));
if (count($product_images)) {
$this->context->smarty->assign('images', $product_images);
}
}
示例3: hookDisplayTmHoverImage
public function hookDisplayTmHoverImage($params)
{
if (!$this->isCached('tmimagehover.tpl', $this->getCacheId($params['id_product']))) {
$id_lang = $this->context->language->id;
$obj = new Product((int) $params['id_product'], false, $id_lang);
$images = $obj->getImages($this->context->language->id);
$_images = array();
if (!empty($images)) {
foreach ($images as $k => $image) {
if (!$image['cover']) {
$_images[] = $obj->id . '-' . $image['id_image'];
}
}
}
$this->smarty->assign(array('link_rewrite' => $params['link_rewrite'], 'images' => $_images));
}
return $this->display(__FILE__, 'tmimagehover.tpl', $this->getCacheId($params['id_product']));
}
示例4: generateProductsData
protected function generateProductsData()
{
$delimiter = ';';
$titles = array();
$id_lang = $this->use_lang;
$new_path = new Sampledatainstall();
$f = fopen($new_path->sendPath() . 'output/products.vsc', 'w');
foreach ($this->product_fields as $field => $array) {
$titles[] = $array['label'];
}
fputcsv($f, $titles, $delimiter, '"');
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true);
foreach ($products as $product) {
$line = array();
$p = new Product($product['id_product'], true, $id_lang, 1);
foreach ($this->product_fields as $field => $array) {
$line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : '';
}
$cats = $p->getProductCategoriesFull($p->id, 1);
$cat_array = array();
foreach ($cats as $cat) {
$cat_array[] = $cat['id_category'];
}
$line['categories'] = implode(',', $cat_array);
$line['price_tex'] = $p->getPrice(false);
$line['price_tin'] = $p->getPrice(true);
$line['upc'] = $p->upc ? $p->upc : '';
$line['features'] = '';
$features = $p->getFrontFeatures($id_lang);
$position = 1;
$devider = '';
foreach ($features as $feature) {
$sql = 'SELECT `id_feature`
FROM ' . _DB_PREFIX_ . 'feature_lang
WHERE `name` = "' . pSql($feature['name']) . '"';
$sql1 = 'SELECT `id_feature_value`
FROM ' . _DB_PREFIX_ . 'feature_value_lang
WHERE `value` = "' . pSql($feature['value']) . '"';
$id_feature = Db::getInstance()->getValue($sql);
$id_feature_value = Db::getInstance()->getValue($sql1);
$line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position;
$devider = ',';
$position++;
}
$specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0);
$line['reduction_price'] = '';
$line['reduction_percent'] = '';
$line['reduction_from'] = '';
$line['reduction_to'] = '';
if ($specificPrice) {
if ($specificPrice['reduction_type'] == 'amount') {
$line['reduction_price'] = $specificPrice['reduction'];
} elseif ($specificPrice['reduction_type'] == 'percent') {
$line['reduction_percent'] = $specificPrice['reduction'];
}
if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
$line['reduction_from'] = $specificPrice['from'];
$line['reduction_to'] = $specificPrice['to'];
}
}
$tags = $p->getTags($id_lang);
$line['tags'] = $tags;
$link = new Link();
$imagelinks = array();
$images = $p->getImages($id_lang);
foreach ($images as $image) {
$imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
$this->copyConverFileName($imagelink);
$imagelinks[] = $imagelink;
}
$line['image'] = implode(',', $imagelinks);
$line['delete_existing_images'] = 0;
$line['shop'] = 1;
$warehouses = Warehouse::getWarehousesByProductId($p->id);
$line['warehouse'] = '';
if (!empty($warehouses)) {
$line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
}
$values = array();
$accesories = $p->getAccessories($id_lang);
if (isset($accesories) && $accesories && count($accesories)) {
foreach ($accesories as $accesorie) {
$values[] = $accesorie['id_product'];
}
}
$line['accessories'] = $values ? implode(',', $values) : '';
$values = array();
$carriers = $p->getCarriers();
if (isset($carriers) && $carriers && count($carriers)) {
foreach ($carriers as $carrier) {
$values[] = $carrier['id_carrier'];
}
}
$line['carriers'] = $values ? implode(',', $values) : '';
$values = array();
$customization_fields_ids = $p->getCustomizationFieldIds();
if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) {
foreach ($customization_fields_ids as $customization_field_id) {
$cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang);
$values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name;
//.........这里部分代码省略.........
示例5: getOfferInfo
private function getOfferInfo(Product $model)
{
$res = '';
$res .= CHtml::tag('url', [], $model->getUrl(true));
$res .= CHtml::tag('price', [], $model->price);
$res .= CHtml::tag('currencyId', [], 'RUR');
$res .= CHtml::tag('categoryId', [], $model->category_id);
// tag market_category
$imageCount = 0;
if ($model->image) {
$res .= CHtml::tag('picture', [], $model->getImageUrl());
$imageCount++;
}
foreach ($model->getImages() as $image) {
if ($imageCount > 10) {
break;
}
$res .= CHtml::tag('picture', [], $image->getImageUrl());
$imageCount++;
}
// tag store
// tag pickup
// tag delivery
// tag local_delivery_cost
// tag typePrefix
$res .= CHtml::tag('vendor', [], $model->producer->name);
// tag vendorCode
$res .= CHtml::tag('model', [], htmlspecialchars(strip_tags($model->name)));
$res .= CHtml::tag('description', [], htmlspecialchars(strip_tags($model->description)));
// tag sales_notes
// tag manufacturer_warranty
// tag seller_warranty
// tag country_of_origin
// tag downloadable
// tag adult
// tag age
// tag barcode
// tag cpa
// tag rec
// tag expiry
// tag weight
// tag dimensions
// tag param
return $res;
}
示例6: 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);
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());
}
// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
$id_shop_list = array();
foreach ($info['shop'] as $shop) {
if (!is_numeric($shop)) {
$id_shop_list[] = Shop::getIdByName($shop);
} else {
$id_shop_list[] = $shop;
}
}
if (isset($info['id_product'])) {
$product = new Product((int) $info['id_product'], false, $default_language);
} else {
continue;
}
$id_image = null;
//delete existing images if "delete_existing_images" is set to 1
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']) {
$product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
$url = $info['image_url'];
$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)) {
$this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
$image->delete();
} else {
$id_image = array($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']) {
$images = $product->getImages($default_language);
if ($images) {
foreach ($images as $row) {
if ($row['position'] == (int) $info['image_position']) {
$id_image = array($row['id_image']);
break;
}
}
}
if (!$id_image) {
$this->warnings[] = sprintf(Tools::displayError('No image was found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
}
}
$id_attribute_group = 0;
// groups
$groups_attributes = array();
if (isset($info['group'])) {
foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
$tab_group = explode(':', $group);
$group = trim($tab_group[0]);
if (!isset($tab_group[1])) {
$type = 'select';
} else {
$type = trim($tab_group[1]);
}
// sets group
$groups_attributes[$key]['group'] = $group;
// if position is filled
//.........这里部分代码省略.........
示例7: addProducts
//.........这里部分代码省略.........
$doc->inStock = true;
} else {
$doc->inStock = false;
}
$doc->isPlusSize = $productObj->is_plussize ? true : false;
$doc->isRTS = $productObj->is_rts ? true : false;
$doc->quantity = $productObj->quantity ? $productObj->quantity : ($atributeQty ? $atributeQty : 0);
//Indian Price
$doc->offer_price_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, true, 1, false, NULL, NULL, IND_ADDRESS_ID);
$doc->offer_price_in_rs = Tools::convertPrice($doc->offer_price_in, 4);
$doc->mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
if ($doc->mrp_in > $doc->offer_price_in) {
$doc->discount_in = Tools::ps_round(($doc->mrp_in - $doc->offer_price_in) / $doc->mrp_in * 100);
}
//Worldwide Price
$doc->offer_price = $productObj->getPrice();
$doc->offer_price_rs = Tools::convertPrice($doc->offer_price, 4);
$doc->mrp = $productObj->getPriceWithoutReduct();
if ($doc->mrp > $doc->offer_price) {
$doc->discount = Tools::ps_round(($doc->mrp - $doc->offer_price) / $doc->mrp * 100);
}
$date = DateTime::createFromFormat('Y-m-d H:i:s', $productObj->date_add);
$doc->date_add = $date->format("Y-m-d\\TG:i:s\\Z");
$doc->product_link = $productObj->getLink();
$idImage = $productObj->getCoverWs();
if ($idImage) {
$idImage = $productObj->id . '-' . $idImage;
} else {
$idImage = Language::getIsoById(1) . '-default';
}
$doc->image_link_list = $link->getImageLink($productObj->link_rewrite, $idImage, 'list');
$doc->image_link_medium = $link->getImageLink($productObj->link_rewrite, $idImage, 'medium');
$doc->image_link_large = $link->getImageLink($productObj->link_rewrite, $idImage, 'large');
$images = $productObj->getImages(1);
$productImages = array();
foreach ($images as $k => $image) {
$productImages[] = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'large');
}
$doc->image_links = $productImages;
$doc->sales = $productScores[$product['id_product']]['score'];
$productObj->fabric = trim($productObj->fabric);
$productObj->fabric = preg_replace('/\\s+/', '-', $productObj->fabric);
$doc->fabric = strtolower($productObj->fabric);
$doc->is_customizable = $productObj->is_customizable;
if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
$colors = explode(',', $productObj->generic_color);
$indexed_colors = array();
foreach ($colors as $color) {
$indexed_colors[] = strtolower(preg_replace('/\\s+/', '-', trim($color)));
}
$doc->color = $indexed_colors;
}
if (isset($productObj->stone) && !empty($productObj->stone)) {
$stones = explode(',', $productObj->stone);
$indexed_stones = array();
foreach ($stones as $stone) {
$indexed_stones[] = strtolower(preg_replace('/\\s+/', '-', trim($stone)));
}
$doc->stone = $indexed_stones;
}
if (isset($productObj->plating) && !empty($productObj->plating)) {
$platings = explode(',', $productObj->plating);
$indexed_platings = array();
foreach ($platings as $plating) {
$indexed_platings[] = strtolower(preg_replace('/\\s+/', '-', trim($plating)));
}
示例8: attributeImport
public function attributeImport()
{
global $cookie;
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
$groups = array();
foreach (AttributeGroup::getAttributesGroups($defaultLanguage) as $group) {
$groups[$group['name']] = (int) $group['id_attribute_group'];
}
$attributes = array();
foreach (Attribute::getAttributes($defaultLanguage) as $attribute) {
$attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
}
$this->receiveTab();
$handle = $this->openCsvFile();
$fsep = (is_null(Tools::getValue('multiple_value_separator')) or trim(Tools::getValue('multiple_value_separator')) == '') ? ',' : Tools::getValue('multiple_value_separator');
self::setLocale();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8_encode_array($line);
}
$info = self::getMaskedRow($line);
$info = array_map('trim', $info);
self::setDefaultValues($info);
$product = new Product((int) $info['id_product'], false, $defaultLanguage);
$id_image = null;
if (isset($info['image_url']) && $info['image_url']) {
$productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id);
$url = $info['image_url'];
$image = new Image();
$image->id_product = (int) $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = !$productHasImages ? true : false;
$image->legend = self::createMultiLangField($product->name);
if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) {
if (!self::copyImg($product->id, $image->id, $url)) {
$this->_warnings[] = Tools::displayError('Error copying image: ') . $url;
} else {
$id_image = array($image->id);
}
} else {
$this->_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
} elseif (isset($info['image_position']) && $info['image_position']) {
$images = $product->getImages($defaultLanguage);
if ($images) {
foreach ($images as $row) {
if ($row['position'] == (int) $info['image_position']) {
$id_image = array($row['id_image']);
break;
}
}
}
if (!$id_image) {
$this->_warnings[] = sprintf(Tools::displayError('No image found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
}
}
$id_product_attribute = $product->addProductAttribute((double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int) $info['default_on'], strval($info['upc']));
foreach (explode($fsep, $info['options']) as $option) {
list($group, $attribute) = array_map('trim', explode(':', $option));
if (!isset($groups[$group])) {
$obj = new AttributeGroup();
$obj->is_color_group = false;
$obj->name[$defaultLanguage] = $group;
$obj->public_name[$defaultLanguage] = $group;
if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
$obj->add();
$groups[$group] = $obj->id;
} else {
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
}
}
if (!isset($attributes[$group . '_' . $attribute])) {
$obj = new Attribute();
$obj->id_attribute_group = $groups[$group];
$obj->name[$defaultLanguage] = str_replace('\\n', '', str_replace('\\r', '', $attribute));
if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
$obj->add();
$attributes[$group . '_' . $attribute] = $obj->id;
} else {
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
}
}
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attributes[$group . '_' . $attribute] . ',' . (int) $id_product_attribute . ')');
}
}
$this->closeCsvFile($handle);
}
示例9: hookProductFooter
public function hookProductFooter($params)
{
$product = new Product((int) Tools::getValue('id_product'));
$lang_id = (int) (int) $this->context->cookie->id_lang;
$images = $product->getImages($lang_id);
foreach ($images as $image) {
if ($image['cover']) {
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
}
}
if (!isset($cover)) {
$cover = array('id_image' => $this->context->language->iso_code . '-default');
}
$prod = new stdClass();
$prod->name = $product->name[$lang_id];
$prod->description = $product->description[$lang_id];
$prod->link_rewrite = $product->link_rewrite[$lang_id];
$prod->price = $product->price;
$this->context->smarty->assign(array('product' => $prod, 'cover' => $cover['id_image']));
return $this->display(__FILE__, 'product.tpl');
}
示例10: updateProductForPrestashop
//.........这里部分代码省略.........
$control_category = $this->isOldOrNewValueForProduct((int) $product->active, $new_active);
if (!$control_category) {
$product->active = $new_active;
$is_change_product = true;
}
$new_minimal_quantity = (int) $product_attributes["Qta_min"];
if (!$this->isOldOrNewValueForProduct((int) $product->minimal_quantity, $new_minimal_quantity)) {
$product->minimal_quantity = $new_minimal_quantity;
$is_change_product = true;
}
$new_quantity = (int) $product_attributes["Qta"];
if (!$this->isOldOrNewValueForProduct((int) $product->getQuantity($id_product), $new_quantity)) {
StockAvailable::setQuantity($id_product, 0, $new_quantity);
}
$array_old_features = $product->getFeatures();
$array_features = $product_attributes["Feature"];
$height = false;
$width = false;
foreach ($array_old_features as $array_old_single_features) {
$feature = new FeatureCore((int) $array_old_single_features['id_feature']);
$tmp_feature = $feature->name;
$single_old_feature = $tmp_feature[$language];
$feature_value = new FeatureValueCore((int) $array_old_single_features["id_feature_value"]);
$tmp_feature_value = $feature_value->value;
$single_old_feature_value = $tmp_feature_value[$language];
if ($this->isOldOrNewValueForProduct("Altezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Altezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Altezza"] . " cm");
$feature_value->update();
$height = true;
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Larghezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Larghezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Larghezza"] . " cm");
$feature_value->update();
$width = true;
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Lunghezza", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Lunghezza"] . " cm")) {
$feature_value->value = array($language => $array_features["Lunghezza"] . " cm");
$feature_value->update();
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Modello", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Modello"])) {
$feature_value->value = array($language => $array_features["Modello"]);
$feature_value->update();
$is_change_product = true;
}
}
if ($this->isOldOrNewValueForProduct("Linea", $single_old_feature)) {
if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Linea"])) {
$feature_value->value = array($language => $array_features["Linea"]);
$feature_value->update();
$is_change_product = true;
}
}
}
if ($height) {
$product->height = (double) $array_features["Altezza"];
$is_change_product = true;
}
if ($width) {
$product->width = (double) $array_features["Larghezza"];
$is_change_product = true;
}
if ($is_change_product) {
$product->update();
}
if (!$control_category) {
$ids_categories_array = $product->getWsCategories();
$this->controlCategoriesForActivateTheir($ids_categories_array);
}
$change_new_image = $this->updateCombinantionsForPrestashop($id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language);
$string_triple = array();
$return = array();
array_push($return, $product->id);
$array_images_combinations_of_the_product = $product->getImages($language);
$element = array();
foreach ($array_images_combinations_of_the_product as $array_combo_image) {
$name_of_the_image = $array_combo_image['legend'];
$id_image_of_the_product = $array_combo_image['id_image'];
array_push($element, $id_image_of_the_product . ";" . $name_of_the_image);
}
array_push($return, $element);
foreach ($change_new_image as $array_combo_image) {
$fetch_tmp = explode(";", $array_combo_image);
$fetch_jpg = explode(".jpg", $fetch_tmp[1]);
$fetch_image_name = explode(",", $fetch_jpg[0]);
array_push($string_triple, $fetch_image_name[2]);
}
array_push($return, $change_new_image);
array_push($return, $string_triple);
return $return;
}
示例11: postProcess
public function postProcess()
{
if (Tools::isSubmit('submitExport')) {
$delimiter = Tools::getValue('export_delimiter');
$id_lang = Tools::getValue('export_language');
$id_shop = (int) $this->context->shop->id;
set_time_limit(0);
$fileName = 'products_' . date("Y_m_d_H_i_s") . '.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$f = fopen('php://output', 'w');
foreach ($this->available_fields as $field => $array) {
$titles[] = $array['label'];
}
fputcsv($f, $titles, $delimiter, '"');
$export_active = Tools::getValue('export_active') == 0 ? false : true;
$export_category = Tools::getValue('export_category') == 99999 ? false : Tools::getValue('export_category');
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', $export_category, $export_active);
foreach ($products as $product) {
$line = array();
$p = new Product($product['id_product'], true, $id_lang, $id_shop);
$p->loadStockData();
foreach ($this->available_fields as $field => $array) {
if (isset($p->{$field}) && !is_array($p->{$field})) {
$line[$field] = $p->{$field} ? $p->{$field} : ' ';
} else {
switch ($field) {
case 'categories':
$cats = $p->getProductCategoriesFull($p->id, $id_lang);
$cat_array = array();
foreach ($cats as $cat) {
$cat_array[] = $cat['name'];
}
$line['categories'] = implode(",", $cat_array);
break;
case 'price_tex':
$line['price_tex'] = $p->getPrice(false);
$line['price_tin'] = $p->getPrice(true);
break;
case 'upc':
$line['upc'] = $p->upc ? $p->upc : ' ';
break;
case 'features':
$line['features'] = '';
$features = $p->getFrontFeatures($id_lang);
$position = 1;
foreach ($features as $feature) {
$line['features'] .= $feature['name'] . ':' . $feature['value'] . ':' . $position;
$position++;
}
break;
case 'reduction_price':
$specificPrice = SpecificPrice::getSpecificPrice($p->id, $id_shop, 0, 0, 0, 0);
$line['reduction_price'] = '';
$line['reduction_percent'] = '';
$line['reduction_from'] = '';
$line['reduction_to'] = '';
if ($specificPrice['reduction_type'] == "amount") {
$line['reduction_price'] = $specificPrice['reduction'];
} elseif ($specificPrice['reduction_type'] == "percent") {
$line['reduction_percent'] = $specificPrice['reduction'];
}
if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
$line['reduction_from'] = date_format(date_create($specificPrice['from']), "Y-m-d");
$line['reduction_to'] = date_format(date_create($specificPrice['to']), "Y-m-d");
}
break;
case 'tags':
$tags = $p->getTags($id_lang);
$line['tags'] = $tags;
break;
case 'image':
$link = new Link();
$imagelinks = array();
$images = $p->getImages($id_lang);
foreach ($images as $image) {
$imagelinks[] = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
}
$line['image'] = implode(",", $imagelinks);
break;
case 'delete_existing_images':
$line['delete_existing_images'] = 0;
break;
case 'shop':
$line['shop'] = $id_shop;
break;
case 'warehouse':
$warehouses = Warehouse::getWarehousesByProductId($p->id);
$line['warehouse'] = '';
if (!empty($warehouses)) {
$line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
}
break;
case 'date_added':
$date = new DateTime($p->date_add);
$line['date_add'] = $date->format("Y-m-d");
//.........这里部分代码省略.........
示例12: hookActionProductListModifier
/**
*
*/
public function hookActionProductListModifier($products)
{
$playout = $this->getConfigValue('product_layout');
if (($playout == 'swap' || $playout == 'gallery') && $products['cat_products']) {
foreach ($products['cat_products'] as $key => $product) {
$obj = new Product($product['id_product'], true, $this->context->language->id, $this->context->shop->id);
$images = $obj->getImages((int) $this->context->cookie->id_lang);
$product['ptsimages'] = $images;
$product['swapimage'] = count($images) > 1 ? $images[1] : '';
$products['cat_products'][$key] = $product;
}
}
}
示例13: getProductDoc
//.........这里部分代码省略.........
$indexed_colors[] = strtolower(preg_replace('/\\s+/', '-', trim($color)));
}
$doc->color = $indexed_colors;
}
if (isset($productObj->stone) && !empty($productObj->stone)) {
$stones = explode(',', $productObj->stone);
$indexed_stones = array();
foreach ($stones as $stone) {
$indexed_stones[] = strtolower(preg_replace('/\\s+/', '-', trim($stone)));
}
$doc->stone = $indexed_stones;
}
if (isset($productObj->plating) && !empty($productObj->plating)) {
$platings = explode(',', $productObj->plating);
$indexed_platings = array();
foreach ($platings as $plating) {
$indexed_platings[] = strtolower(preg_replace('/\\s+/', '-', trim($plating)));
}
$doc->plating = $indexed_platings;
}
if (isset($productObj->material) && !empty($productObj->material)) {
$materials = explode(',', $productObj->material);
$indexed_materials = array();
foreach ($materials as $material) {
$indexed_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($material)));
}
$doc->material = $indexed_materials;
}
if (isset($productObj->look) && !empty($productObj->look)) {
$looks = explode(',', $productObj->look);
$indexed_looks = array();
foreach ($looks as $look) {
$indexed_looks[] = strtolower(preg_replace('/\\s+/', '-', trim($look)));
}
$doc->look = $indexed_looks;
}
if (isset($productObj->handbag_occasion) && !empty($productObj->handbag_occasion)) {
$handbag_occasions = explode(',', $productObj->handbag_occasion);
$indexed_handbag_occasions = array();
foreach ($handbag_occasions as $handbag_occasion) {
$indexed_handbag_occasions[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_occasion)));
}
$doc->handbag_occasion = $indexed_handbag_occasions;
}
if (isset($productObj->handbag_style) && !empty($productObj->handbag_style)) {
$handbag_styles = explode(',', $productObj->handbag_style);
$indexed_handbag_styles = array();
foreach ($handbag_styles as $handbag_style) {
$indexed_handbag_styles[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_style)));
}
$doc->handbag_style = $indexed_handbag_styles;
}
if (isset($productObj->handbag_material) && !empty($productObj->handbag_material)) {
$handbag_materials = explode(',', $productObj->handbag_material);
$indexed_handbag_materials = array();
foreach ($handbag_materials as $handbag_material) {
$indexed_handbag_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_material)));
}
$doc->handbag_material = $indexed_handbag_materials;
}
$combinaisons = $productObj->getAttributeCombinaisons(1);
$indexed_sizes = array();
foreach ($combinaisons as $k => $combinaison) {
if ($combinaison['group_name'] == 'size' || $combinaison['group_name'] == 'Size') {
$indexed_sizes[] = $combinaison['attribute_name'];
}
}
$doc->size = $indexed_sizes;
//Indian Price
$doc->offer_price_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, true, 1, false, NULL, NULL, IND_ADDRESS_ID);
$doc->offer_price_in_rs = Tools::convertPrice($doc->offer_price_in, 4);
$doc->mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
if ($doc->mrp_in > $doc->offer_price_in) {
$doc->discount_in = Tools::ps_round(($doc->mrp_in - $doc->offer_price_in) / $doc->mrp_in * 100);
}
//Worldwide Price
$doc->offer_price = $productObj->getPrice();
$doc->offer_price_rs = Tools::convertPrice($doc->offer_price, 4);
$doc->mrp = $productObj->getPriceWithoutReduct();
if ($doc->mrp > $doc->offer_price) {
$doc->discount = Tools::ps_round(($doc->mrp - $doc->offer_price) / $doc->mrp * 100);
}
$doc->product_link = $productObj->getLink();
$idImage = $productObj->getCoverWs();
if ($idImage) {
$idImage = $productObj->id . '-' . $idImage;
} else {
$idImage = Language::getIsoById(1) . '-default';
}
$doc->image_link_list = $link->getImageLink($productObj->link_rewrite, $idImage, 'list');
$doc->image_link_medium = $link->getImageLink($productObj->link_rewrite, $idImage, 'medium');
$doc->image_link_large = $link->getImageLink($productObj->link_rewrite, $idImage, 'large');
$images = $productObj->getImages(1);
$productImages = array();
foreach ($images as $k => $image) {
$productImages[] = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'large');
}
$doc->image_links = $productImages;
return $doc;
}
示例14: parseTemplateStandard
//.........这里部分代码省略.........
} else {
$lnk = false;
}
$thumb = $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('thumb-image'));
$image = $tool->getMainTemplate(array('id' => 'category' . $product['id_image'], 'group' => 'category', 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('large-image')), 'thumb' => $thumb, 'title' => $product['name'], 'shortDescription' => $product['description_short'], 'description' => $product['description']));
//$image = preg_replace('/<a class="MagicZoomPlus"/is', '<a class="MagicZoomPlus product_img_link"', $image);
$image_suffix = $tool->params->getValue('thumb-image') ? '-' . $tool->params->getValue('thumb-image') : '';
$file_path = _PS_PROD_IMG_DIR_ . $product['id_image'] . $image_suffix . '.jpg';
if (!file_exists($file_path)) {
$split_ids = explode('-', $product['id_image']);
$id_image = isset($split_ids[1]) ? $split_ids[1] : $split_ids[0];
$folders = implode('/', str_split((string) $id_image)) . '/';
$file_path = _PS_PROD_IMG_DIR_ . $folders . $id_image . $image_suffix . '.jpg';
}
$size = getimagesize($file_path);
//need a.product_img_link > img for blockcart module
$image = '<div class="MagicToolboxContainer" style="float: left; width: ' . $size[0] . 'px; margin-right: 0.6em;" ><div style="width:0px;height:1px;overflow:hidden;visibility:hidden;"><a class="product_img_link" href="#"><img src="' . $thumb . '" /></a></div>' . $image . '</div>';
//$image = '<div class="MagicToolboxContainer" style="float: left; width: '.$size[0].'px; margin-right: 0.6em;" >'.$image.'</div>';
$pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $product['id_image'], 'home'), '/') . '"[^>]*?>';
$pattern = '(<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
$output = preg_replace('/' . $pattern . '/is', $image, $output);
}
break;
case 'product':
if (!isset($GLOBALS['magictoolbox']['magiczoomplus']['product'])) {
//for skip loyalty module product.tpl
return self::prepareOutput($output);
}
//$product = new Product(intval($smarty->$tpl_vars['product']->id), true, intval($cookie->id_lang));
//get some data from $GLOBALS for compatible with Prestashop modules which reset the $product smarty variable
$product = new Product(intval($GLOBALS['magictoolbox']['magiczoomplus']['product']['id']), true, intval($cookie->id_lang));
$lrw = $product->link_rewrite;
$pid = $product->id;
$images = $product->getImages(intval($cookie->id_lang));
$productImages = array();
foreach ($images as $image) {
if ($image['cover']) {
$cover = $image;
$cover['id_image'] = intval($product->id) . '-' . $cover['id_image'];
}
$productImages[intval($image['id_image'])] = $image;
}
if (!isset($cover)) {
// ensure that we have the image
return self::prepareOutput($output);
}
$GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
$thumb = $_link->getImageLink($lrw, $cover['id_image'], $tool->params->getValue('thumb-image'));
$image = $tool->getMainTemplate(array('id' => 'MainImage', 'img' => $_link->getImageLink($lrw, $cover['id_image'], $tool->params->getValue('large-image')), 'thumb' => $thumb, 'title' => $product->name, 'shortDescription' => $product->description_short, 'description' => $product->description));
$iTypes = $this->getImagesTypes();
$selectors = array();
if (count($productImages) > 0) {
$pattern = '<img[^>]*?src="[^"]*?{medium}"[^>]*>';
//$pattern = '(<a[^>]*?href="[^"]*?{thickbox}"[^>]*>\s*)?' . $pattern . '(\s*<\/a>)?';
$pattern = '(<a[^>]*?href="[^"]*"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
foreach ($productImages as $i) {
$s = $tool->getSelectorTemplate(array('id' => 'MainImage', 'img' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('large-image')), 'medium' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('thumb-image')), 'thumb' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('selector-image')), 'title' => $i['legend']));
$s = str_replace('<img ', '<img id="thumb_' . $i['id_image'] . '" ', $s);
$s = str_replace('<a ', '<a class="magicthickbox" ', $s);
//$p = str_replace('{thickbox}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'thickbox'), '/'), $pattern);
//$p = str_replace('{medium}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'medium'), '/'), $p);
$p = str_replace('{medium}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'medium'), '/'), $pattern);
$replaced = 0;
if ($tool->params->checkValue('template', 'original')) {
// append selector in their preserved place
$output = preg_replace('/' . $p . '/is', $s, $output, -1, $replaced);
示例15: 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']);
//.........这里部分代码省略.........