New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a column id_shop in product_sale #29547
base: develop
Are you sure you want to change the base?
Conversation
classes/ProductSale.php
Outdated
@@ -240,10 +240,11 @@ public static function getBestSalesLight($idLang, $pageNumber = 0, $nbProducts = | |||
*/ | |||
public static function addProductSale($productId, $qty = 1) | |||
{ | |||
$idShop = Context::getContext()->shop->id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code is only used in FO then only handling a single shop case would suffice But it maybe be also used in BO where the context can also be: All shops, and Shop groups
So those use cases should be anticipated, so you should use Shop::getContextListShopID()
with the list of affected IDs and use this in a IN
condition instead of a strict equality on one shop only.
This applies also for the read queries you modified, although be aware that when Shop::addSqlAssociation
is used this is already partially done already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will look into this. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In
getNbSales()
,Shop::addSqlAssociation
will handle the problem. - If
addProductSale()
is called, there must always be added only one line for the shop the order belongs to.Shop::getContextListShopID()
will not help, if someone is modifying an order while being in all-shop-context. We must add an argument id_shop. - For
removeProductSale()
it is the same case. getNbrSales()
is used only inProductSaleCore
and must also takeid_shop
as an argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid there are BC Breaks.
If you want to avoid it, you need to:
- add new arguments at the end of the methods
- don't make them required, get shop from the
Context::getContext()
if the shop is not provided
You are right, I didn't think about it before. I think add new arguments at the end of the methods and don't make them required will not be enough to avoid BC break. Thus, it does not seem possible to me to keep consistency AND to avoid a BC break. |
Hi @lmeyer1
I think it's possible, only when your For |
* | ||
* @return bool Indicates whether the sale was successfully added | ||
*/ | ||
public static function addProductSale($productId, $qty = 1) | ||
public static function addProductSale($productId, $qty = 1, $idShop = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jolelievre, @kpodemski
I now changed like suggested.
But for these two functions addProductSale
and removeProductSale
working in shop group
or all shop
context is hurting the statistics. In both cases, we either add or remove one sale for each shop. This is duplicating sales or removing them duplicated.
We could argue, that it would be better do nothing, if $isShop
is null, because in this case we can assess exactly the error: one sale has not be added or removed. When adding or removing on an array of shops, this array could be big, and the error introduced would be big too. (Suppose we have 20 shops, we would save 20 sales instead of 1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmeyer1, you are right. Unfortunately, I don't see any way to keep "BC Break-free" different way
We could:
- introduce a new method addProductSaleForShop
- deprecate or leave the old one
- change the use of addProductSale for addProductSaleForShop
- but still, there will be a problem with those who run addProductSale because
id_shop
will beNULL
, and we won't get any information about it in methods getting sales
Maybe we should wait for PS 9.0 and change it then?
2b1d07b
to
bc1677f
Compare
bc1677f
to
93f37a6
Compare
id_shop
to tablePREFIX_product_sale
and adapt all queriesProductSaleCore
change their signature.These queries must be run in order to test this PR: