Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Discount on individual order

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-26-2019, 10:39 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default 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.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #2  
Old 11-26-2019, 01:02 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 11-28-2019, 10:49 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default 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?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #4  
Old 12-05-2019, 01:47 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default 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?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:21 AM.

   

 
X-Cart forums © 2001-2020