Apply custom discount to admin order












0















I have a client that would like to do the following when creating an Admin Sales Order (without creating a Price Rule);



Give £10 discount when ordering 4 of Product A (Unit Price: £10).



At present, it seems that the only way this can be done is by checking the Custom Price and setting the Unit Price of all 4 items to £7.50 to give the discount of £10 making a total of £30.



The ideal would be to do something like this;



Add 2 of Product A at £10
Add 2 of Product A at £5



So that the total would be £30 instead of £40. Or to have a field when creating the admin order that can simply add a fixed amount discount to the order.



The client gives different discounts and they don't want to have to keep creating a price rule every time that they wish to create an admin order with a discount.



Has anyone comes across an extension that can do this before? I've done endless searching online and have asked at some of the extension developers like Amasty, Webshopapps and Mageworx etc but they're all pretty certain that this isn't possible. But I figured I would try here too as I hate telling a client that something just can't be done within the Magento framework.










share|improve this question














bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

    – Bruno Monteiro
    Nov 15 '16 at 21:56











  • Is solved your issue?

    – user51361
    Jun 6 '17 at 8:56
















0















I have a client that would like to do the following when creating an Admin Sales Order (without creating a Price Rule);



Give £10 discount when ordering 4 of Product A (Unit Price: £10).



At present, it seems that the only way this can be done is by checking the Custom Price and setting the Unit Price of all 4 items to £7.50 to give the discount of £10 making a total of £30.



The ideal would be to do something like this;



Add 2 of Product A at £10
Add 2 of Product A at £5



So that the total would be £30 instead of £40. Or to have a field when creating the admin order that can simply add a fixed amount discount to the order.



The client gives different discounts and they don't want to have to keep creating a price rule every time that they wish to create an admin order with a discount.



Has anyone comes across an extension that can do this before? I've done endless searching online and have asked at some of the extension developers like Amasty, Webshopapps and Mageworx etc but they're all pretty certain that this isn't possible. But I figured I would try here too as I hate telling a client that something just can't be done within the Magento framework.










share|improve this question














bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

    – Bruno Monteiro
    Nov 15 '16 at 21:56











  • Is solved your issue?

    – user51361
    Jun 6 '17 at 8:56














0












0








0








I have a client that would like to do the following when creating an Admin Sales Order (without creating a Price Rule);



Give £10 discount when ordering 4 of Product A (Unit Price: £10).



At present, it seems that the only way this can be done is by checking the Custom Price and setting the Unit Price of all 4 items to £7.50 to give the discount of £10 making a total of £30.



The ideal would be to do something like this;



Add 2 of Product A at £10
Add 2 of Product A at £5



So that the total would be £30 instead of £40. Or to have a field when creating the admin order that can simply add a fixed amount discount to the order.



The client gives different discounts and they don't want to have to keep creating a price rule every time that they wish to create an admin order with a discount.



Has anyone comes across an extension that can do this before? I've done endless searching online and have asked at some of the extension developers like Amasty, Webshopapps and Mageworx etc but they're all pretty certain that this isn't possible. But I figured I would try here too as I hate telling a client that something just can't be done within the Magento framework.










share|improve this question














I have a client that would like to do the following when creating an Admin Sales Order (without creating a Price Rule);



Give £10 discount when ordering 4 of Product A (Unit Price: £10).



At present, it seems that the only way this can be done is by checking the Custom Price and setting the Unit Price of all 4 items to £7.50 to give the discount of £10 making a total of £30.



The ideal would be to do something like this;



Add 2 of Product A at £10
Add 2 of Product A at £5



So that the total would be £30 instead of £40. Or to have a field when creating the admin order that can simply add a fixed amount discount to the order.



The client gives different discounts and they don't want to have to keep creating a price rule every time that they wish to create an admin order with a discount.



Has anyone comes across an extension that can do this before? I've done endless searching online and have asked at some of the extension developers like Amasty, Webshopapps and Mageworx etc but they're all pretty certain that this isn't possible. But I figured I would try here too as I hate telling a client that something just can't be done within the Magento framework.







price shopping-cart-price-rules discount






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '16 at 16:56









doubleplusgooddoubleplusgood

88316




88316





bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

    – Bruno Monteiro
    Nov 15 '16 at 21:56











  • Is solved your issue?

    – user51361
    Jun 6 '17 at 8:56



















  • I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

    – Bruno Monteiro
    Nov 15 '16 at 21:56











  • Is solved your issue?

    – user51361
    Jun 6 '17 at 8:56

















I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

– Bruno Monteiro
Nov 15 '16 at 21:56





I had a similar problem and the only way I found was creating promo codes that just the admin would use to give that discount. It is not the best solution, I know, but was the only way I find to do that...

– Bruno Monteiro
Nov 15 '16 at 21:56













Is solved your issue?

– user51361
Jun 6 '17 at 8:56





Is solved your issue?

– user51361
Jun 6 '17 at 8:56










1 Answer
1






active

oldest

votes


















0














Steps To Apply Custom Discount while placing order from admin:



Please follow the below steps:





  1. Create sales.xml file in your custom module inside etc directory



    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
    <section name="quote">
    <group name="totals">
    <item name="customdiscount" instance="[VendorName][Namespace]ModelQuoteAddressTotalDiscount" sort_order="500"/>
    </group>
    </section>
    </config>



  2. Create discount.php in [VendorName]/[Namespace]/Model/Quote/Address/Total



    namespace [VendorName][Namespace]ModelQuoteAddressTotal;

    use MagentoCatalogModelProductRepository;

    class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
    {
    /** @var $_productRepository */
    protected $_productRepository;

    /**
    * Discount constructor.
    * @param ProductRepository $productRepository
    */
    public function __construct(
    ProductRepository $productRepository
    ) {
    $this->setCode('customdiscount');
    $this->_productRepository = $productRepository;
    }

    /**
    * Collect address discount amount
    * @param MagentoQuoteModelQuote $quote
    * @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
    * @param MagentoQuoteModelQuoteAddressTotal $total
    * @return $this
    */
    public function collect(
    MagentoQuoteModelQuote $quote,
    MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
    MagentoQuoteModelQuoteAddressTotal $total
    ) {
    $data = $quote->getItems();
    if (!count($data)) {
    return $this;
    }
    parent::collect($quote, $shippingAssignment, $total);

    /** Custom Discount is saved in line item level (i.e in quote_item) */
    foreach ($data as $item) {
    /** Add your Logic Here */
    if ($item['product_id'] == 'A' && $item['qty'] ) {
    $item->setDiscountAmount([setyourcustomdiscount]);
    $item->setBaseDiscountAmount([setyourcustomdiscount]);
    }

    }
    /** Saving the values in quote_address table */
    $total->setDiscountDescription('Custom Discount');
    $total->setDiscountAmount([setTotalDiscountAmount]);
    $total->setBaseDiscountAmount([setTotalDiscountAmount]);

    }
    Note : 1. setTotalDiscountAmount is the sum of all discount amount.
    2. setyourcustomdiscount is the discount per item in cart id applicable.
    3. sales.xml is used to add the custom discount. This is common for both frontend and admin.i.e this logic will work in frontend as well.







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%2f145911%2fapply-custom-discount-to-admin-order%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














    Steps To Apply Custom Discount while placing order from admin:



    Please follow the below steps:





    1. Create sales.xml file in your custom module inside etc directory



      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
      <section name="quote">
      <group name="totals">
      <item name="customdiscount" instance="[VendorName][Namespace]ModelQuoteAddressTotalDiscount" sort_order="500"/>
      </group>
      </section>
      </config>



    2. Create discount.php in [VendorName]/[Namespace]/Model/Quote/Address/Total



      namespace [VendorName][Namespace]ModelQuoteAddressTotal;

      use MagentoCatalogModelProductRepository;

      class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
      {
      /** @var $_productRepository */
      protected $_productRepository;

      /**
      * Discount constructor.
      * @param ProductRepository $productRepository
      */
      public function __construct(
      ProductRepository $productRepository
      ) {
      $this->setCode('customdiscount');
      $this->_productRepository = $productRepository;
      }

      /**
      * Collect address discount amount
      * @param MagentoQuoteModelQuote $quote
      * @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
      * @param MagentoQuoteModelQuoteAddressTotal $total
      * @return $this
      */
      public function collect(
      MagentoQuoteModelQuote $quote,
      MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
      MagentoQuoteModelQuoteAddressTotal $total
      ) {
      $data = $quote->getItems();
      if (!count($data)) {
      return $this;
      }
      parent::collect($quote, $shippingAssignment, $total);

      /** Custom Discount is saved in line item level (i.e in quote_item) */
      foreach ($data as $item) {
      /** Add your Logic Here */
      if ($item['product_id'] == 'A' && $item['qty'] ) {
      $item->setDiscountAmount([setyourcustomdiscount]);
      $item->setBaseDiscountAmount([setyourcustomdiscount]);
      }

      }
      /** Saving the values in quote_address table */
      $total->setDiscountDescription('Custom Discount');
      $total->setDiscountAmount([setTotalDiscountAmount]);
      $total->setBaseDiscountAmount([setTotalDiscountAmount]);

      }
      Note : 1. setTotalDiscountAmount is the sum of all discount amount.
      2. setyourcustomdiscount is the discount per item in cart id applicable.
      3. sales.xml is used to add the custom discount. This is common for both frontend and admin.i.e this logic will work in frontend as well.







    share|improve this answer






























      0














      Steps To Apply Custom Discount while placing order from admin:



      Please follow the below steps:





      1. Create sales.xml file in your custom module inside etc directory



        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
        <section name="quote">
        <group name="totals">
        <item name="customdiscount" instance="[VendorName][Namespace]ModelQuoteAddressTotalDiscount" sort_order="500"/>
        </group>
        </section>
        </config>



      2. Create discount.php in [VendorName]/[Namespace]/Model/Quote/Address/Total



        namespace [VendorName][Namespace]ModelQuoteAddressTotal;

        use MagentoCatalogModelProductRepository;

        class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
        {
        /** @var $_productRepository */
        protected $_productRepository;

        /**
        * Discount constructor.
        * @param ProductRepository $productRepository
        */
        public function __construct(
        ProductRepository $productRepository
        ) {
        $this->setCode('customdiscount');
        $this->_productRepository = $productRepository;
        }

        /**
        * Collect address discount amount
        * @param MagentoQuoteModelQuote $quote
        * @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
        * @param MagentoQuoteModelQuoteAddressTotal $total
        * @return $this
        */
        public function collect(
        MagentoQuoteModelQuote $quote,
        MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
        MagentoQuoteModelQuoteAddressTotal $total
        ) {
        $data = $quote->getItems();
        if (!count($data)) {
        return $this;
        }
        parent::collect($quote, $shippingAssignment, $total);

        /** Custom Discount is saved in line item level (i.e in quote_item) */
        foreach ($data as $item) {
        /** Add your Logic Here */
        if ($item['product_id'] == 'A' && $item['qty'] ) {
        $item->setDiscountAmount([setyourcustomdiscount]);
        $item->setBaseDiscountAmount([setyourcustomdiscount]);
        }

        }
        /** Saving the values in quote_address table */
        $total->setDiscountDescription('Custom Discount');
        $total->setDiscountAmount([setTotalDiscountAmount]);
        $total->setBaseDiscountAmount([setTotalDiscountAmount]);

        }
        Note : 1. setTotalDiscountAmount is the sum of all discount amount.
        2. setyourcustomdiscount is the discount per item in cart id applicable.
        3. sales.xml is used to add the custom discount. This is common for both frontend and admin.i.e this logic will work in frontend as well.







      share|improve this answer




























        0












        0








        0







        Steps To Apply Custom Discount while placing order from admin:



        Please follow the below steps:





        1. Create sales.xml file in your custom module inside etc directory



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
          <section name="quote">
          <group name="totals">
          <item name="customdiscount" instance="[VendorName][Namespace]ModelQuoteAddressTotalDiscount" sort_order="500"/>
          </group>
          </section>
          </config>



        2. Create discount.php in [VendorName]/[Namespace]/Model/Quote/Address/Total



          namespace [VendorName][Namespace]ModelQuoteAddressTotal;

          use MagentoCatalogModelProductRepository;

          class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
          {
          /** @var $_productRepository */
          protected $_productRepository;

          /**
          * Discount constructor.
          * @param ProductRepository $productRepository
          */
          public function __construct(
          ProductRepository $productRepository
          ) {
          $this->setCode('customdiscount');
          $this->_productRepository = $productRepository;
          }

          /**
          * Collect address discount amount
          * @param MagentoQuoteModelQuote $quote
          * @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
          * @param MagentoQuoteModelQuoteAddressTotal $total
          * @return $this
          */
          public function collect(
          MagentoQuoteModelQuote $quote,
          MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
          MagentoQuoteModelQuoteAddressTotal $total
          ) {
          $data = $quote->getItems();
          if (!count($data)) {
          return $this;
          }
          parent::collect($quote, $shippingAssignment, $total);

          /** Custom Discount is saved in line item level (i.e in quote_item) */
          foreach ($data as $item) {
          /** Add your Logic Here */
          if ($item['product_id'] == 'A' && $item['qty'] ) {
          $item->setDiscountAmount([setyourcustomdiscount]);
          $item->setBaseDiscountAmount([setyourcustomdiscount]);
          }

          }
          /** Saving the values in quote_address table */
          $total->setDiscountDescription('Custom Discount');
          $total->setDiscountAmount([setTotalDiscountAmount]);
          $total->setBaseDiscountAmount([setTotalDiscountAmount]);

          }
          Note : 1. setTotalDiscountAmount is the sum of all discount amount.
          2. setyourcustomdiscount is the discount per item in cart id applicable.
          3. sales.xml is used to add the custom discount. This is common for both frontend and admin.i.e this logic will work in frontend as well.







        share|improve this answer















        Steps To Apply Custom Discount while placing order from admin:



        Please follow the below steps:





        1. Create sales.xml file in your custom module inside etc directory



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
          <section name="quote">
          <group name="totals">
          <item name="customdiscount" instance="[VendorName][Namespace]ModelQuoteAddressTotalDiscount" sort_order="500"/>
          </group>
          </section>
          </config>



        2. Create discount.php in [VendorName]/[Namespace]/Model/Quote/Address/Total



          namespace [VendorName][Namespace]ModelQuoteAddressTotal;

          use MagentoCatalogModelProductRepository;

          class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
          {
          /** @var $_productRepository */
          protected $_productRepository;

          /**
          * Discount constructor.
          * @param ProductRepository $productRepository
          */
          public function __construct(
          ProductRepository $productRepository
          ) {
          $this->setCode('customdiscount');
          $this->_productRepository = $productRepository;
          }

          /**
          * Collect address discount amount
          * @param MagentoQuoteModelQuote $quote
          * @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
          * @param MagentoQuoteModelQuoteAddressTotal $total
          * @return $this
          */
          public function collect(
          MagentoQuoteModelQuote $quote,
          MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
          MagentoQuoteModelQuoteAddressTotal $total
          ) {
          $data = $quote->getItems();
          if (!count($data)) {
          return $this;
          }
          parent::collect($quote, $shippingAssignment, $total);

          /** Custom Discount is saved in line item level (i.e in quote_item) */
          foreach ($data as $item) {
          /** Add your Logic Here */
          if ($item['product_id'] == 'A' && $item['qty'] ) {
          $item->setDiscountAmount([setyourcustomdiscount]);
          $item->setBaseDiscountAmount([setyourcustomdiscount]);
          }

          }
          /** Saving the values in quote_address table */
          $total->setDiscountDescription('Custom Discount');
          $total->setDiscountAmount([setTotalDiscountAmount]);
          $total->setBaseDiscountAmount([setTotalDiscountAmount]);

          }
          Note : 1. setTotalDiscountAmount is the sum of all discount amount.
          2. setyourcustomdiscount is the discount per item in cart id applicable.
          3. sales.xml is used to add the custom discount. This is common for both frontend and admin.i.e this logic will work in frontend as well.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 11 '18 at 13:26









        7ochem

        5,79293768




        5,79293768










        answered Jul 11 '18 at 12:46









        Renu MishraRenu Mishra

        214




        214






























            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%2f145911%2fapply-custom-discount-to-admin-order%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

            Alcázar de San Juan

            Griza ansero

            Heinkel He 51