Announcement

Collapse
No announcement yet.

"Internals" question about new discount features

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    "Internals" question about new discount features

    Hi folks,

    I'm currently negotiating a project for a client that sells steel plate in custom sizes. The exact price depends on the size that the customer chooses, so it's not practical to pre-calculate it and store it in the DB. A custom module will read the customer's inputs for length and width, and then alter the :price field in the BasketItem that the store creates. I have a number of other modules out there that do similar things, and I think some other free-lancers do too.

    I'm wondering how this will interact with the new discount features in v9, which seem to do things like create new BasketItems, or change the line_id values of existing ones. I want to find out if a conflict could occur, e.g. if a customer has one of these custom items in the basket, and then applies a coupon or Buy X Get Y discount.

    My specific question is: in managing discounts, will the store ever (1) alter the :price field of a BasketItem by overwriting it with a value from the Products table, or (2) create a new BasketItem from scratch, and use a price from the Products table instead of copying it from an existing BasketItem?

    Thanks --
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    #2
    Re: "Internals" question about new discount features

    The discounting system will modify the price column of existing BasketItems. It attempts to retain any difference between the Product record's price and the BasketItem price in order to be compatible with legacy discounting modules, but that's no guarantee that it will work properly with your system.

    New BasketItems are never created from scratch.

    If we were implementing the solution you describe we would probably write it as a discount module in the first place, which would ensure that it works properly with the rest of the discounting system.

    Comment


      #3
      Re: "Internals" question about new discount features

      Thanks Burch, I'll take a closer look at the discount API.
      ...
      OK, I just did that :^) .

      I see that the reference manual refers to a function named DiscountModule_Discount_Basket, but the modules in the LSK all call it DiscountModule_Discount_Items. I suppose the LSK is a more reliable source?

      For my purposes, it looks like I can use the Specific Sale Price module as a starting point, and modify it to do some math instead of just pulling the discount price from a table. In this case, the item's dimensions will be set by attributes From looking at the LSK, I gather that the BasketItems and their BasketOptions will be available to my module in the l.discount_state:items variable. Is that correct?

      Thanks again --
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Re: "Internals" question about new discount features

        DiscountModule_Discount_Basket and DiscountModule_Discount_Items are both valid functions and do different things. DiscountModule_Discount_Basket is provided for modules that want to apply a discount to the basket as a whole rather than set the pricing of specific items. You're correct, though, in that DiscountModule_Discount_Items is the function you want.

        Yes, options should be available off each item as :options. I'll caution you against directly reading or modifying fields in the discount_state variable. You should use the helper functions provided in pgr_ut.mv instead. If you base your module off the Specific Sale Price module you'll see that it calls DiscountState_Eligible_Items to get a list of the items which are assigned to the particular price group in question.

        Comment


          #5
          Re: "Internals" question about new discount features

          So the reference manual needs to be updated to include DiscountModule_Discount_Items. But I should be able to figure out what I need from the LSK, plus your sage advice ... Thanks & have a good weekend!
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Re: "Internals" question about new discount features

            Sorry for such a noob question but, looking at the new discount functionalities, is there a function from where I can get the final individual item prices after every discount has been applied? I can't seem to find that on the API.

            Comment


              #7
              Re: "Internals" question about new discount features

              If you're talking about BasketItems and/or OrderItems, the "price" column is the fully discounted price. If you're wanting the discounted price before a product is added to the basket, you should look into the DiscountState_Predict_xxx functions. There is a helpful wrapper for those functions that calculates the discounted price for an array of products in features/tui/tui_ut.mv: CommonComponentFields_Initialize_Product_Discounts _Runtime( products var, product_count )

              Comment


                #8
                Re: "Internals" question about new discount features

                Hi, I'm making progress on my custom discount module. I have a couple of follow-up questions.

                1. This module needs to adjust the weight, as well as the price, of the items in the basket. It can compute the correct weight at the same time as the price. I think that, to get the new weight into the store correctly, the module should change the weight of the item in the discount_state:items array (which is a somewhat non-standard thing to do), and also update the item weight in the BasketItems table. Is that correct?

                2. This module is not computing a "discount" in the usual sense; it's computing the actual standard price for the item. I'm writing it as a discount module to ensure compatibility with other types of discounts that the store may use. But we want this particular "discount" to always be applied. In case of any conflicts between price groups, this one should always win; and if multiple discounts are applied to an item, this one should always go first.

                I see that in MM9, price groups have a Priority setting. Can we set that to some very large number such as 999 to make sure that this discount always has priority over all others? Is there anything else we need to do to ensure that this works as intended?

                Thanks again --
                Kent Multer
                Magic Metal Productions
                http://TheMagicM.com
                * Web developer/designer
                * E-commerce and Miva
                * Author, The Official Miva Web Scripting Book -- available on-line:
                http://www.amazon.com/exec/obidos/IS...icmetalproducA

                Comment

                Working...
                X