3

困っています。私がやりたいのは、誰かが私たちのニュースレターを購読するたびに、Magentoで1つのランダムなクーポンコードを自動的に生成することです。クーポンは何でも10ドルオフで、経験値があります。サブスクリプションから2週間後の日付。

だから、私は「ニュースレターを購読する」フォームが送信されたときにトリップする簡単なスクリプトを書こうとしています。このスクリプトは、Magentoと通信し、Magentoに単一のランダムクーポンコードを要求し、いくつかの基本的な価格ルールを設定します(10ドルオフ) 、顧客ごとに1回使用、クーポンごとに1回使用、生成から2週間で有効期限が切れます)、次に、渡される変数に格納できるランダムなクーポンコード(例:WELCOME5​​798)を返します。 -MailChimpAPIを介してMailChimpにメールを送信します。MageにPHPスクリプトを介してそのようなコードを生成させ、そのコードを返す方法を除いて、私はこれをすべて理解しました(つまり、フォームがあり、MailChimpに値を渡す方法を知っています)。

私はMagentoを初めて使用するので、大変な時間を過ごしています。Mage / SalesRule / Model / Couponのコードを見たことがあります。また、次のような、似たような質問を解決する人々の例もいくつか見ました。Magento-コードを使用して一意のクーポンコードを作成し、顧客にメールで送信する

しかし、私は自分の目的のためにこの作品をどこから始めればよいのか本当に途方に暮れています。いくつかのヘルプ/設定をまっすぐに使用できます。:(皆さんありがとう。

4

1 に答える 1

3

それで、あなたの質問は何ですか?要件に合ったクーポンを生成する方法は? または、モジュールに配置する方法は?

イベントnewsletter_subscriber_save_afterを使用して、カスタムアクションを購読プロセスに挿入できます。

ニーズに合わせたクーポン作成例はこちら

<?php
/**
 * Create coupon for fixed price discount
 *
 * @param int $customer_id
 * @param float $discount
 */
public function createCoupon($customer_id, $discount)
{
    $customer = Mage::getModel('customer/customer')->load($customer_id);

    $customerGroupIds = Mage::getModel('customer/group')->getCollection()->getAllIds();
    $websitesId = Mage::getModel('core/website')->getCollection()->getAllIds();

    $customer_name = $customer->getName();
    $couponCode = Mage::helper('core')->getRandomString(9);

    $model = Mage::getModel('salesrule/rule');
    $model->setName('Discount for ' . $customer_name);
    $model->setDescription('Discount for ' . $customer_name);
    $model->setFromDate(date('Y-m-d'));
    $model->setToDate(date('Y-m-d', strtotime('+2 days')));
    $model->setCouponType(2);
    $model->setCouponCode($couponCode);
    $model->setUsesPerCoupon(1);
    $model->setUsesPerCustomer(1);
    $model->setCustomerGroupIds($customerGroupIds);
    $model->setIsActive(1);
    $model->setConditionsSerialized('a:6:{s:4:\"type\";s:32:\"salesrule/rule_condition_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
    $model->setActionsSerialized('a:6:{s:4:\"type\";s:40:\"salesrule/rule_condition_product_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
    $model->setStopRulesProcessing(0);
    $model->setIsAdvanced(1);
    $model->setProductIds('');
    $model->setSortOrder(1);
    $model->setSimpleAction('by_fixed');
    $model->setDiscountAmount($discount);
    $model->setDiscountStep(0);
    $model->setSimpleFreeShipping(0);
    $model->setTimesUsed(0);
    $model->setIsRss(0);
    $model->setWebsiteIds($websitesId);

    try {
        $model->save();
    } catch (Exception $e) {
        Mage::log($e->getMessage());
    }
}
于 2012-10-09T20:41:32.030 に答える