How to duplicate sales rule programmatically in Magento2 The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to create sales rule programmatically in Magento2How do I programmatically load a specified sales rule in Magento 2?Magento 2: How to override newsletter Subscriber modelReceiving object specific class which was injected in constructor by three-part extensionMagento 2.1 Create a filter in the product grid by new attributeMagento 2: Add a product to the cart programmaticallyMagento2: How to properly set actions & conditions when creating sales-rule programmatically?I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 Can't view module's front end page output?

How should I replace vector<uint8_t>::const_iterator in an API?

Windows 10: How to Lock (not sleep) laptop on lid close?

How to pronounce 1ターン?

Simulating Exploding Dice

How does ice melt when immersed in water?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

What can I do if neighbor is blocking my solar panels intentionally?

Didn't get enough time to take a Coding Test - what to do now?

Simulation of a banking system with an Account class in C++

How can I define good in a religion that claims no moral authority?

Can a novice safely splice in wire to lengthen 5V charging cable?

Problems with Ubuntu mount /tmp

What is this lever in Argentinian toilets?

Take groceries in checked luggage

Can smartphones with the same camera sensor have different image quality?

How do I add random spotting to the same face in cycles?

What is special about square numbers here?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Do working physicists consider Newtonian mechanics to be "falsified"?

When did F become S in typeography, and why?

Change bounding box of math glyphs in LuaTeX

Would an alien lifeform be able to achieve space travel if lacking in vision?

Segmentation fault output is suppressed when piping stdin into a function. Why?

What's the point in a preamp?



How to duplicate sales rule programmatically in Magento2



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to create sales rule programmatically in Magento2How do I programmatically load a specified sales rule in Magento 2?Magento 2: How to override newsletter Subscriber modelReceiving object specific class which was injected in constructor by three-part extensionMagento 2.1 Create a filter in the product grid by new attributeMagento 2: Add a product to the cart programmaticallyMagento2: How to properly set actions & conditions when creating sales-rule programmatically?I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 Can't view module's front end page output?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Im try to duplicate some salesrule exist, i can duplicate this, but i can't use setConditionsSerialized and setActionsSerialized with getCondition and getActionCondition, its dont working



 use MagentoSalesRuleModelRuleRepository;
use MagentoSalesRuleModelRuleFactory;

protected $_ruleRepostitory;

protected $_ruleFactory;

public function __construct(
RuleFactory $ruleFactory,
RuleRepository $ruleRepostitory,
)
$this->_ruleRepostitory = $ruleRepostitory;
$this->_ruleFactory = $ruleFactory;


$id = 1;
$getRule = $this->_ruleRepostitory->getById($id);
$ruleModel = $this->_ruleFactory->create();
$Default = 'ABCZXC';
$randomNumber = random_int(000, 999);
$ruleModel->setName($getRule->getName())
->setDescription($getRule->getDescription())
->setCouponType(2)
->setConditionsSerialized(json_encode($getRule->getCondition()))
->setActionsSerialized(json_encode($getRule->getActionCondition()))
->setCouponCode($random = $Default . " - " . $randomNumber)
->setFromDate($getRule->getFromDate())
->setToDate($getRule->getFromDate())
->setUsesPerCustomer($getRule->getUsesPerCustomer())
->setCustomerGroupIds($getRule->getCustomerGroupIds())
->setIsActive($getRule->getIsActive())
->setStopRulesProcessing($getRule->getStopRulesProcessing())
->setIsAdvanced($getRule->getIsAdvanced())
->setProductIds($getRule->getProductIds())
->setSortOrder($getRule->getSortOrder())
->setSimpleAction($getRule->getSimpleAction())
->setDiscountAmount($getRule->getDiscountAmount())
->setDiscountQty($getRule->getDiscountQty())
->setDiscountStep($getRule->getDiscountStep())
->setSimpleFreeShipping($getRule->getSimpleFreeShipping())
->setApplyToShipping($getRule->getApplyToShipping())
->setTimesUsed($getRule->getTimesUsed())
->setIsRss($getRule->getIsRss())
->setWebsiteIds($getRule->getWebsiteIds())
->setUsesPerCoupon($getRule->getUsesPerCoupon());
$ruleModel->save();









share|improve this question






























    1















    Im try to duplicate some salesrule exist, i can duplicate this, but i can't use setConditionsSerialized and setActionsSerialized with getCondition and getActionCondition, its dont working



     use MagentoSalesRuleModelRuleRepository;
    use MagentoSalesRuleModelRuleFactory;

    protected $_ruleRepostitory;

    protected $_ruleFactory;

    public function __construct(
    RuleFactory $ruleFactory,
    RuleRepository $ruleRepostitory,
    )
    $this->_ruleRepostitory = $ruleRepostitory;
    $this->_ruleFactory = $ruleFactory;


    $id = 1;
    $getRule = $this->_ruleRepostitory->getById($id);
    $ruleModel = $this->_ruleFactory->create();
    $Default = 'ABCZXC';
    $randomNumber = random_int(000, 999);
    $ruleModel->setName($getRule->getName())
    ->setDescription($getRule->getDescription())
    ->setCouponType(2)
    ->setConditionsSerialized(json_encode($getRule->getCondition()))
    ->setActionsSerialized(json_encode($getRule->getActionCondition()))
    ->setCouponCode($random = $Default . " - " . $randomNumber)
    ->setFromDate($getRule->getFromDate())
    ->setToDate($getRule->getFromDate())
    ->setUsesPerCustomer($getRule->getUsesPerCustomer())
    ->setCustomerGroupIds($getRule->getCustomerGroupIds())
    ->setIsActive($getRule->getIsActive())
    ->setStopRulesProcessing($getRule->getStopRulesProcessing())
    ->setIsAdvanced($getRule->getIsAdvanced())
    ->setProductIds($getRule->getProductIds())
    ->setSortOrder($getRule->getSortOrder())
    ->setSimpleAction($getRule->getSimpleAction())
    ->setDiscountAmount($getRule->getDiscountAmount())
    ->setDiscountQty($getRule->getDiscountQty())
    ->setDiscountStep($getRule->getDiscountStep())
    ->setSimpleFreeShipping($getRule->getSimpleFreeShipping())
    ->setApplyToShipping($getRule->getApplyToShipping())
    ->setTimesUsed($getRule->getTimesUsed())
    ->setIsRss($getRule->getIsRss())
    ->setWebsiteIds($getRule->getWebsiteIds())
    ->setUsesPerCoupon($getRule->getUsesPerCoupon());
    $ruleModel->save();









    share|improve this question


























      1












      1








      1








      Im try to duplicate some salesrule exist, i can duplicate this, but i can't use setConditionsSerialized and setActionsSerialized with getCondition and getActionCondition, its dont working



       use MagentoSalesRuleModelRuleRepository;
      use MagentoSalesRuleModelRuleFactory;

      protected $_ruleRepostitory;

      protected $_ruleFactory;

      public function __construct(
      RuleFactory $ruleFactory,
      RuleRepository $ruleRepostitory,
      )
      $this->_ruleRepostitory = $ruleRepostitory;
      $this->_ruleFactory = $ruleFactory;


      $id = 1;
      $getRule = $this->_ruleRepostitory->getById($id);
      $ruleModel = $this->_ruleFactory->create();
      $Default = 'ABCZXC';
      $randomNumber = random_int(000, 999);
      $ruleModel->setName($getRule->getName())
      ->setDescription($getRule->getDescription())
      ->setCouponType(2)
      ->setConditionsSerialized(json_encode($getRule->getCondition()))
      ->setActionsSerialized(json_encode($getRule->getActionCondition()))
      ->setCouponCode($random = $Default . " - " . $randomNumber)
      ->setFromDate($getRule->getFromDate())
      ->setToDate($getRule->getFromDate())
      ->setUsesPerCustomer($getRule->getUsesPerCustomer())
      ->setCustomerGroupIds($getRule->getCustomerGroupIds())
      ->setIsActive($getRule->getIsActive())
      ->setStopRulesProcessing($getRule->getStopRulesProcessing())
      ->setIsAdvanced($getRule->getIsAdvanced())
      ->setProductIds($getRule->getProductIds())
      ->setSortOrder($getRule->getSortOrder())
      ->setSimpleAction($getRule->getSimpleAction())
      ->setDiscountAmount($getRule->getDiscountAmount())
      ->setDiscountQty($getRule->getDiscountQty())
      ->setDiscountStep($getRule->getDiscountStep())
      ->setSimpleFreeShipping($getRule->getSimpleFreeShipping())
      ->setApplyToShipping($getRule->getApplyToShipping())
      ->setTimesUsed($getRule->getTimesUsed())
      ->setIsRss($getRule->getIsRss())
      ->setWebsiteIds($getRule->getWebsiteIds())
      ->setUsesPerCoupon($getRule->getUsesPerCoupon());
      $ruleModel->save();









      share|improve this question
















      Im try to duplicate some salesrule exist, i can duplicate this, but i can't use setConditionsSerialized and setActionsSerialized with getCondition and getActionCondition, its dont working



       use MagentoSalesRuleModelRuleRepository;
      use MagentoSalesRuleModelRuleFactory;

      protected $_ruleRepostitory;

      protected $_ruleFactory;

      public function __construct(
      RuleFactory $ruleFactory,
      RuleRepository $ruleRepostitory,
      )
      $this->_ruleRepostitory = $ruleRepostitory;
      $this->_ruleFactory = $ruleFactory;


      $id = 1;
      $getRule = $this->_ruleRepostitory->getById($id);
      $ruleModel = $this->_ruleFactory->create();
      $Default = 'ABCZXC';
      $randomNumber = random_int(000, 999);
      $ruleModel->setName($getRule->getName())
      ->setDescription($getRule->getDescription())
      ->setCouponType(2)
      ->setConditionsSerialized(json_encode($getRule->getCondition()))
      ->setActionsSerialized(json_encode($getRule->getActionCondition()))
      ->setCouponCode($random = $Default . " - " . $randomNumber)
      ->setFromDate($getRule->getFromDate())
      ->setToDate($getRule->getFromDate())
      ->setUsesPerCustomer($getRule->getUsesPerCustomer())
      ->setCustomerGroupIds($getRule->getCustomerGroupIds())
      ->setIsActive($getRule->getIsActive())
      ->setStopRulesProcessing($getRule->getStopRulesProcessing())
      ->setIsAdvanced($getRule->getIsAdvanced())
      ->setProductIds($getRule->getProductIds())
      ->setSortOrder($getRule->getSortOrder())
      ->setSimpleAction($getRule->getSimpleAction())
      ->setDiscountAmount($getRule->getDiscountAmount())
      ->setDiscountQty($getRule->getDiscountQty())
      ->setDiscountStep($getRule->getDiscountStep())
      ->setSimpleFreeShipping($getRule->getSimpleFreeShipping())
      ->setApplyToShipping($getRule->getApplyToShipping())
      ->setTimesUsed($getRule->getTimesUsed())
      ->setIsRss($getRule->getIsRss())
      ->setWebsiteIds($getRule->getWebsiteIds())
      ->setUsesPerCoupon($getRule->getUsesPerCoupon());
      $ruleModel->save();






      magento2 programmatically rules






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 10 at 4:50







      wightman

















      asked Apr 10 at 4:15









      wightmanwightman

      63




      63




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Yeah, I did it, this is my code for duplicate Sales Rule . Does anyone have different answer .



          use MagentoSalesRuleModelRuleFactory;

          protected $_ruleFactory;

          public function __construct(
          RuleFactory $ruleFactory
          )

          $this->_ruleFactory = $ruleFactory;
          parent::__construct($context);


          public function execute()

          $duplicateRule = $this->_ruleFactory->create();
          $ruleModel = $this->_ruleFactory->create()->load($id);
          $default = 'ABCZXC'; // random code with ABCZXC+xxx, your can Enabled Use Auto Generation if you want
          print_r($ruleModel->getData());
          $randomNumber = random_int(000, 999);
          $duplicateRule
          ->setName($ruleModel->getName())
          ->setDescription($ruleModel->getDescription())
          ->setCouponType($ruleModel->getCouponType())
          ->setConditionsSerialized($ruleModel->getConditionsSerialized())
          ->setActionsSerialized($ruleModel->getActionsSerialized())
          ->setCouponCode($random = $default . " - " . $randomNumber)
          ->setFromDate($ruleModel->getFromDate())
          ->setToDate($ruleModel->getFromDate())
          ->setUsesPerCustomer($ruleModel->getUsesPerCustomer())
          ->setCustomerGroupIds($ruleModel->getCustomerGroupIds())
          ->setIsActive($ruleModel->getIsActive())
          ->setStopRulesProcessing($ruleModel->getStopRulesProcessing())
          ->setIsAdvanced($ruleModel->getIsAdvanced())
          ->setProductIds($ruleModel->getProductIds())
          ->setSortOrder($ruleModel->getSortOrder())
          ->setSimpleAction($ruleModel->getSimpleAction())
          ->setDiscountAmount($ruleModel->getDiscountAmount())
          ->setDiscountQty($ruleModel->getDiscountQty())
          ->setDiscountStep($ruleModel->getDiscountStep())
          ->setSimpleFreeShipping($ruleModel->getSimpleFreeShipping())
          ->setUseAutoGeneration($ruleModel->getUseAutoGeneration())
          ->setApplyToShipping($ruleModel->getApplyToShipping())
          ->setTimesUsed($ruleModel->getTimesUsed())
          ->setIsRss($ruleModel->getIsRss())
          ->setWebsiteIds($ruleModel->getWebsiteIds())
          ->setUsesPerCoupon($ruleModel->getUsesPerCoupon());
          $duplicateRule->save();






          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269442%2fhow-to-duplicate-sales-rule-programmatically-in-magento2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Yeah, I did it, this is my code for duplicate Sales Rule . Does anyone have different answer .



            use MagentoSalesRuleModelRuleFactory;

            protected $_ruleFactory;

            public function __construct(
            RuleFactory $ruleFactory
            )

            $this->_ruleFactory = $ruleFactory;
            parent::__construct($context);


            public function execute()

            $duplicateRule = $this->_ruleFactory->create();
            $ruleModel = $this->_ruleFactory->create()->load($id);
            $default = 'ABCZXC'; // random code with ABCZXC+xxx, your can Enabled Use Auto Generation if you want
            print_r($ruleModel->getData());
            $randomNumber = random_int(000, 999);
            $duplicateRule
            ->setName($ruleModel->getName())
            ->setDescription($ruleModel->getDescription())
            ->setCouponType($ruleModel->getCouponType())
            ->setConditionsSerialized($ruleModel->getConditionsSerialized())
            ->setActionsSerialized($ruleModel->getActionsSerialized())
            ->setCouponCode($random = $default . " - " . $randomNumber)
            ->setFromDate($ruleModel->getFromDate())
            ->setToDate($ruleModel->getFromDate())
            ->setUsesPerCustomer($ruleModel->getUsesPerCustomer())
            ->setCustomerGroupIds($ruleModel->getCustomerGroupIds())
            ->setIsActive($ruleModel->getIsActive())
            ->setStopRulesProcessing($ruleModel->getStopRulesProcessing())
            ->setIsAdvanced($ruleModel->getIsAdvanced())
            ->setProductIds($ruleModel->getProductIds())
            ->setSortOrder($ruleModel->getSortOrder())
            ->setSimpleAction($ruleModel->getSimpleAction())
            ->setDiscountAmount($ruleModel->getDiscountAmount())
            ->setDiscountQty($ruleModel->getDiscountQty())
            ->setDiscountStep($ruleModel->getDiscountStep())
            ->setSimpleFreeShipping($ruleModel->getSimpleFreeShipping())
            ->setUseAutoGeneration($ruleModel->getUseAutoGeneration())
            ->setApplyToShipping($ruleModel->getApplyToShipping())
            ->setTimesUsed($ruleModel->getTimesUsed())
            ->setIsRss($ruleModel->getIsRss())
            ->setWebsiteIds($ruleModel->getWebsiteIds())
            ->setUsesPerCoupon($ruleModel->getUsesPerCoupon());
            $duplicateRule->save();






            share|improve this answer



























              0














              Yeah, I did it, this is my code for duplicate Sales Rule . Does anyone have different answer .



              use MagentoSalesRuleModelRuleFactory;

              protected $_ruleFactory;

              public function __construct(
              RuleFactory $ruleFactory
              )

              $this->_ruleFactory = $ruleFactory;
              parent::__construct($context);


              public function execute()

              $duplicateRule = $this->_ruleFactory->create();
              $ruleModel = $this->_ruleFactory->create()->load($id);
              $default = 'ABCZXC'; // random code with ABCZXC+xxx, your can Enabled Use Auto Generation if you want
              print_r($ruleModel->getData());
              $randomNumber = random_int(000, 999);
              $duplicateRule
              ->setName($ruleModel->getName())
              ->setDescription($ruleModel->getDescription())
              ->setCouponType($ruleModel->getCouponType())
              ->setConditionsSerialized($ruleModel->getConditionsSerialized())
              ->setActionsSerialized($ruleModel->getActionsSerialized())
              ->setCouponCode($random = $default . " - " . $randomNumber)
              ->setFromDate($ruleModel->getFromDate())
              ->setToDate($ruleModel->getFromDate())
              ->setUsesPerCustomer($ruleModel->getUsesPerCustomer())
              ->setCustomerGroupIds($ruleModel->getCustomerGroupIds())
              ->setIsActive($ruleModel->getIsActive())
              ->setStopRulesProcessing($ruleModel->getStopRulesProcessing())
              ->setIsAdvanced($ruleModel->getIsAdvanced())
              ->setProductIds($ruleModel->getProductIds())
              ->setSortOrder($ruleModel->getSortOrder())
              ->setSimpleAction($ruleModel->getSimpleAction())
              ->setDiscountAmount($ruleModel->getDiscountAmount())
              ->setDiscountQty($ruleModel->getDiscountQty())
              ->setDiscountStep($ruleModel->getDiscountStep())
              ->setSimpleFreeShipping($ruleModel->getSimpleFreeShipping())
              ->setUseAutoGeneration($ruleModel->getUseAutoGeneration())
              ->setApplyToShipping($ruleModel->getApplyToShipping())
              ->setTimesUsed($ruleModel->getTimesUsed())
              ->setIsRss($ruleModel->getIsRss())
              ->setWebsiteIds($ruleModel->getWebsiteIds())
              ->setUsesPerCoupon($ruleModel->getUsesPerCoupon());
              $duplicateRule->save();






              share|improve this answer

























                0












                0








                0







                Yeah, I did it, this is my code for duplicate Sales Rule . Does anyone have different answer .



                use MagentoSalesRuleModelRuleFactory;

                protected $_ruleFactory;

                public function __construct(
                RuleFactory $ruleFactory
                )

                $this->_ruleFactory = $ruleFactory;
                parent::__construct($context);


                public function execute()

                $duplicateRule = $this->_ruleFactory->create();
                $ruleModel = $this->_ruleFactory->create()->load($id);
                $default = 'ABCZXC'; // random code with ABCZXC+xxx, your can Enabled Use Auto Generation if you want
                print_r($ruleModel->getData());
                $randomNumber = random_int(000, 999);
                $duplicateRule
                ->setName($ruleModel->getName())
                ->setDescription($ruleModel->getDescription())
                ->setCouponType($ruleModel->getCouponType())
                ->setConditionsSerialized($ruleModel->getConditionsSerialized())
                ->setActionsSerialized($ruleModel->getActionsSerialized())
                ->setCouponCode($random = $default . " - " . $randomNumber)
                ->setFromDate($ruleModel->getFromDate())
                ->setToDate($ruleModel->getFromDate())
                ->setUsesPerCustomer($ruleModel->getUsesPerCustomer())
                ->setCustomerGroupIds($ruleModel->getCustomerGroupIds())
                ->setIsActive($ruleModel->getIsActive())
                ->setStopRulesProcessing($ruleModel->getStopRulesProcessing())
                ->setIsAdvanced($ruleModel->getIsAdvanced())
                ->setProductIds($ruleModel->getProductIds())
                ->setSortOrder($ruleModel->getSortOrder())
                ->setSimpleAction($ruleModel->getSimpleAction())
                ->setDiscountAmount($ruleModel->getDiscountAmount())
                ->setDiscountQty($ruleModel->getDiscountQty())
                ->setDiscountStep($ruleModel->getDiscountStep())
                ->setSimpleFreeShipping($ruleModel->getSimpleFreeShipping())
                ->setUseAutoGeneration($ruleModel->getUseAutoGeneration())
                ->setApplyToShipping($ruleModel->getApplyToShipping())
                ->setTimesUsed($ruleModel->getTimesUsed())
                ->setIsRss($ruleModel->getIsRss())
                ->setWebsiteIds($ruleModel->getWebsiteIds())
                ->setUsesPerCoupon($ruleModel->getUsesPerCoupon());
                $duplicateRule->save();






                share|improve this answer













                Yeah, I did it, this is my code for duplicate Sales Rule . Does anyone have different answer .



                use MagentoSalesRuleModelRuleFactory;

                protected $_ruleFactory;

                public function __construct(
                RuleFactory $ruleFactory
                )

                $this->_ruleFactory = $ruleFactory;
                parent::__construct($context);


                public function execute()

                $duplicateRule = $this->_ruleFactory->create();
                $ruleModel = $this->_ruleFactory->create()->load($id);
                $default = 'ABCZXC'; // random code with ABCZXC+xxx, your can Enabled Use Auto Generation if you want
                print_r($ruleModel->getData());
                $randomNumber = random_int(000, 999);
                $duplicateRule
                ->setName($ruleModel->getName())
                ->setDescription($ruleModel->getDescription())
                ->setCouponType($ruleModel->getCouponType())
                ->setConditionsSerialized($ruleModel->getConditionsSerialized())
                ->setActionsSerialized($ruleModel->getActionsSerialized())
                ->setCouponCode($random = $default . " - " . $randomNumber)
                ->setFromDate($ruleModel->getFromDate())
                ->setToDate($ruleModel->getFromDate())
                ->setUsesPerCustomer($ruleModel->getUsesPerCustomer())
                ->setCustomerGroupIds($ruleModel->getCustomerGroupIds())
                ->setIsActive($ruleModel->getIsActive())
                ->setStopRulesProcessing($ruleModel->getStopRulesProcessing())
                ->setIsAdvanced($ruleModel->getIsAdvanced())
                ->setProductIds($ruleModel->getProductIds())
                ->setSortOrder($ruleModel->getSortOrder())
                ->setSimpleAction($ruleModel->getSimpleAction())
                ->setDiscountAmount($ruleModel->getDiscountAmount())
                ->setDiscountQty($ruleModel->getDiscountQty())
                ->setDiscountStep($ruleModel->getDiscountStep())
                ->setSimpleFreeShipping($ruleModel->getSimpleFreeShipping())
                ->setUseAutoGeneration($ruleModel->getUseAutoGeneration())
                ->setApplyToShipping($ruleModel->getApplyToShipping())
                ->setTimesUsed($ruleModel->getTimesUsed())
                ->setIsRss($ruleModel->getIsRss())
                ->setWebsiteIds($ruleModel->getWebsiteIds())
                ->setUsesPerCoupon($ruleModel->getUsesPerCoupon());
                $duplicateRule->save();







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 10 at 10:28









                wightmanwightman

                63




                63



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269442%2fhow-to-duplicate-sales-rule-programmatically-in-magento2%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP