X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Discount on individual order (https://forum.x-cart.com/showthread.php?t=77379)

Ed B. 11-26-2019 10:39 AM

Discount on individual order
 
I would like to make discounts "manually" on individual order in my module, just as one can do in the admin page for order editing. I am aware that
a correct way would be to set up "surcharges/modifiers". However, a quick look at the
xcart table structure reveals that the table xc_order_items have columns
itemNetPrice and discountedSubtotal. So, I thought it would suffice to modify these columns (and of course, the total in xc_order). However, if I change manually the
content of the table

Code:

$item -> getItemNetPrice()


doesn't reflect the change I made. But
Code:

$item ->getDiscountedSubtotal()
gives the value in the table. Is there any way to implement this idea?
When one edits the orders in admin page, one simply modifies the column "price", but I would like to leave that column unchanged.

cflsystems 11-26-2019 01:02 PM

Re: Discount on individual order
 
It is not only the order items table, discounts/surcharges are also registered in the order surcharges table.
I'd suggest you follow the XC way of working with discounts/surcharges instead of direct changes to number sin database as this may just not always work properly

Ed B. 11-28-2019 10:49 AM

Re: Discount on individual order
 
Quote:

Originally Posted by cflsystems
It is not only the order items table, discounts/surcharges are also registered in the order surcharges table.

It is precisely this kind of details that makes me finding a "shortcut" to "XC way". So,
basically I would need, besides the usual classes (Viewer, Controller, whatever is needed
to get forms), a Model class to decorate /Model/Order/Surchare.php, and a class extending Logic/Order/Modifier/Discount.php, or am I still missing something?

Quote:


I'd suggest you follow the XC way of working with discounts/surcharges instead of direct changes to number sin database as this may just not always work properly


OK, so let's forget about the netPrice column, although I wonder why it is there if it is the result of calculation. At least for one of the modules I am writing, I don't mind changing the values of "price" column in OrderItem table, which is actually done in XC's stock class. As far as I understand, there is the class /View/ItemsList/Model/OrderItem.php, which starts with
Code:

namespace XLite\View\ItemsList\Model;

/**
 * OrderItem items list
 */
class OrderItem extends \XLite\View\ItemsList\Model\Table
{
    use \XLite\View\Base\ViewListsFallbackTrait;

    /**
    * Widget param names
    */
    const PARAM_ORDER = 'order';


This widget is called from the twig file xcart/skins/admin/order/page/parts/items/items.twig as
Code:

{{ widget('\\XLite\\View\\ItemsList\\Model\\OrderItem', order=this.order) }}

So the twig files call the widget with 'order' as parameter. However, I can't figure out from which view class the twig gets the value of this.order. So I can't figure out how to pass this parameter to the twig.



For example, if I try to feed the "value" of "order" by doing something like
/View/Page/Admin/Demo.php
Code:

    protected function getDefaultTemplate()
    {
        return 'modules/order/page/parts/items/items.twig';
    }


    protected function getOrder()
    {
          $id=1;
        $order = \XLite\Core\Database::getRepo('XLite\Model\Order')->find($id);
        return $order;
    }


it leads to an internal error, instead of showing a widget to edit the order with

order_id=1. Any idea on what I am doing wrong here?

Ed B. 12-05-2019 01:47 AM

Re: Discount on individual order
 
Quote:

Originally Posted by Ed B.
It is precisely this kind of details that makes me finding a "shortcut" to "XC way". So,
basically I would need, besides the usual classes (Viewer, Controller, whatever is needed
to get forms), a Model class to decorate /Model/Order/Surcharge.php, and a class extending Logic/Order/Modifier/Discount.php, or am I still missing something?


I certainly was missing Model/OrderItem/Surcharge.php class! But how do I use this? I haven't found a single example.







Quote:

Originally Posted by Ed B.
OK, so let's forget about the netPrice column, although I wonder why it is there if it is the result of calculation. At least for one of the modules I am writing, I don't mind changing the values of "price" column in OrderItem table, which is actually done in XC's stock class.





I realized that in XC5.3, orders couldn't be edited on admin order detail page (admin.php?target=order&order_number=..." whereas in XC5.4 they can. So there must be something new in XC5.4. However, I compared the codes of the classes

Model/OrderItem.php, View/ItemsList/OrderItem.php Controller/Admin/Order.php in two versions to find out why orders are editable in XC5.4 and not in XC5.3. However, I don't really see anything. Does anyone know where the difference comes from?


All times are GMT -8. The time now is 05:40 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.