本文整理汇总了PHP中Tag::addTags方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::addTags方法的具体用法?PHP Tag::addTags怎么用?PHP Tag::addTags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tag
的用法示例。
在下文中一共展示了Tag::addTags方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateEntityTag
/**
* Special case for "tag" entity
*/
public function populateEntityTag()
{
foreach ($this->languages as $id_lang => $iso) {
if (!file_exists($this->lang_path . $this->getFallBackToDefaultLanguage($iso) . '/data/tag.xml')) {
continue;
}
$xml = $this->loadEntity('tag', $this->getFallBackToDefaultLanguage($iso));
$tags = array();
foreach ($xml->tag as $tag_node) {
$products = trim((string) $tag_node['products']);
if (!$products) {
continue;
}
foreach (explode(',', $products) as $product) {
$product = trim($product);
$product_id = $this->retrieveId('product', $product);
if (!isset($tags[$product_id])) {
$tags[$product_id] = array();
}
$tags[$product_id][] = trim((string) $tag_node['name']);
}
}
foreach ($tags as $id_product => $tag_list) {
Tag::addTags($id_lang, $id_product, $tag_list);
}
}
}
示例2: updateTags
/**
* Update product tags
*
* @param array Languages
* @param object $product Product
* @return boolean Update result
*/
public function updateTags($languages, $product)
{
$tagError = true;
/* Reset all tags for THIS product */
if (!Db::getInstance()->Execute('
DELETE FROM `' . _DB_PREFIX_ . 'product_tag`
WHERE `id_product` = ' . intval($product->id))) {
return false;
}
/* Assign tags to this product */
foreach ($languages as $language) {
if ($value = Tools::getValue('tags_' . $language['id_lang'])) {
$tagError &= Tag::addTags($language['id_lang'], intval($product->id), $value);
}
}
return $tagError;
}
示例3: productImport
//.........这里部分代码省略.........
} else {
$res = $product->add();
}
}
}
// If both failed, mysql error
if (!$res) {
$this->_errors[] = $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
} else {
// SpecificPrice (only the basic reduction feature is supported by the import)
if (isset($info['reduction_price']) and $info['reduction_price'] > 0 or isset($info['reduction_percent']) and $info['reduction_percent'] > 0) {
$specificPrice = new SpecificPrice();
$specificPrice->id_product = (int) $product->id;
$specificPrice->id_shop = (int) Shop::getCurrentShop();
$specificPrice->id_currency = 0;
$specificPrice->id_country = 0;
$specificPrice->id_group = 0;
$specificPrice->price = 0.0;
$specificPrice->from_quantity = 1;
$specificPrice->reduction = (isset($info['reduction_price']) and $info['reduction_price']) ? $info['reduction_price'] : $info['reduction_percent'] / 100;
$specificPrice->reduction_type = (isset($info['reduction_price']) and $info['reduction_price']) ? 'amount' : 'percentage';
$specificPrice->from = (isset($info['reduction_from']) and Validate::isDate($info['reduction_from'])) ? $info['reduction_from'] : '0000-00-00 00:00:00';
$specificPrice->to = (isset($info['reduction_to']) and Validate::isDate($info['reduction_to'])) ? $info['reduction_to'] : '0000-00-00 00:00:00';
if (!$specificPrice->add()) {
$this->_addProductWarning($info['name'], $product->id, $this->l('Discount is invalid'));
}
}
if (isset($product->tags) and !empty($product->tags)) {
// Delete tags for this id product, for no duplicating error
Tag::deleteTagsForProduct($product->id);
$tag = new Tag();
if (!is_array($product->tags)) {
$product->tags = self::createMultiLangField($product->tags);
foreach ($product->tags as $key => $tags) {
$isTagAdded = $tag->addTags($key, $product->id, $tags);
if (!$isTagAdded) {
$this->_addProductWarning($info['name'], $product->id, $this->l('Tags list') . ' ' . $this->l('is invalid'));
break;
}
}
} else {
foreach ($product->tags as $key => $tags) {
$str = '';
foreach ($tags as $one_tag) {
$str .= $one_tag . ',';
}
$str = rtrim($str, ',');
$isTagAdded = $tag->addTags($key, $product->id, $str);
if (!$isTagAdded) {
$this->_addProductWarning($info['name'], $product->id, 'Invalid tag(s) (' . $str . ')');
break;
}
}
}
}
//delete existing images if "delete_existing_images" is set to 1
if (isset($product->delete_existing_images)) {
if ((bool) $product->delete_existing_images) {
$product->deleteImages();
} elseif (isset($product->image) and is_array($product->image) and sizeof($product->image)) {
$product->deleteImages();
}
}
if (isset($product->image) and is_array($product->image) and sizeof($product->image)) {
$productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id);
foreach ($product->image as $key => $url) {
if (!empty($url)) {
$image = new Image();
$image->id_product = (int) $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = (!$key and !$productHasImages) ? true : false;
$image->legend = self::createMultiLangField($product->name[$defaultLanguageId]);
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 {
$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();
}
}
}
}
if (isset($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
$features = get_object_vars($product);
foreach ($features as $feature => $value) {
if (!strncmp($feature, '#F_', 3) and Tools::strlen($product->{$feature})) {
$feature_name = str_replace('#F_', '', $feature);
$id_feature = Feature::addFeatureImport($feature_name);
$id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature});
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
}
$this->closeCsvFile($handle);
}
示例4: productImport
//.........这里部分代码省略.........
$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[] = intval($category['id_category']);
} else {
$categoryToCreate = new Category();
$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[] = intval($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();
}
}
}
}
}
$product->id_category_default = isset($product->id_category[0]) ? intval($product->id_category[0]) : '';
$link_rewrite = is_array($product->link_rewrite) ? $product->link_rewrite[$defaultLanguageId] : '';
$valid_link = Validate::isLinkRewrite($link_rewrite);
$bak = $product->link_rewrite;
if (isset($product->link_rewrite[$defaultLanguageId]) and empty($product->link_rewrite[$defaultLanguageId]) or !$valid_link) {
$link_rewrite = Tools::link_rewrite($product->name[$defaultLanguageId]);
}
if (!$valid_link) {
$this->_warnings[] = Tools::displayError('Rewrited link for') . ' ' . $bak . (isset($info['id']) ? ' (ID ' . $info['id'] . ') ' : '') . ' ' . Tools::displayError('was re-written as') . ' ' . $link_rewrite;
}
$product->link_rewrite = self::createMultiLangField($link_rewrite);
$res = false;
$fieldError = $product->validateFields(UNFRIENDLY_ERROR, true);
$langFieldError = $product->validateFieldsLang(UNFRIENDLY_ERROR, true);
if ($fieldError === true and $langFieldError === true) {
// check quantity
if ($product->quantity == NULL) {
$product->quantity = 0;
}
// If id product AND id product already in base, trying to update
if ($product->id and Product::existsInDatabase(intval($product->id))) {
$datas = Db::getInstance()->getRow('SELECT `date_add` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . intval($product->id));
$product->date_add = pSQL($datas['date_add']);
$res = $product->update();
}
// If no id_product or update failed
if (!$res) {
$res = $product->add();
}
}
// If both failed, mysql error
if (!$res) {
$this->_errors[] = $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
} else {
if (isset($product->tags) and !empty($product->tags)) {
$tag = new Tag();
$array = self::createMultiLangField($product->tags);
foreach ($array as $key => $tags) {
$a = $tag->addTags($key, $product->id, $tags);
}
}
if (isset($product->image) and is_array($product->image) and sizeof($product->image)) {
$productHasImages = (bool) Image::getImages(intval($cookie->id_lang), intval($product->id));
foreach ($product->image as $key => $url) {
if (!empty($url)) {
$image = new Image();
$image->id_product = intval($product->id);
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = (!$key and !$productHasImages) ? true : false;
$image->legend = self::createMultiLangField($product->name[$defaultLanguageId]);
if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) {
self::copyImg($product->id, $image->id, $url);
} 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();
}
}
}
}
if (isset($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
$features = get_object_vars($product);
foreach ($features as $feature => $value) {
if (!strncmp($feature, '#F_', 3) and Tools::strlen($product->{$feature})) {
$feature_name = str_replace('#F_', '', $feature);
$id_feature = Feature::addFeatureImport($feature_name);
$id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature});
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
}
$this->closeCsvFile($handle);
}
示例5: productImportOne
//.........这里部分代码省略.........
$specific_price->from_quantity = 1;
$specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100;
$specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage';
$specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00';
$specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00';
if (!$validateOnly && !$specific_price->save()) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid'));
}
}
}
if (!$validateOnly && isset($product->tags) && !empty($product->tags)) {
if (isset($product->id) && $product->id) {
$tags = Tag::getProductTags($product->id);
if (is_array($tags) && count($tags)) {
if (!empty($product->tags)) {
$product->tags = explode($this->multiple_value_separator, $product->tags);
}
if (is_array($product->tags) && count($product->tags)) {
foreach ($product->tags as $key => $tag) {
if (!empty($tag)) {
$product->tags[$key] = trim($tag);
}
}
$tags[$id_lang] = $product->tags;
$product->tags = $tags;
}
}
}
// Delete tags for this id product, for no duplicating error
Tag::deleteTagsForProduct($product->id);
if (!is_array($product->tags) && !empty($product->tags)) {
$product->tags = AdminImportController::createMultiLangField($product->tags);
foreach ($product->tags as $key => $tags) {
$is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid'));
break;
}
}
} else {
foreach ($product->tags as $key => $tags) {
$str = '';
foreach ($tags as $one_tag) {
$str .= $one_tag . $this->multiple_value_separator;
}
$str = rtrim($str, $this->multiple_value_separator);
$is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
break;
}
}
}
}
//delete existing images if "delete_existing_images" is set to 1
if (!$validateOnly && isset($product->delete_existing_images)) {
if ((bool) $product->delete_existing_images) {
$product->deleteImages();
}
}
if (!$validateOnly && isset($product->image) && is_array($product->image) && count($product->image)) {
$product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
foreach ($product->image as $key => $url) {
$url = trim($url);
$error = false;
if (!empty($url)) {
示例6: updateTags
public function updateTags($languages, $product)
{
${${"GLOBALS"}["eexlddxulmu"]} = true;
$iqvagwtobzz = "tag_success";
if (!Tag::deleteTagsForProduct((int) $product->id)) {
$this->errors[] = Tools::displayError("An error occurred while attempting to delete previous tags.");
}
foreach (${${"GLOBALS"}["emgichjdg"]} as ${${"GLOBALS"}["exhdxhsxzdo"]}) {
if (${${"GLOBALS"}["kzwkbwmzgtl"]} = Tools::getValue("tags_" . ${${"GLOBALS"}["exhdxhsxzdo"]}["id_lang"])) {
${${"GLOBALS"}["eexlddxulmu"]} &= Tag::addTags(${${"GLOBALS"}["exhdxhsxzdo"]}["id_lang"], (int) $product->id, ${${"GLOBALS"}["kzwkbwmzgtl"]});
}
}
$jgkmbwkqkq = "tag_success";
if (!${$iqvagwtobzz}) {
$this->errors[] = Tools::displayError("An error occurred while adding tags.");
}
return ${$jgkmbwkqkq};
}
示例7: handleConfirm
//.........这里部分代码省略.........
if ($fieldError === true and $langFieldError === true) {
// check quantity
if ($product->quantity == NULL) {
$product->quantity = 0;
}
// If no id_product or update failed
if ($update && $product->id) {
$res = $product->update();
} else {
$res = $product->add();
}
$added_product_ids[] = $product->id;
}
if (isset($product->discount) && $product->discount > 0) {
SpecificPrice::deleteByProductId((int) $product->id);
$specificPrice = new SpecificPrice();
$specificPrice->id_product = (int) $product->id;
$specificPrice->id_shop = (int) Shop::getCurrentShop();
$specificPrice->id_currency = 0;
$specificPrice->id_country = 0;
$specificPrice->id_group = 0;
$specificPrice->from_quantity = 1;
$specificPrice->reduction = $product->discount / 100;
$specificPrice->reduction_type = 'percentage';
$specificPrice->from = '2012-01-01 00:00:00';
$specificPrice->to = '2016-01-01 00:00:00';
$specificPrice->price = $product->price;
$specificPrice->add();
}
if (isset($product->tags) and !empty($product->tags)) {
// Delete tags for this id product, for no duplicating error
Tag::deleteTagsForProduct($product->id);
$tag = new Tag();
$tag->addTags($defaultLanguageId, $product->id, $tags);
}
if (isset($product->images) and is_array($product->images) and sizeof($product->images) and !$update || $overwrite_imgs == "on") {
$product->deleteImages();
$first_image = true;
foreach ($product->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 (!self::copyImg($product->id, $image->id, $image_path)) {
$_warnings[] = Tools::displayError('Error copying image: ') . $image_path;
} else {
//delete the original image
@unlink($image_path);
}
} else {
$_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
$first_image = false;
}
}
if (isset($product->id_category)) {
$product->updateCategories(array_map('intval', $product->id_category));
}
$this->addFeature($product->id, 'fabric', $product->fabric);
示例8: productImport
//.........这里部分代码省略.........
$product_supplier->id_product = $product->id;
$product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = $product->id_supplier;
$product_supplier->product_supplier_price_te = $product->wholesale_price;
$product_supplier->product_supplier_reference = $product->supplier_reference;
$product_supplier->save();
}
// SpecificPrice (only the basic reduction feature is supported by the import)
if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) {
$specific_price = new SpecificPrice();
$specific_price->id_product = (int) $product->id;
// @todo multishop specific price import
$specific_price->id_shop = $this->context->shop->id;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->price = -1;
$specific_price->id_customer = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100;
$specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage';
$specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00';
$specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00';
if (!$specific_price->add()) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid'));
}
}
if (isset($product->tags) && !empty($product->tags)) {
// Delete tags for this id product, for no duplicating error
Tag::deleteTagsForProduct($product->id);
if (!is_array($product->tags)) {
$product->tags = AdminImportController::createMultiLangField($product->tags);
foreach ($product->tags as $key => $tags) {
$is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid'));
break;
}
}
} else {
foreach ($product->tags as $key => $tags) {
$str = '';
foreach ($tags as $one_tag) {
$str .= $one_tag . $this->multiple_value_separator;
}
$str = rtrim($str, $this->multiple_value_separator);
$is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
break;
}
}
}
}
//delete existing images if "delete_existing_images" is set to 1
if (isset($product->delete_existing_images)) {
if ((bool) $product->delete_existing_images) {
$product->deleteImages();
} else {
if (isset($product->image) && is_array($product->image) && count($product->image)) {
$product->deleteImages();
}
}
}
if (isset($product->image) && is_array($product->image) && count($product->image)) {
$product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
示例9: addTags
public function addTags($post_id, $tags)
{
$tagModel = new Tag();
$tagModel->addTags($post_id, $tags);
}
示例10: function
});
$app->post('/new-post', function () use($app) {
$req = $app->request();
if ($req->post('new-post')) {
require_once 'core/post.inc.php';
require_once 'core/tag.inc.php';
session_start();
$post = new Post();
$tag = new Tag();
$title = $req->post('title');
$body = $req->post('body');
$tags = explode(" ", $req->post('tags'));
$result = $post->addPost(array('title' => $title, 'body' => $body, 'uid' => $_SESSION['user_id']));
if (gettype($result) == 'integer') {
// print_r($tags);
$tag->addTags($result, $tags);
$app->redirect('/Blog-It/post/' . $result);
} else {
$app->render('new.php', array('err' => 'There was an error adding your post. Please try again later.'));
}
}
});
/*
* Custom 404 page
*/
$app->notFound(function () use($app) {
require_once 'core/user.inc.php';
$user = new User();
$loggedIn = 0;
session_start();
if ($user->isLoggedIn()) {
示例11: productImport
//.........这里部分代码省略.........
$specific_price->id_customer = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100;
$specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage';
$specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00';
$specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00';
if (!$specific_price->save()) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid'));
}
}
}
if (isset($product->tags) && !empty($product->tags)) {
if (isset($product->id) && $product->id) {
$tags = Tag::getProductTags($product->id);
if (is_array($tags) && count($tags)) {
if (!empty($product->tags)) {
$product->tags = explode($this->multiple_value_separator, $product->tags);
}
if (is_array($product->tags) && count($product->tags)) {
foreach ($product->tags as $key => $tag) {
if (!empty($tag)) {
$product->tags[$key] = trim($tag);
}
}
$tags[$id_lang] = $product->tags;
$product->tags = $tags;
}
}
}
Tag::deleteTagsForProduct($product->id);
if (!is_array($product->tags) && !empty($product->tags)) {
$product->tags = AdminImportController::createMultiLangField($product->tags);
foreach ($product->tags as $key => $tags) {
$is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid'));
break;
}
}
} else {
foreach ($product->tags as $key => $tags) {
$str = '';
foreach ($tags as $one_tag) {
$str .= $one_tag . $this->multiple_value_separator;
}
$str = rtrim($str, $this->multiple_value_separator);
$is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
if (!$is_tag_added) {
$this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
break;
}
}
}
}
if (isset($product->delete_existing_images)) {
if ((bool) $product->delete_existing_images) {
$product->deleteImages();
}
}
if (isset($product->image) && is_array($product->image) && count($product->image)) {
$product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
foreach ($product->image as $key => $url) {
$url = trim($url);
$error = false;
if (!empty($url)) {
$url = str_replace(' ', '%20', $url);
示例12: importProducts
protected function importProducts()
{
$this->truncateTables(array('product', 'product_lang', 'product_shop', 'product_sale', 'product_supplier', 'product_tag', 'feature_product', 'category_product', 'product_carrier', 'compare_product', 'product_attachment', 'product_country_tax', 'product_download', 'product_group_reduction_cache', 'scene_products', 'warehouse_product_location', 'customization', 'customization_field', 'customization_field_lang', 'supply_order_detail', 'attribute_impact', 'pack'));
$handle = $this->openCsvFile('products.csv');
$languages = Language::getLanguages(false);
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$product = new Product((int) $line[0]);
$product->id = (int) $line[0];
$product->active = $line[1];
foreach ($languages as $lang) {
$product->name[$lang['id_lang']] = $line['2'];
}
$categories = explode(',', $line[3]);
$product->id_category_default = $categories[0] ? $categories[0] : Configuration::get('PS_HOME_CATEGORY');
if (isset($categories) && $categories && count($categories)) {
$product->addToCategories($categories);
}
if (isset($line[4])) {
$product->price_tex = $line[4];
}
if (isset($line[5])) {
$product->price_tin = $line[5];
}
$product->id_tax_rules_group = trim($line[6]) ? $line[6] : 0;
$product->wholesale_price = trim($line[7]) ? $line[7] : 0;
$product->on_sale = trim($line[8]) ? $line[8] : 0;
if (trim($line[13])) {
$product->reference = $line[13];
}
if (trim($line[14])) {
$product->supplier_reference = trim($line[14]);
}
if (trim($line[15])) {
$product->id_supplier = (int) $line[15];
}
if (isset($product->id) && $product->id && isset($product->id_supplier) && property_exists($product, 'supplier_reference')) {
$id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier((int) $product->id, 0, (int) $product->id_supplier);
if ($id_product_supplier) {
$product_supplier = new ProductSupplier($id_product_supplier);
} else {
$product_supplier = new ProductSupplier();
}
$product_supplier->id_product = (int) $product->id;
$product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = (int) $product->id_supplier;
$product_supplier->product_supplier_price_te = $product->wholesale_price;
$product_supplier->product_supplier_reference = $product->supplier_reference;
$product_supplier->save();
}
if (trim($line[16])) {
$product->id_manufacturer = $line[16];
}
if (!Tools::isEmpty(trim($line[17]))) {
$product->ean13 = $line[17];
}
if (trim($line[18])) {
$product->upc = $line[18];
}
if (trim($line[19])) {
$product->ecotax = $line[19];
}
$product->width = $line[20];
$product->height = $line[21];
$product->depth = $line[22];
$product->weight = $line[23];
if ($line[24]) {
StockAvailable::setQuantity((int) $product->id, 0, (int) $line[24], (int) $this->context->shop->id);
}
$product->minimal_quantity = $line[25];
$product->visibility = $line[26];
$product->additional_shipping_cost = $line[27];
if (trim($line[28])) {
$product->unity = $line[28];
}
if (trim($line[29])) {
$product->unit_price = $line[29];
}
foreach ($languages as $lang) {
$product->description_short[$lang['id_lang']] = $line[30];
$product->description[$lang['id_lang']] = $line[31];
}
if ($line[32]) {
foreach ($languages as $lang) {
Tag::addTags($lang['id_lang'], $product->id, $line[32]);
}
}
foreach ($languages as $lang) {
$product->meta_title[$lang['id_lang']] = $line[33];
$product->meta_keywords[$lang['id_lang']] = $line[34];
$product->meta_description[$lang['id_lang']] = $line[35];
$product->link_rewrite[$lang['id_lang']] = $line[36];
$product->available_now[$lang['id_lang']] = $line[37];
$product->available_later[$lang['id_lang']] = $line[38];
}
$product->available_for_order = $line[39];
$product->available_date = $line[40];
$product->date_add = $line[41];
$product->show_price = $line[42];
// Features import
//.........这里部分代码省略.........