Jump to content

Sync attribute quantities


tommo3344

Recommended Posts

Hi,

 

I'm using prestashop 1.6.0.14, Is there a way to sync all of a products attribute quantities(product combination quantities)to match the quantity of the default combination?

 

We would like to be able to update the default combination only, via the back office product page and have that update all the other combinations for that product at the same time.

 

For example, we have a product which can be purchased plain for one price or can be personalised/engraved for an extra cost. Meaning that there is only one product which is itself modified before being shipped. We have multiple options for this which creates discrepancies between the physical stock number and the stock number in prestashop.

 

We've got around the front end stock quantity display issue using a plugin from presto-changeo, however updating quantities in the Back office when we get new stock is still not practical because we would have to update all combinations manually or regenerate combinations every time.

 

I've searched elsewhere on the forum for similar issues and found this:

(https://www.prestashop.com/forums/topic/354190-updating-stock-quantities-for-each-product-attributes/)

 

Which suggests it is possible to update all a products combinations quantities with one MySQL query, and I think I would need to modify this template file to integrate the query: (/admin/themes/default/template/controllers/products/quantities.tpl)

 

Specifically this section on lines 160 -168

{foreach from=$attributes item=attribute}
								<tr>
									<td class="available_quantity" id="qty_{$attribute['id_product_attribute']}">
										<span>{$available_quantity[$attribute['id_product_attribute']]}</span>
										<input type="text" name="qty_{$attribute['id_product_attribute']}" class="fixed-width-sm" value="{$available_quantity[$attribute['id_product_attribute']]|htmlentities}"/>
									</td>
									<td>{$product_designation[$attribute['id_product_attribute']]}</td>
								</tr>
							{/foreach}

Is anyone able to help and point me in the right direction on how I would do this?

 

Many thanks,

Tom

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

I have been attempting to do this using jQuery to update all of the input boxes, which does work, however the new value is not being saved to the database when I click save. Here's the code:

<!-- test -->
	<script>
	$('#singletesdef').keyup(function () { //takes the value entered via <input id="singletesdef"> below 
	    $(".tesdef").val($(this).val());   //adds it to each attribute instance <input class="tesdef">
	});
</script>
<tr>
		<td class="available_quantity" id="">
			<span></span>
			<input id="singletesdef" type="text" name="" class="fixed-width-sm" value=""/>
		</td>
		<td>test default </td>
	</tr>
<!-- /test -->

{foreach from=$attributes item=attribute}
	<tr>
		<td class="available_quantity" id="qty_{$attribute['id_product_attribute']}">
			<span>{$available_quantity[$attribute['id_product_attribute']]}</span>
			<input type="text" name="qty_{$attribute['id_product_attribute']}" class="tesdef fixed-width-sm" value="{$available_quantity[$attribute['id_product_attribute']]|htmlentities}"/>
		</td>
		<td>{$product_designation[$attribute['id_product_attribute']]}</td>
	</tr>
{/foreach}

Is there anything I can do to get these values to update when I click save?

 

Any help would be greatly appreciated.

 

Kind regards,

Tommo3344

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

I've found a solution using javascript to trigger the change method. This does what I need.


<script>
	$('#singletesdef').keyup(function () { //takes the value entered via <input id="singletesdef"> below 
	    $(".tesdef").val($(this).val()); //adds it to each attribute instance <input class="tesdef">
	    $('.available_quantity').find('input').trigger('change');
	});
</script>

I'll mark this as solved.

 

-

Tommo3344

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...