Ela*_*gan 3 magento magento-1.4
我有一个magento商店,我们已经创建了300多种产品.事情是每10到15个产品都有80%以上的同名格式.
例如:
Embroidered Vine - 12
Embroidered Vine - 13
Embroidered Vine - 14
Embroidered Vine - 15
Embroidered Vine - 16
Embroidered Vine - 17
现在,通过在描述字段中输入这些项目来显示其他相关项目.相反,我想运行一个脚本,脚本将需要自动添加相关产品,因为产品名称除了最后两个字符之外是相似的.请有人告诉我如何通过代码自动在magento中设置相关产品.
是否有像setRelatedItems()这样的函数到magento中的产品.
我正在使用magento 1.4.2
您可以为此执行一些原始SQL查询.我已经开发了一个数据集,大量将产品导入magento所以我知道如何做到这一点.
你能做的是以下几点:
SELECT DISTINCT cpev.entity_id
FROM catalog_product_entity_varchar cpev
WHERE value LIKE 'Embroidered Vine%'
Run Code Online (Sandbox Code Playgroud)
在这里,您现在拥有以'Embroidered Vine'作为标题开头的产品的所有实体ID.这个结果可以存储在一个数组中$result.
然后你必须做一个双循环(对于每个刺绣藤产品,你必须添加所有其他刺绣藤产品作为相关产品)
首先在foreach循环中为另一个阵列制作所有'Embroidered Vine'产品的副本(这可能不需要,但仍然只是这样做).
$copy = $result; // Where result is the result of the query (= the entity_id's)
foreach($result as $main_product){ //Each 'Embroidered Vine' product
foreach($copy as $related_product){
if($main_product["entity_id"] == $related_product["entity_id"])
continue; //We do not want to add the same products as related product
// Insert related product
mysql_query("INSERT INTO catalog_product_link (product_id,linked_product_id,link_type_id) VALUES ($main_product["entity_id"],$related_product["entity_id"],1)");
}
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多帮助,只需添加评论,我会看到我能做什么;)
我希望这对你有帮助.
问候,肯尼
| 归档时间: |
|
| 查看次数: |
1629 次 |
| 最近记录: |