【发布时间】:2016-09-30 08:06:18
【问题描述】:
我在将产品从 prestashop 导出到 ebay 时遇到问题“缺少 ean 代码”
如何向我的所有 PrestaShop 1000 产品添加/生成随机 EAN 代码?
谢谢
【问题讨论】:
标签: prestashop
我在将产品从 prestashop 导出到 ebay 时遇到问题“缺少 ean 代码”
如何向我的所有 PrestaShop 1000 产品添加/生成随机 EAN 代码?
谢谢
【问题讨论】:
标签: prestashop
一次编辑多个产品的最快方法是使用“导入”功能。 您只能使用它来编辑产品的 EAN。
您可以在“高级参数”选项卡中找到它。
您的产品 EAN 将会更新。
希望对你有帮助:)
/!\ 导入带有强制 ID 的文件时要小心,它会覆盖现有信息。如果您在某些产品上有现有的 EAN,它们将被修改。 /!*
【讨论】:
您能否就如何出口产品或从哪里出口产品的问题多解释一下?所以,我可以给你这个问题的准确解决方案。
如果您想要通用解决方案,请查看以下代码:
打开您的产品类文件:root_directory/classes/Product.php
编辑以下函数:
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) {
parent::__construct($id_product, $id_lang, $id_shop);
if (empty($this->ean13)) {
$this->ean13 = $this->generateEAN13(); //New function
}
//Remaining part of this function keep same
}
在此文件中添加新函数以生成 EAN13:
public function generateEAN13() {
$length = 13;
$ean_number = '';
$chars = '0123456789';
$maxlength = Tools::strlen($chars);
$i = 0;
while ($i < $length) {
$char = Tools::substr($chars, mt_rand(0, $maxlength - 1), 1);
if (!strstr($code, $char)) {
$code .= $char;
$i++;
}
}
//Check whether this ean alread exist or not for product
$sql = 'SELECT id_product FROM '._DB_PREFIX_.'product where ean13 = "'.pSQL($code).'"';
if ((int)Db::getInstance()->getValue($sql) == 0) {
return $code;
} else {
//Check ean13 on combination
$sql = 'SELECT id_product_attribute FROM '._DB_PREFIX_.'product_attribute where ean13 = "'.pSQL($code).'"';
if ((int)Db::getInstance()->getValue($sql) == 0) {
return $code;
}
}
return $this->generateEAN13();
}
只要您获得产品数据并且产品没有 EAN13,上述代码就会为您提供带有 ean13 编号的产品。
【讨论】:
请编辑 Product.php 类文件有一个名为 priceCalculation() 的函数
此函数使用以下代码计算税金并将其添加到产品价格中:
if ($use_tax) {
$price = $product_tax_calculator->addTaxes($price);
}
和
$price += $ecotax_tax_calculator->addTaxes($ecotax);
您可以为制造商添加一些条件以获得所需的结果。
【讨论】: