0

Hi guys i have a scenario where the customer gets one month free delivery on all orders which i can move him to a customer group with rules.

how to switch the customer back to general customer group automatically after the one month or two month etc.

5
  • have you manged flag to customer move general group to a customer group with rules.? – Abdul Nov 9 '15 at 9:41
  • I can manually move the customer to a group. But i need the customer back to general group after a period of time automatically. say one mont or two month. – nafiz ahmed Nov 9 '15 at 9:42
  • but how to identified to move particular customer in general group one month or two month. – Abdul Nov 9 '15 at 9:45
  • identified created date or updated date? – Abdul Nov 9 '15 at 9:46
  • your customer A is moved to group named free delivery on 9-11-2015 is right. But have you log customer moved in database table? – Abdul Nov 9 '15 at 10:31
1

Easiest way to do this is with a cronjob. You'll need to write your own module and define a cron in there

config.xml

<config>
    <modules>
        <[Namespace]_[Module]>
            <version>1.0.0</version>
        </[Namespace]_[Module]>
    </modules>
    <global>
        <models>
            <[namespace]_[module]>
                <class>[Namespace]_[Module]_Model</class>
            </[namespace]_[module]>                         
        </models>
    </global>
    <crontab>
        <jobs>
            <[namespace]_[module]_switchgroup>
                <schedule><cron_expr>* * */1 * *</cron_expr></schedule>
                <run><model>[namespace]_[module]/cron::setGroup</model></run>
            </[namespace]_[module]_switchgroup>
        </jobs>
    </crontab>
</config>

[Namespace]/[Module]/Model/Cron.php

class [Namespace]_[Module]_Model_Cron
{
    public function setGroup() 
    {
        $collection = Mage::getModel('customer/customer')->getCollection()
            ->addAttributeToFilter('created_at', array('lteq' => date('Y-m-d', strtotime('-1 month'))))
            ->addAttributeToFilter('group_id', [old group id]);

        foreach ($collection as $_customer) {
            $_customer->setGroupId([the updated id]);
            $_customer->save();
        }
    }
}

might need some tweaking here and there but it basically looks for all 1 month old customers with a customer group ID once per day and updates them to the new group

4
  • Hi sander, thank your for your efforts to write up the whole code. I was looking to keep a customer in a group for certain time from the date of moving him to the group. example:( customer A is moved to group named free delivery on 9-11-2015 i want him back into general group on 9-12-105 or any specific date. – nafiz ahmed Nov 9 '15 at 10:14
  • That's basically what above code does. It fetches customers created a month ago and switches them to, for example, a general group – Sander Mangel Nov 9 '15 at 10:42
  • thats perfect. How do i do it more specific like for each customer.? some might be two months, some can be 15 days. totally a dynamic date :) – nafiz ahmed Nov 9 '15 at 10:59
  • You would probably need to set an attribute or something that defines the period they're allowed have free shipping. Or use an observer to see if that attributes exists but something like that would go way beyond the scope of this question – Sander Mangel Nov 9 '15 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.