Author Topic: Save virtuemart_product_id in product_sku field  (Read 539 times)

Alexikakos

  • Beginner
  • *
  • Posts: 12
Save virtuemart_product_id in product_sku field
« 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?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9050
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Save virtuemart_product_id in product_sku field
« Reply #1 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10358
  • VirtueMart Version: 3+
Re: Save virtuemart_product_id in product_sku field
« Reply #2 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>
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9050
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Save virtuemart_product_id in product_sku field
« Reply #3 on: January 30, 2019, 21:27:04 pm »
the above  will only work after the initial save though...
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Alexikakos

  • Beginner
  • *
  • Posts: 12
Re: Save virtuemart_product_id in product_sku field
« Reply #4 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.

Code: [Select]
<?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.