0

I am new to magento. I am using magento 1.9 version. I want to create Shopping cart price rule module programmatically like default magento shopping cart price rule.

How to do this. What are the files used.

Is there any free extension available to do this.

  • what have you tried so far? You should show something. where did you get problem? if you want module there is couples of module you can try see here – Kul Nov 7 '16 at 11:11
0

For creating coupon code you can use the following function. I can't explain the whole functionality here but have a look to it, it will be beneficial to you

if (!Mage::getStoreConfig('abandonedcart/coupon/isactive'))
            return '';

        $model = Mage::getModel('salesrule/rule');
        $model->load(Mage::getStoreConfig('abandonedcart/coupon/roleid'));
        $massGenerator = $model->getCouponMassGenerator();
        $session = Mage::getSingleton('core/session');
        $ruleId = Mage::getStoreConfig('abandonedcart/coupon/roleid');
        if (!is_numeric($ruleId)) {
            return self::ERROR_SHOPPING_CARD_RULE_IS_MISSING;
        }
        $rule = Mage::getModel('salesrule/rule')->load($ruleId);
        if (!$rule->getId()) {
            return self::ERROR_SHOPPING_CARD_RULE_IS_MISSING;
        }

        try {
            $massGenerator->setData(array(
                'rule_id' => $ruleId,
                'qty' => 1,
                'length' => Mage::getStoreConfig('abandonedcart/coupon/length'),
                'format' => Mage::getStoreConfig('abandonedcart/coupon/format'),
                'prefix' => Mage::getStoreConfig('abandonedcart/coupon/prefix'),
                'suffix' => Mage::getStoreConfig('abandonedcart/coupon/suffix'),
                'dash' => Mage::getStoreConfig('abandonedcart/coupon/dash'),
                'uses_per_coupon' => 1,
                'uses_per_customer' => 1
            ));
            $massGenerator->generatePool();
            $latestCuopon = max($model->getCoupons());
        } catch (Mage_Core_Exception $e) {
            $session->addException($e, $this->__('There was a problem with coupon: %s', $e->getMessage()));
        } catch (Exception $e) {
            $session->addException($e, $this->__('There was a problem with coupon.'));
        }

        return $latestCuopon->getCode();

Also have a look to this too.

public function generateRule($name = null, $coupon_code = null, $discount = 0, $sku, $uses) {

        /*
         * These conditions are directly copied from the result provided by firebug post variables
         */
        $conditions = array(
            "1" => array(
                "type" => "salesrule/rule_condition_product_combine",
                "aggregator" => "all",
                "value" => "1",
                "new_child" => null
            ),
            "1--1" => array(
                "type" => "salesrule/rule_condition_product_subselect",
                "aggregator" => "all",
                "attribute" => "base_row_total",
                "operator" => ">=",
                "value" => 10,
                "new_child" => null
            ),
            "1--1--1" => array(
                "type" => "salesrule/rule_condition_product",
                "attribute" => "category_ids",
                "operator" => "!=",
                "value" => "3" //category ID to which the product should not belong to
            )
        );
        $expiryDate = date("Y-m-d", strtotime("+30 days")); //30 days
        $storeLabel = "Inaugural Discount ($coupon_code)";
        $timestamp = time();
        $data = array(
            'product_ids' => null,
            'name' => $name,
            'description' => 'New Discount offer created',
            'is_active' => 1,
            'website_ids' => array(1),
            'customer_group_ids' => array(1),
            'coupon_type' => 2,
            'coupon_code' => $coupon_code,
            'uses_per_coupon' => $uses,
            'from_date' => date("Y-m-d", $timestamp),
            'to_date' => $expiryDate,
            'sort_order' => null,
            'is_rss' => 0,
            'rule' => array(
                'conditions' => $conditions
            ),
            'simple_action' => 'cart_fixed',
            'discount_amount' => $discount,
            'apply_to_shipping' => 0,
            'store_labels' => array($storeLabel)
        );

        $couponModel = Mage::getModel('salesrule/rule');
        $validateResult = $couponModel->validateData(new Varien_Object($data));
        if ($validateResult == true) {
            if (isset($data['simple_action']) && $data['simple_action'] == 'by_percent' && isset($data['discount_amount'])) {
                $data['discount_amount'] = min(100, $data['discount_amount']);
            }
            if (isset($data['rule']['conditions'])) {
                $data['conditions'] = $data['rule']['conditions'];
            }
            if (isset($data['rule']['actions'])) {
                $data['actions'] = $data['rule']['actions'];
            }
            unset($data['rule']);
            $couponModel->loadPost($data);
            $couponModel->save();
  • thanks for your reply @Vivek. Am new to magento. I need the whole module, ie., like All Default admin panel options. Is it possible to get it? – Saravanan DS Nov 7 '16 at 11:42
  • For this you have to explore. basically you need a module which can be used to create shopping price cart rule. Right ? – Vivek Khandelwal Nov 7 '16 at 11:45
  • Yes, I need the whole default magento shopping cart price module. When i referring, i it is rendering from core > Mage > adminhtml, salesrule modules. Is there any possibilities to get all files related to shopping cart pricerule together as a module. – Saravanan DS Nov 7 '16 at 11:49

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.