Unexpected getRebate() value

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

Unexpected getRebate() value

Post by sixbynine » 05 Jul 2018, 11:28

I'm trying to get the rebate value of the variant of a selection product (its value is 5.00 in mshop_price) with :

Code: Select all

$product->getPrice()->getRebate();
----
returned value : 0.00
Here's a part of the dump of my $product Object. Curiously the rebate is 0.00 (the returned value) in Aimeos\MShop\Price\Item\Standard but 5.00 (the expected value) in Aimeos\MShop\Common\Item\Base.

Is this a bug or do i miss something?

["values":"Aimeos\MShop\Price\Item\Standard":private]=> array(20) {
["price.id"]=> string(3) "213"
["price.siteid"]=> string(1) "1"
["price.typeid"]=> string(1) "3"
["price.currencyid"]=> string(3) "EUR"
["price.domain"]=> string(7) "product"
["price.label"]=> string(0) ""
["price.quantity"]=> string(1) "1"
["price.value"]=> string(4) "3.00"
["price.costs"]=> string(4) "1.00"
["price.rebate"]=> string(4) "0.00"
["price.taxrate"]=> string(4) "6.00"
["price.status"]=> string(1) "1"
["price.mtime"]=> string(19) "2018-06-27 18:40:02"
["price.editor"]=> string(22) "user"
["price.ctime"]=> string(19) "2018-05-26 00:20:50"
["price.type"]=> string(7) "default"
["price.typename"]=> string(8) "Standard"
["currencyid"]=> string(3) "EUR"
["price.taxflag"]=> int(0)
["price.tax"]=> string(6) "0.1800"
}

["bdata":"Aimeos\MShop\Common\Item\Base":private]=> array(19) {
["price.id"]=> string(3) "213"
["price.siteid"]=> string(1) "1"
["price.typeid"]=> string(1) "3"
["price.currencyid"]=> string(3) "EUR"
["price.domain"]=> string(7) "product"
["price.label"]=> string(0) ""
["price.quantity"]=> string(1) "1"
["price.value"]=> string(4) "3.00"
["price.costs"]=> string(4) "1.00"
["price.rebate"]=> string(4) "5.00"
["price.taxrate"]=> string(4) "6.00"
["price.status"]=> string(1) "1"
["price.mtime"]=> string(19) "2018-06-27 18:40:02"
["price.editor"]=> string(22) "user"
["price.ctime"]=> string(19) "2018-05-26 00:20:50"
["price.type"]=> string(7) "default"
["price.typename"]=> string(8) "Standard"
["currencyid"]=> string(3) "EUR"
["price.taxflag"]=> int(0)
}

Thank you a lot (as always)!

User avatar
aimeos
Administrator
Posts: 8194
Joined: 01 Jan 1970, 00:00

Re: Unexpected getRebate() value

Post by aimeos » 05 Jul 2018, 16:33

Is this the case after you've added the product to the basket or when does it occur?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

Re: Unexpected getRebate() value

Post by sixbynine » 05 Jul 2018, 20:42

Thank you a lot for your answer.
It happens indeed after the product is in the basket.

Ok I found this post, explaining everything !

topic847.html

Sorry for the inconvenience.

sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

Re: Unexpected getRebate() value

Post by sixbynine » 06 Jul 2018, 09:14

So, I read everything about this case.

And I used the ->getPrice()->getRawValues() to get the original rebate.

But I would also like to keep and store the original price rebate value and if I well understand, the field "rebate" in mshop_order table after the order is inserted is used to store the coupons rebate.

What is the best way to store also the original rebate (total only) in the table?
I guess I probably need to add a new field originalrebate in the mshop_order table?

Where do i need to add/write it in the checkout process?

Thank you a lot in advance!

User avatar
aimeos
Administrator
Posts: 8194
Joined: 01 Jan 1970, 00:00

Re: Unexpected getRebate() value

Post by aimeos » 09 Jul 2018, 07:35

In which places you want to show the original rebate value?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

Re: Unexpected getRebate() value

Post by sixbynine » 09 Jul 2018, 08:49

In the user account "my orders" page.

User avatar
aimeos
Administrator
Posts: 8194
Joined: 01 Jan 1970, 00:00

Re: Unexpected getRebate() value

Post by aimeos » 09 Jul 2018, 09:08

If you need it only there, the easiest option would be to write a decorator for the account history component that walks over the ordered products of an order and fetch the products with their prices to calculate the rebate amount dynamically. Disadvantage: The rebate amount changes depending on the rebate in the product.

A durable solution would be to calculate the rebate in the order base manager (fetching the products with prices) and storing the rebate amount in a new column in the mshop_order_base table. Then you have to extend the order base item to return that value.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

Re: Unexpected getRebate() value

Post by sixbynine » 10 Jul 2018, 10:35

I prefer the second option because indeed the rebate amount could change in the time. Thank you very much !

kdim95
Advanced
Posts: 213
Joined: 26 Aug 2022, 12:17

Re: Unexpected getRebate() value

Post by kdim95 » 23 Jan 2023, 12:09

Hello,

I am also facing the same problem, the original rebate value is not accessible in the basket /shop/basket.
I am looking at the mshop_order_base and planning to add an original_rebate database migration but I can't find the current order I'm making. Is the order stored in a session before its complete?

What is the correct way to get the rebate that the product was added to the cart with?
aimeos wrote: 09 Jul 2018, 09:08 If you need it only there, the easiest option would be to write a decorator for the account history component that walks over the ordered products of an order and fetch the products with their prices to calculate the rebate amount dynamically. Disadvantage: The rebate amount changes depending on the rebate in the product.

A durable solution would be to calculate the rebate in the order base manager (fetching the products with prices) and storing the rebate amount in a new column in the mshop_order_base table. Then you have to extend the order base item to return that value.

User avatar
aimeos
Administrator
Posts: 8194
Joined: 01 Jan 1970, 00:00

Re: Unexpected getRebate() value

Post by aimeos » 25 Jan 2023, 11:56

kdim95 wrote: 23 Jan 2023, 12:09 I can't find the current order I'm making. Is the order stored in a session before its complete?
Yes, it's stored in the mshop_order_basket table until the customer clicks on "Buy now" at the end of the checkout process.
kdim95 wrote: 23 Jan 2023, 12:09 What is the correct way to get the rebate that the product was added to the cart with?
1.) Create a migration file:
https://aimeos.org/docs/latest/infrastr ... ing-tables

2.) Overwrite this method in the order product item:
https://github.com/aimeos/aimeos-core/b ... #L741-L773

3.) Overwrite this method in the order product manager to use the new item:
https://github.com/aimeos/aimeos-core/b ... 1091-L1103

4.) Configure your new order product manager so it will be used:

Code: Select all

mshop/order/manager/base/product/name = '<my new manager name>'
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply