Jump to content

Multi Store - How to turn on "sharing quantities" without resetting qty


Recommended Posts

I'm trying to change my running shop with plenty of products with stock quantities to multistore.

I wonder is there a way to change option: "share available quantities" in existing default group to yes without resetting quantities to 0?

Has someone accomplished this in a reasonable way?

Link to comment
Share on other sites

  • 4 weeks later...
I found the solution. 

And it also prevents to issue: "You already have the maximum quantity available for this product." when multistore is ON , "allow order when out of stock" is ON (there are dozens topics with this issue without answer :P)

I've changed that stupid reset function in classes/stock/StockAvailable.php to:

 

public static function resetProductFromStockAvailableByShopGroup(ShopGroup $shop_group)

{

 

                             if ($shop_group->share_stock) 

                             {

$shop_list = Shop::getShops(false, $shop_group->id, true);

if (count($shop_list) > 0) {

$id_shops_list = implode(', ', $shop_list);

return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available SET id_shop=0,id_shop_group=1 WHERE id_shop_group=0');

} } else {

return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available SET id_shop=0,id_shop_group=1 WHERE id_shop_group=0');

}

}

 

it's working with PS 1.6

  • Like 3
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 3 weeks later...

Hi,

 

thanks for the solution. Can I ask a question about it? Here's my issue:

 

1. I had a working shop (Shop A) and a few months ago I hired a developer to set up a multishop (to create Shop B )

2. I thought that Shop A stock quantities automatically apply to Shop B as well. I just found out that its not true.

3. Now I have different quantites in Shop A and Shop B.

4. Right now Shop A has the correct quantities. If I apply this code, is it possible to make sure that Shop B will get the quantities of Shop A?

 

Thanks!

 

PS. Advanced Stock Management has been disabled for the whole time.

Edited by hannes01 (see edit history)
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

I can not add products to the cart after sharing quantities in 1.615

 

I want to enable quantity sharing with this hack not to loose quantities, but I'm afraid that it will create other problems.

 

Have you found a solution?

Link to comment
Share on other sites

If anyone just wants additional domain (stores) that  share 'everything' but has configuration for localization of stand alone shop, check this module out.

https://www.prestashop.com/forums/topic/530535-module-international-seo-multishop-pro/

 

I ran into many issues with multitshop,  but not with native so much but in non-compliant themes/modules, this partly due to PS not have a  'multishop' compliant feature on addon's.  I still think native ps multitshop is very good when used correctly to duplicated same content across domains...but myself and clients wanted another solution, this was first written for 1.4. but back by popular demand.  

Link to comment
Share on other sites

  • 4 months later...

 

I found the solution. 
And it also prevents to issue: "You already have the maximum quantity available for this product." when multistore is ON , "allow order when out of stock" is ON (there are dozens topics with this issue without answer :P)
I've changed that stupid reset function in classes/stock/StockAvailable.php to:
 
public static function resetProductFromStockAvailableByShopGroup(ShopGroup $shop_group)
{
 
                             if ($shop_group->share_stock) 
                             {
$shop_list = Shop::getShops(false, $shop_group->id, true);
if (count($shop_list) > 0) {
$id_shops_list = implode(', ', $shop_list);
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available SET id_shop=0,id_shop_group=1 WHERE id_shop_group=0');
} } else {
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available SET id_shop=0,id_shop_group=1 WHERE id_shop_group=0');
}
}
 
it's working with PS 1.6

 

 

I'm really interested in that hack!

It's just what I was looking for.

But trying to figure out the function you wrote, i guess I have to fit the id_shop and the id_shop_group variables...

And moreover, I don't get the point of that "if" condition, since you return the the same whatever...

Can you (or whoever) please clarify that point?

I'd be really thankful for any infos to fix that stupid reset function built by Presta !

  • Like 1
Link to comment
Share on other sites

Sooo, me again...

 

I found that:

http://blog.irrelevant.com/2013/08/prestashop-switching-to-shared-stock.html

 

Is it really that simple??

 

I mean, when I code something, there is always a purpose behind a function, otherwise I wouldn't spend time on it. And I'm not a pro-team of international coders like Prestashop has. But I really don't get the point of that reset function if it is that simple to switch from shared to not shared.

 

I guess undoing would be more problematic, though IMHO a simple droplist for the choice of who's keeping the children or do we share them half/half wouldn't be that hard to implement... But as said, I'm more of a designer with coding abilities than a presta core developer.

 

Anyway, before I commit, I'd like to hear of any problem I might run in doing it.

 

Thanks in advance!

Link to comment
Share on other sites

Another solution for multiple groups of shops would be to modify hatak's hack, to get a function like so:

	public static function resetProductFromStockAvailableByShopGroup(ShopGroup $shop_group)
	{
		if ($shop_group->share_stock)
		{
			$shop_list = Shop::getShops(false, $shop_group->id, true);

			if (count($shop_list) > 0)
			{
				$id_shops_list = implode(', ', $shop_list);

				return Db::getInstance()->execute('
					UPDATE  '._DB_PREFIX_.'stock_available
					SET id_shop=0, id_shop_group='.$shop_group->id.' 
                                        WHERE id_shop IN ('.$id_shops_list.')'
				);
			}
		}
		else
		{
			return Db::getInstance()->execute('
				DELETE FROM '._DB_PREFIX_.'stock_available
				WHERE id_shop_group = '.$shop_group->id
			);
		}
	}

I didn't test it yet, but theoretically, it should work without having to do any sql request, and moreover it should take in count the shops and groups of shops we are actually concerned about (for those who have several groups).

Link to comment
Share on other sites

  • 2 months later...

Well I came up with another solution.

 

You are making all the changes in the database. 

 

3 to 4 queries are needed.

 

First of you change the value in ps_shop_group from 0 to 1 in share_stock column.

 

Then you run the following simple queries. 

UPDATE ps_stock_available SET id_shop_group = 1; #assuming your id_shop_group is 1
DELETE ps_stock_available WHERE id_shop = 2; #my default shop is id 1 and i want the quantities from shop 1
UPDATE ps_stock_available SET id_shop = 0; #thats the final trick!

I have not tested this very far but so far I did not face any issues. 

 

  • Back Up you database always
  • Eneble maintenace mode before changes
  • Re back up database :) just to be sure

 

HINT: After you issue the last query go to your dumb sql file and retrieve all the insert queries for ps_stock_available and run them in your DB. If you do that you will be able to return to these values if you disable share stock option in multistore. Furtheremore I strongly believe that these values are needed. 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

Well I came up with another solution.

 

You are making all the changes in the database. 

 

3 to 4 queries are needed.

 

First of you change the value in ps_shop_group from 0 to 1 in share_stock column.

 

Then you run the following simple queries. 

UPDATE ps_stock_available SET id_shop_group = 1; #assuming your id_shop_group is 1
DELETE ps_stock_available WHERE id_shop = 2; #my default shop is id 1 and i want the quantities from shop 1
UPDATE ps_stock_available SET id_shop = 0; #thats the final trick!

I have not tested this very far but so far I did not face any issues. 

 

  • Back Up you database always
  • Eneble maintenace mode before changes
  • Re back up database :) just to be sure

 

HINT: After you issue the last query go to your dumb sql file and retrieve all the insert queries for ps_stock_available and run them in your DB. If you do that you will be able to return to these values if you disable share stock option in multistore. Furtheremore I strongly believe that these values are needed. 

 

 

Thanks! it works :)

Link to comment
Share on other sites

  • 3 months later...

Well I came up with another solution.

 

You are making all the changes in the database. 

 

3 to 4 queries are needed.

 

First of you change the value in ps_shop_group from 0 to 1 in share_stock column.

 

Then you run the following simple queries. 

UPDATE ps_stock_available SET id_shop_group = 1; #assuming your id_shop_group is 1
DELETE ps_stock_available WHERE id_shop = 2; #my default shop is id 1 and i want the quantities from shop 1
UPDATE ps_stock_available SET id_shop = 0; #thats the final trick!

I have not tested this very far but so far I did not face any issues. 

 

  • Back Up you database always
  • Eneble maintenace mode before changes
  • Re back up database :) just to be sure

 

HINT: After you issue the last query go to your dumb sql file and retrieve all the insert queries for ps_stock_available and run them in your DB. If you do that you will be able to return to these values if you disable share stock option in multistore. Furtheremore I strongly believe that these values are needed. 

 

Thanks for this solution. It has been driving me crazy that stock is not working when you make a multistore in an existing shop.

 

However, you are missing something in query #2. It should be:

DELETE FROM ps_stock_available WHERE id_shop = 2;

without FROM the syntax is invalid.

  • Like 2
Link to comment
Share on other sites

  • 1 year later...
On 20/1/2017 at 11:10 AM, 01generator said:

Well I came up with another solution.

 

You are making all the changes in the database. 

 

3 to 4 queries are needed.

 

First of you change the value in ps_shop_group from 0 to 1 in share_stock column.

 

Then you run the following simple queries. 


UPDATE ps_stock_available SET id_shop_group = 1; #assuming your id_shop_group is 1
DELETE ps_stock_available WHERE id_shop = 2; #my default shop is id 1 and i want the quantities from shop 1
UPDATE ps_stock_available SET id_shop = 0; #thats the final trick!

I have not tested this very far but so far I did not face any issues. 

 

  • Back Up you database always
  • Eneble maintenace mode before changes
  • Re back up database :) just to be sure

 

HINT: After you issue the last query go to your dumb sql file and retrieve all the insert queries for ps_stock_available and run them in your DB. If you do that you will be able to return to these values if you disable share stock option in multistore. Furtheremore I strongly believe that these values are needed. 

Works perfect with prestashop 1.7.4.2

Link to comment
Share on other sites

  • 2 months later...

Hello i have Prestashop 1.7.4.3

I started with Two Shop groups but no working after thinking i decide work only whit One Group, i make some changes on the DB:

  1. Delete the group_shop (In this case) 2
    shop_group.JPG.17f50e5e266e07de61bf3edaed598d64.JPG
  2. Put all shops on the default group, on group 1
    shop.JPG.318fa9e59a55609024d01e8bd7b40ac8.JPG
  3. Go to stock_available and set the column id_chop all in 0 (teke care that you no have repeat product with different id_shop)
    image.thumb.png.33dd01847f7fdc38acde2652061e63dd.png

Really i don't know why (if some one can explain) but work for me.

Regards

Edited by hardstonepaul (see edit history)
Link to comment
Share on other sites

  • 3 months later...

Dear all

I am suffering the same issue, and these solution does not works for me with the PS 1.7.5.

After define the DDBB values from the table, the stock of main web is removed. I checked several times but I can not do it with the properly way.

I have a default grup with the option Do Not Share Quantites(Share quantities disabled) defined. From this group, there are 5 stores, but I only want the main store(main.com/admin..) that contains the stock properly imported from a migration. Then, the rest 4 stores can be removed, but I can not do it on Backoffice because these stores contains orders imported.

Then, I would like to remove the four stores mantaining the main with the good stock, and then, change the Grup option in order to be able to share quantities into the store group, and create the rest of stores later sharing stocks.

 

Can you help me?

Thank you in advance.

Joan

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...