VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: Alexikakos on January 30, 2019, 12:48:25 PM

Title: Save virtuemart_product_id in product_sku field
Post by: Alexikakos on January 30, 2019, 12:48:25 PM
Hi,
Is any way to save virtuemart_product_id of a product in product_sku field, in same time?

I tried to find where sql query "INSERT" is, but i finded Nothing!

Any idea?
Title: Re: Save virtuemart_product_id in product_sku field
Post by: GJC Web Design on January 30, 2019, 17:08:57 PM
There is no insert for the pid as it is just the cumulative next increment id....

I would build an onsave triggered plugin that copies the pid to the sku field - since around VM3.4 there is a flag for first save as well so it wouldn't be called every time you updated etc
Title: Re: Save virtuemart_product_id in product_sku field
Post by: PRO on January 30, 2019, 20:31:26 PM
OVERRIDE THE PRODUCT FORM

administrator/views/product/product_edit_information.php


         <td>
            <input type="text" class="inputbox" name="product_sku" id="product_sku" value="<?php echo $this->product->product_sku; ?>" size="32" maxlength="255" />
         </td>


to
         <td>
            <input type="text" class="inputbox" name="product_sku" id="product_sku" value="<?php echo $this->product->virtuemart_product_id; ?>" size="32" maxlength="255" />
         </td>
Title: Re: Save virtuemart_product_id in product_sku field
Post by: GJC Web Design on January 30, 2019, 21:27:04 PM
the above  will only work after the initial save though...
Title: Re: Save virtuemart_product_id in product_sku field
Post by: Alexikakos on January 31, 2019, 09:25:03 AM
Thank you PRO
I used your solution with a little modification because I needed to add a few more digits for the date and it worked perfectly.

I give the modification I did in case someone else will need it.


<?php
  
// get current date
   
$Y date('y');
   
$M date('m');
?>


<input type="text" class="inputbox disabled" name="product_sku" id="product_sku" value="<?php echo $this->product->virtuemart_product_id $Y $M?>" size="32" maxlength="255" />


So now, the product sku has the product id plus a four digit number for the date it was created or editted.