本文整理汇总了PHP中Attribute::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::add方法的具体用法?PHP Attribute::add怎么用?PHP Attribute::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attribute
的用法示例。
在下文中一共展示了Attribute::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _attributeExists
private function _attributeExists($v)
{
$v = explode(":", $v);
$result = Db::getInstance()->getRow('SELECT `id_attribute` FROM ' . DB_PREFIX . 'attribute WHERE `name`="' . pSQL($v[1]) . '"');
if (isset($result['id_attribute'])) {
return $result['id_attribute'];
} else {
$attribute = new Attribute();
$attribute->id_attribute_group = $v[0];
$attribute->name = $v[1];
$attribute->add();
return $attribute->id;
}
}
示例2: 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);
}
示例3: attributeImportOne
protected function attributeImportOne($info, $default_language, &$groups, &$attributes, $regenerate, $shop_is_feature_active, $validateOnly = false)
{
AdminImportController::setDefaultValues($info);
if (!$shop_is_feature_active) {
$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();
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']) && $info['id_product']) {
$product = new Product((int) $info['id_product'], false, $default_language);
} elseif (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']) . '"
', false);
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product'], false, $default_language);
}
} else {
return;
}
$id_image = array();
if (isset($info['image_url']) && $info['image_url']) {
$info['image_url'] = explode($this->multiple_value_separator, $info['image_url']);
if (is_array($info['image_url']) && count($info['image_url'])) {
foreach ($info['image_url'] as $key => $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;
if (isset($info['image_alt'])) {
$alt = self::split($info['image_alt']);
if (isset($alt[$key]) && strlen($alt[$key]) > 0) {
$alt = self::createMultiLangField($alt[$key]);
$image->legend = $alt;
}
}
$field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
$lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
if ($field_error === true && $lang_field_error === true && !$validateOnly && $image->add()) {
$image->associateTo($id_shop_list);
// FIXME: 2s/image !
if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) {
$this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url);
$image->delete();
} else {
$id_image[] = (int) $image->id;
}
// until here
} else {
if (!$validateOnly) {
$this->warnings[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
}
if ($field_error !== true || $lang_field_error !== true) {
$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($this->multiple_value_separator, $info['image_position']);
if (is_array($info['image_position']) && count($info['image_position'])) {
foreach ($info['image_position'] as $position) {
// choose images from product by position
$images = $product->getImages($default_language);
if ($images) {
foreach ($images as $row) {
if ($row['position'] == (int) $position) {
$id_image[] = (int) $row['id_image'];
break;
}
}
}
if (empty($id_image)) {
$this->warnings[] = sprintf($this->trans('No image was found for combination with id_product = %s and image position = %s.', array(), 'Admin.Parameters.Notification'), $product->id, (int) $position);
}
}
}
}
$id_attribute_group = 0;
// groups
$groups_attributes = array();
if (isset($info['group'])) {
foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
//.........这里部分代码省略.........
示例4: attributeImport
public function attributeImport()
{
$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')) {
$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_product_attribute = $product->addProductAttribute((double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], null, 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] = $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);
}
示例5: 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
//.........这里部分代码省略.........
示例6: updateCombinantionsForPrestashop
/**
* Updates product combinations on Prestashop.
*
* @param integer $id_product
* @param string $url_photo
* @param array $triple_cod_col_siz
* @param array $array_combinations
* @param integer $language
* @return bool
* @see $this->createAttributeGroups
* @see $this->setArrayElementForLinkRewrite
* @see $this->getCodeColor
* @see PrestashopImageHandler getIdImageByName()
* @see PrestashopImageHandler insertImageInPrestashop()
*
*/
private function updateCombinantionsForPrestashop($id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language = 1)
{
$product = new Product((int) $id_product);
$id_new_images = array();
$price = '0.000';
//(float)$product->price;
$reference = $product->reference;
$id_supplier = (int) $product->id_supplier;
foreach ($triple_cod_col_siz as $triple) {
$array_attributes_and_values = $array_combinations[$triple];
$attributes = $array_attributes_and_values["Attributi"];
$values = $array_attributes_and_values["Valori"];
$image = trim($array_attributes_and_values["Immagine"]);
$quantity = (int) $array_attributes_and_values["Qta"];
$variable_tmp_attributes = explode(",", $attributes);
$variable_tmp_values = explode(",", $values);
$id_attributes_for_combinations = array();
$flag_just_exist_color = 1;
$flag_just_exist_size = 1;
for ($i = 0; $i < sizeof($variable_tmp_attributes); $i++) {
$code = "";
if ($variable_tmp_values[$i] != "") {
$id_attribute_group = $this->createAttributeGroups($variable_tmp_attributes[$i], $language);
$id_attributes_for_not_repeat = $this->getAttributeColorAndSize($variable_tmp_values[$i], $language);
if (strtolower($variable_tmp_attributes[$i]) === "colore" || strtolower($variable_tmp_attributes[$i]) === "colori") {
$product_attribute_for_not_reply = $product->getAttributeCombinations($language);
if (empty($product_attribute_for_not_reply)) {
if ($id_attributes_for_not_repeat === '-1') {
$code = $this->getCodeColor(strtolower($variable_tmp_values[$i]));
if ($code != "") {
$code = "#" . $code;
$attribute_for_product = new Attribute();
$attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
$attribute_for_product->color = $code;
$attribute_for_product->id_attribute_group = $id_attribute_group;
$attribute_for_product->add();
array_push($id_attributes_for_combinations, $attribute_for_product->id);
}
} else {
array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
}
} else {
$flag = 1;
foreach ($product_attribute_for_not_reply as $more_attributes) {
if ($more_attributes['attribute_name'] === $variable_tmp_values[$i]) {
array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']);
$flag = 0;
$flag_just_exist_color = 0;
break;
}
}
if ($flag) {
if ($id_attributes_for_not_repeat === '-1') {
$code = $this->getCodeColor(strtolower($variable_tmp_values[$i]));
if ($code != "") {
$code = "#" . $code;
$attribute_for_product = new Attribute();
$attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
$attribute_for_product->color = $code;
$attribute_for_product->id_attribute_group = $id_attribute_group;
$attribute_for_product->add();
array_push($id_attributes_for_combinations, $attribute_for_product->id);
}
} else {
array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
}
}
}
}
if (strtolower($variable_tmp_attributes[$i]) === "taglia" || strtolower($variable_tmp_attributes[$i]) === "taglie") {
$product_attribute_for_not_reply = $product->getAttributeCombinations($language);
if (empty($product_attribute_for_not_reply)) {
if ($id_attributes_for_not_repeat === '-1') {
$attribute_for_product = new Attribute();
$attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
$attribute_for_product->id_attribute_group = $id_attribute_group;
$attribute_for_product->add();
array_push($id_attributes_for_combinations, $attribute_for_product->id);
} else {
array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
}
} else {
$flag = 1;
foreach ($product_attribute_for_not_reply as $more_attributes) {
//.........这里部分代码省略.........
示例7: array
<?php
$group = 'Format eBook';
$default_language = Configuration::get('PS_LANG_DEFAULT');
$id_shop_list = array(1);
$position = AttributeGroup::getHigherPosition() + 1;
$attributeGroup = new AttributeGroup();
$attributeGroup->is_color_group = false;
$attributeGroup->group_type = pSQL('select');
$attributeGroup->name[$default_language] = $group;
$attributeGroup->public_name[$default_language] = $group;
$attributeGroup->position = $position;
$attributeGroup->add();
$attributeGroup->associateTo($id_shop_list);
// create one attribute for each file type
foreach ($this->file_types as $type) {
$position_attribute = Attribute::getHigherPosition($attributeGroup->id) + 1;
$obj = new Attribute();
$obj->id_attribute_group = $attributeGroup->id;
$obj->name[$default_language] = $type;
$obj->position = $position_attribute;
$obj->add();
$obj->associateTo($id_shop_list);
Configuration::updateValue('prestaebooks_attribute_id_' . $type, $obj->id);
}
示例8: 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']);
//.........这里部分代码省略.........
示例9: Attribute
<?php
if (Tools::G('id_attribute_group') > 0) {
$id_attribute_group = Tools::G('id_attribute_group');
}
if (Tools::P('saveAttribute') == 'add' && Tools::P('id_attribute_group') > 0) {
$attribute = new Attribute();
$attribute->copyFromPost();
$attribute->add();
if (is_array($attribute->_errors) and count($attribute->_errors) > 0) {
$errors = $attribute->_errors;
} else {
$_GET['id'] = $attribute->id;
UIAdminAlerts::conf('属性值已添加');
}
$id_attribute_group = Tools::P('id_attribute_group');
}
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
$attribute = new Attribute($id);
$id_attribute_group = $attribute->id_attribute_group;
}
if (Tools::P('saveAttribute') == 'edit') {
if (Validate::isLoadedObject($attribute)) {
$attribute->copyFromPost();
$attribute->update();
}
if (is_array($attribute->_errors) and count($attribute->_errors) > 0) {
$errors = $attribute->_errors;
} else {
UIAdminAlerts::conf('属性值已更新');
示例10: importAttributes
protected function importAttributes()
{
$this->truncateTables(array('attribute', 'attribute_lang', 'attribute_shop'));
$handle = $this->openCsvFile('attributes.csv');
$languages = Language::getLanguages(false);
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$fields = $this->filterFields('Attribute', $this->attributes_fields, $line);
if (!isset($fields['id'])) {
$attribute = new Attribute((int) $line[0]);
$attribute->id = $line[0];
} else {
$attribute = new Attribute((int) $fields['id']);
}
foreach ($fields as $key => $field) {
if ($key == 'name') {
$attribute->{$key} = $this->multilFild($field);
} else {
$attribute->{$key} = $field;
}
}
$attribute->force_id = true;
if (!$res) {
$attribute->add();
}
}
$this->closeCsvFile($handle);
return true;
}