【问题标题】:How to Import coupon code csv in magento如何在magento中导入优惠券代码csv
【发布时间】:2014-03-31 05:16:32
【问题描述】:

我想在magento中导入优惠券代码csv

我有一个 csv,但不知道如何导入它。我用谷歌搜索了它,但没有得到任何合适的解决方案。

请建议,我如何在 magento 中导入优惠券代码 csv

【问题讨论】:

  • 你的意思是,通过 csv 添加促销购物车规则?
  • @DRAJi,是的,添加促销购物车规则。
  • 如果您的问题仍未解决,您可以查看magento 2 import coupon codes 的扩展,希望它会解决

标签: magento csv


【解决方案1】:

我之前在 Magento 2 中使用 admin 和 MySQL 完成了此操作。 您需要访问管理员和数据库,以及带有正则表达式查找和替换的文本编辑器(例如 Notepad++) 这个过程在 Magento 1 中是类似的。

  1. 在 Magento 2 Admin :: Marketing > Cart Price Rules > Add(或复制)规则上创建优惠券。设置所有规则参数并勾选“使用自动生成”。保存并继续编辑。
  2. 管理优惠券代码。根据您要导入的优惠券设置参数。生成 1 张优惠券。
  3. 在 M2 数据库表 salesrule_coupon 中查找您刚刚生成的那个 - 例如:SELECT * FROM salesrule_coupon WHERE CODE = '[replace with generated code]'
  4. 将行导出为 SQL 插入,带有标题,但没有 auto_increment 列(或仅在下面的“replace”语句中更改 rule_id(例如 1999)和 created_at 日期时间。
  5. 将优惠券粘贴到 Notepad++ 中,将其转换为插入语句。

方便的 No​​tepad++ 正则表达式:

优惠券数据示例:

1111111111
2222222222
3333333333

查找

(.*)

替换(在 Notepad++ 中,您需要使用反斜杠转义括号 - )

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\);

然后对数据库运行它并在管理屏幕中刷新规则 - 你的新优惠券将在那里。

【讨论】:

    【解决方案2】:

    虽然这篇文章有点老,但上述答案也可以通过这个来源解决。此处使用固定百分比导入 CSV。 CSV 也作为示例给出。希望这会有所帮助!

    http://www.livesyncshop.com/tutorials/how-to-import-multiple-coupons-in-magento-from-a-csv/

    is_active,coupon_code,description,discount_amount
    1,1c5e8b24,serie1 coupon,20
    1,593d90a1,serie1 coupon,20
    

    现在将这段代码粘贴到一个 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;
    }
    

    【讨论】:

      【解决方案3】:

      在 Magento 管理员中转到系统 -> 导入/导出 -> 数据流高级配置文件 单击“添加新配置文件”按钮 填充“配置文件名称”和“操作 XML”文本字段: 个人资料名称 - 写下您想要的名称 Action XML – 粘贴此模板:

      <action type="dataflow/convert_adapter_io" method="load">
          <var name="type">file</var>
          <var name="path">var/import</var>
          <var name="filename"><![CDATA[coupons_test.csv]]></var>
          <var name="format"><![CDATA[csv]]></var>
      </action>
      
      <action type="dataflow/convert_parser_csv" method="parse">
          <var name="delimiter"><![CDATA[,]]></var>
          <var name="enclose"><![CDATA["]]></var>
          <var name="fieldnames">true</var>
          <var name="store"><![CDATA[0]]></var>
          <var name="number_of_records">100</var>
          <var name="decimal_separator"><![CDATA[.]]></var>
          <var name="adapter">Extendix_CouponImport_Model_SimpleImport</var>
          <var name="method">parse</var>
      </action>

      更多详情请点击此链接

      http://ceckoslab.com/magento/free-extension-coupons-import/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-26
        • 1970-01-01
        • 2016-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-18
        相关资源
        最近更新 更多