如何在magento中导入优惠券代码csv
我想在magento中导入优惠券代码csv 我有一个csv,但不知道如何导入它。我用谷歌搜索了一下,但没有找到合适的解决方案如何在magento中导入优惠券代码csv,magento,csv,Magento,Csv,我想在magento中导入优惠券代码csv 我有一个csv,但不知道如何导入它。我用谷歌搜索了一下,但没有找到合适的解决方案 请建议我如何在magento中导入优惠券代码csv尽管这篇文章有点老,但上述答案也可以通过此来源解决。此处使用固定百分比导入CSV。CSV也是一个例子。希望这有帮助 现在将此代码粘贴到php文件中 <?php // Import coupon codes // Thanks go out to Marius Strajeru // Original URL: h
请建议我如何在magento中导入优惠券代码csv尽管这篇文章有点老,但上述答案也可以通过此来源解决。此处使用固定百分比导入CSV。CSV也是一个例子。希望这有帮助 现在将此代码粘贴到php文件中
<?php
// Import coupon codes
// Thanks go out to Marius Strajeru
// Original URL: http://marius-strajeru.blogspot.nl/2010/04/create-bulk-discount-rules.html
// modified to use fixed percentage and one time use
require 'app/Mage.php';
Mage::app();
// Import CSV from ViArt format:
$handle = fopen('all_coupons1.csv', 'r');
$cols = array_flip(fgetcsv($handle));
while($data = fgetcsv($handle))
{
if($data[$cols['is_active']] == 1)
{
echo 'Importing coupon with code: '.$data[$cols['coupon_code']].'<br />';
createCoupon(
$data[$cols['coupon_code']],
$data[$cols['description']],
'by_fixed',
$data[$cols['discount_amount']]
);
} else {
echo 'Not imported (not active): '.$data[$cols['coupon_code']].'<br />';
}
}
/**
* Import coupon
* @param $code String Coupon code
* @param $description String Description
* @param $type String by_percent, by_fixed, cart_fixed, buy_x_get_y (not implemented)
* @param $amount int The amount
* @param array $options Optional options (from, to)
*/
function createCoupon($code, $description, $type, $amount, $options = array())
{
// Create coupon:
/* @var $rule Mage_SalesRule_Model_Rule */
$rule = Mage::getModel('salesrule/rule');
// set name can be code coupon by using ($code)
$rule->setName('20procent');
$rule->setCouponCode($code);
$rule->setDescription($description);
// Default options:
if(!isset($options['from'])) { $options['from'] = date('Y-m-d'); }
$rule->setFromDate($options['from']); // From date
// To date:
if(isset($options['to'])) {
$rule->setToDate($options['to']);//if you need an expiration date
}
$rule->setUsesPerCoupon(1);//number of allowed uses for this coupon
$rule->setUsesPerCustomer(1);//number of allowed uses for this coupon for each customer
$rule->setCustomerGroupIds(getAllCustomerGroups());//if you want only certain groups replace getAllCustomerGroups() with an array of desired ids
$rule->setIsActive(1);
$rule->setStopRulesProcessing(0);//set to 1 if you want all other rules after this to not be processed
$rule->setIsRss(0);//set to 1 if you want this rule to be public in rss
$rule->setIsAdvanced(1);//have no idea what it means :)
$rule->setProductIds('');
$rule->setSortOrder(0);// order in which the rules will be applied
$rule->setSimpleAction('by_percent');
$rule->setDiscountAmount($amount);//the discount amount/percent. if SimpleAction is by_percent this value must be <= 100
$rule->setDiscountQty(0);//Maximum Qty Discount is Applied to
$rule->setDiscountStep(0);//used for buy_x_get_y; This is X
$rule->setSimpleFreeShipping(0);//set to 1 for Free shipping
$rule->setApplyToShipping(1);//set to 0 if you don't want the rule to be applied to shipping
$rule->setWebsiteIds(getAllWbsites());//if you want only certain websites replace getAllWbsites() with an array of desired ids
$labels = array();
$labels[0] = $description;
$rule->setStoreLabels($labels);
$rule->setCouponType(2);
$rule->save();
}
/**
* Get all customer groups
* @return array
*/
function getAllCustomerGroups(){
//get all customer groups
$customerGroups = Mage::getModel('customer/group')->getCollection();
$groups = array();
foreach ($customerGroups as $group){
$groups[] = $group->getId();
}
return $groups;
}
/**
* Get all websites
* @return array
*/
function getAllWbsites(){
//get all wabsites
$websites = Mage::getModel('core/website')->getCollection();
$websiteIds = array();
foreach ($websites as $website){
$websiteIds[] = $website->getId();
}
return $websiteIds;
}
在Magento管理中转到系统->导入/导出->数据流高级配置文件 单击“添加新配置文件”按钮 填充“配置文件名称”和“操作XML”文本字段: 配置文件名称–写下您想要的名称 操作XML–粘贴此模板:
文件
风险值/进口
我以前在Magento 2中只使用了admin和MySQL就做到了这一点。
您需要访问admin和数据库,以及带有regex find和replace的文本编辑器(例如Notepad++)
这一过程在Magento 1中类似
在Magento 2上创建优惠券管理::营销>购物车价格规则>添加(或复制)规则。设置所有规则参数并勾选“使用自动生成”。保存并继续编辑
管理优惠券代码。根据要导入的优惠券设置参数。生成1张优惠券
在M2数据库表salesrule_优惠券中查找您刚才生成的优惠券-例如:SELECT*FROM salesrule_优惠券,其中code='[替换为生成的代码]'
将行导出为SQL insert,带有标题,但没有自动增量列(或者只更改规则id(例如1999
),并在下面的“replace”语句中的datetime创建
将优惠券粘贴到Notepad++,将其转换为insert语句
方便的记事本++正则表达式:
优惠券数据示例:
1111111111
2222222222
3333333333
发现
替换(在记事本++中,需要用反斜杠转义括号-)
然后在数据库中运行,并在管理屏幕中刷新规则-您的新优惠券将在那里。您的意思是,通过csv添加促销购物车规则?@DRAJi,是添加促销购物车规则。
1111111111
2222222222
3333333333
(.*)
INSERT INTO `salesrule_coupon` \(`rule_id`, `code`, `usage_limit`, `usage_per_customer`, `times_used`, `expiration_date`, `is_primary`, `created_at`, `type`, `generated_by_dotmailer`\) VALUES \(1999, '$1', 1, 0, 0, NULL, NULL, '2019-09-06 05:08:48', 1, NULL\);