0

I am new to magento, I have created the Module which is Auto Replenish. Here admin can schedule orders based on user conviviality like Daily,Weekly,Monthly or Yearly. For this I have written the code and showing the design on admin panel perfect. Here I have little bit of doubt to struck, how to validate (ex:1 if I select Daily disable date, 2 If I select Weekly Enable week days ...etc..) and how to create crontab event for this. Is this Idea is correct or wrong Any Idea ?.

my code is: magento\app\code\local\Easylife\Autoreplenish\Block\Adminhtml\Autoreplenish\Edit\Tab\Form.php

<?php
class Easylife_Autoreplenish_Block_Adminhtml_Autoreplenish_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{

    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);

        $fieldset = $form->addFieldset('autoreplenish_form',
            array('legend'=>'Auto Replenish Information'));

        $fieldset->addField('customer_name', 'text',
            array(
                'label' => 'Customer Name',
                'class' => 'required-entry',
                'required' => true,
                'name' => 'customer_name',
            ));
        $fieldset->addField('customer_email', 'text',
            array(
                'label' => 'Customer Email',
                'class' => 'required-entry',
                'required' => true,
                'name' => 'customer_email',
            ));
        $fieldset->addField('mobile_number', 'text',
            array(
                'label' => 'Phone Number',
                'class' => 'required-entry',
                'required' => true,
                'name' => 'mobile_number',
            ));
$fieldset->addField('sku', 'text',
            array(
                'label' => 'Item SKU',
                'class' => 'required-entry',
                'required' => true,
                'name' => 'sku',
            ));

        $fieldset->addField('select', 'select', array(
            'label' => Mage::helper('autoreplenish')->__('Frequency'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'title',
            'onclick' => "",
            'onchange' => "",
            'values' => array('-1'=>'Please Select..','1' => 'Daily','2' => 'Weekly', '3' => 'Monthly', '4' => 'Yearly'),
            'disabled' => false,
            'readonly' => false,
            'after_element_html' => 'Select Frequency',
            'tabindex' => 1
        ));


        $fieldset->addField('date', 'date', array(
            'label' => Mage::helper('autoreplenish')->__('Date'),
            'after_element_html' => 'Date',
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)
        ));

        $fieldset->addField('time', 'time', array(
            'label' => Mage::helper('autoreplenish')->__('Time'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'time',
            'onclick' => "",
            'onchange' => "",
            'disabled' => false,
            'readonly' => false,
            'after_element_html' => 'Time',
            'tabindex' => 1
        ));

        $fieldset->addField('select2', 'select', array(
            'label' => Mage::helper('autoreplenish')->__('Active'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'title',
            'onclick' => "",
            'onchange' => "",
            'values' => array('-1'=>'Please Select..','1' => 'Yes','2' => 'No'),
            'disabled' => false,
            'readonly' => false,
            'tabindex' => 1
        ));


        if ( Mage::registry('autoreplenish_data') )
        {
            $form->setValues(Mage::registry('autoreplenish_data')->getData());
        }
        return parent::_prepareForm();
    }
}

magento\app\code\local\Easylife\Autoreplenish\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Autoreplenish>
            <version>0.0.1</version>
        </Easylife_Autoreplenish>
    </modules>

    <frontend>
        <routers>
            <!--<autoreplenish>
                <use>standard</use>
                <args>
                    <module>Easylife_Autoreplenish</module>
                    <frontName>autoreplenish</frontName>
                </args>
            </autoreplenish>-->
            <customer>
                <args>
                    <modules>
                        <autoreplenish before="Mage_Customer">Easylife_Autoreplenish_Customer</autoreplenish>
                    </modules>
                </args>
            </customer>
        </routers>
        <layout>
            <updates>
                <autoreplenish>
                    <file>autoreplenish.xml</file>
                </autoreplenish>
            </updates>
        </layout>
    </frontend>

    <admin>

        <routers>
            <autoreplenish>
                <use>admin</use>
                <args>
                    <module>Easylife_Autoreplenish</module>
                    <frontName>autoreplenish</frontName>
                </args>
            </autoreplenish>
        </routers>
    </admin>

    <global>
        <models>
            <autoreplenish>
                <class>Easylife_Autoreplenish_Model</class>
                <resourceModel>autoreplenish_resource</resourceModel>
            </autoreplenish>
            <autoreplenish_resource>
                <class>Easylife_Autoreplenish_Model_Resource</class>
                <entities>
                    <autoreplenish>
                        <table>autoreplenish</table>
                    </autoreplenish>
                </entities>
            </autoreplenish_resource>
        </models>
        <resources>
            <autoreplenish_setup>
                <setup>
                    <module>Easylife_Autoreplenish</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </autoreplenish_setup>
            <autoreplenish_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </autoreplenish_read>
            <autoreplenish_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </autoreplenish_write>
        </resources>
        <blocks>
            <autoreplenish>
                <class>Easylife_Autoreplenish_Block</class>
            </autoreplenish>
            <autoreplenish_admin>
                <class>Easylife_Autoreplenish_Block_Adminhtml</class>
            </autoreplenish_admin>
        </blocks>
        <helpers>
            <autoreplenish>
                <class>Easylife_Autoreplenish_Helper</class>
            </autoreplenish>
        </helpers>
    </global>

    <adminhtml>
        <menu>
            <autoreplenish translate="title" module="autoreplenish">
                <title>Auto Replenish</title>
                <sort_order>1</sort_order>
                <children>
                    <development translate="title" module="autoreplenish">
                        <title>Auto Replenish Settings</title>
                        <action>autoreplenish/adminhtml_index</action>
                        <sort_order>100</sort_order>
                    </development>
                </children>
            </autoreplenish>
        </menu>
        <acl>
            <resources>
                <admin>
                    <children>
                        <autoreplenish translate="title" module="autoreplenish">
                            <title>Auto Replenish</title>
                            <sort_order>0</sort_order>
                            <children>
                                <development translate="title" module="autoreplenish">
                                    <title>Auto Replenish Settings</title>
                                    <sort_order>100</sort_order>
                                </development>
                            </children>
                        </autoreplenish>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <autoreplenish>
                    <file>autoreplenish.xml</file>
                </autoreplenish>
            </updates>
        </layout>
    </adminhtml>

</config>

Waiting for Expert's Idea?

Thanks in advance.

1 Answer 1

1

These are two questions, therefore I recommend to open two questions.

hide/show selects based on input

You can add a layout.xml file to your module in adminhtml, then add a JS file and implement the hiding and showing.

Crontab

What is your exact problem? There are plenty of good tutorials out there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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