Adding product -> saving product => changing "created_on" date

Started by chrlar, April 05, 2013, 09:21:01 AM

Previous topic - Next topic

GJC Web Design

I'm not saying the stored #__virtuemart_products.created_on is touched..

What is happening is when the two arrays are merged in function getProductPrices()

$product = (object)array_merge ((array)$product, (array)$product->prices[0]);

the #__virtuemart_product_prices.created_on overwrites it in the $product object

So every call to $products = $productModel->getProductsInCategory($categoryId); in a template returns the #__virtuemart_product_prices.created_on not the #__virtuemart_products.created_on

and in this case it is 0000-00-00 00:00:00 - in other cases may be something else but never the less the wrong created_on is being returned in the object..

All my #__virtuemart_product_prices.created_on are 0000-00-00 00:00:00 - is there even a point to having that field?

All I do is  unset($product->prices[0]['created_on']) before the array merge so the products is not overwritten..
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

K&K media production

#16
this can be, but the normal output for latest products don't have this call ... so I think the template from him don't use the normal output method for latest products

this is the call for latest products:

$productModel->getProductListing('latest', $latest_products_count);

GJC Web Design

Which call?

it's the standard call in the categories view.html

and it's not a case of latest products - we use it to display a "New" flag if added recently

// Load the products in the given category
       $products = $productModel->getProductsInCategory($categoryId);
       $productModel->addImages($products,1);

and looking at administrator/components/com_virtuemart/models/product.php line ~ 759 release 2.0.20b I find

if(count($product->prices)===1){
         unset($product->prices[0]['virtuemart_product_id']);
         $product = (object)array_merge ((array)$product, (array)$product->prices[0]);

so the overwriting is a  known problem - as I say - why is the created_on needed in the prices? it's never set..

my fix works as

if(count($product->prices)===1){
         unset($product->prices[0]['virtuemart_product_id']);
                        unset($product->prices[0]['created_on']);//GJC fix for created_on

         $product = (object)array_merge ((array)$product, (array)$product->prices[0]);
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

chrlar


Oh! We like you very much GJC!! ;)

Hurray!

The core files now has a small but efficient little change!

GJC can take the credit and lay out the change himself.. :)

Thank you - thank you - thank you!!!



[attachment cleanup by admin]

K&K media production

the issue of chrlar are the latest products

yes I've inserted unset created_on

I don't know why created_on is needed in the prices ... or why it isn't the created_on from the price

$productModel->getProductListing

returns products for latest, recent, featured, random and topten

chrlar

I'm not sure what you mean, kkmediaproduction...?

In my case the created _on has nothing to do with the prices... at least not our prices...

I wanted to label the product picture in category view, and needed the system to read the created_on date....

GJC may explain this better for you... :)

K&K media production

Quote
I don't know why created_on is needed in the prices ... or why it isn't the created_on from the price

this was the answer to the question from GJC: why is the created_on needed in the prices?

Milbo

I added now this


unset($product->prices[0]['virtuemart_product_id']);
unset($product->prices[0]['created_on']);
unset($product->prices[0]['created_by']);
unset($product->prices[0]['modified_on']);
unset($product->prices[0]['modified_by']);
unset($product->prices[0]['locked_on']);
unset($product->prices[0]['locked_by']);


Should solve it.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/