When we add a product and save it, the product gets the right created_on date. And the if we save the product again, with or without making any changes, the created_on changes to a strange date...
This results in no "Latest product" since the date is all wrong.... This is how we discovered the problem.
Now, how do we solve this?
We do no longer think it's a template problem, since it has something to do with adding/saving the products.
See attached image..
:/
[attachment cleanup by admin]
Forgot to mention:
Joomla 2.5.9
VM 2.0.20b
You have a UNIX time stamp? In database there is the date stored like 2012-10-25 10:36:01
This unix time is displayed when I print the debug line (on request from my template forum).
This is how it looks in the database. (see images)
We haven't done any changes to tables or fields. Just regular VM.
[attachment cleanup by admin]
This is the core SQL for latest products:
case 'latest':
$date = JFactory::getDate (time () - (60 * 60 * 24 * $latest_products_days));
$dateSql = $date->toMySQL ();
$where[] = 'p.`' . $latest_products_orderBy . '` > "' . $dateSql . '" ';
$orderBy = 'ORDER BY p.`' . $latest_products_orderBy . '`';
$this->filter_order_Dir = 'DESC';
break;
This works fine.
Have you checked the settings for latest products?
Configuration > Shopfront > Core Settings :
Latest Products - Number of days to display
Latest Products - Sort order of display
Else I think it's a template problem ... try it with default template like beez
Or have you changed any core files?
and you can use vm debug for debugging...enable it in configuration and use vmdebug('my debugging',$variable);
I don't know much about debugging...
I used this to see what the database had as created date and today's date:
print 'Debug Line '.__LINE__.' $createddate <pre>'; print_r ($createddate); print "</pre><br />\n";
Here's our core settings: (see image)
I have done nothing to make the save process change the created_on date.
Why do you think this has to with the template we use? We use standard Joomla admin template....
We only have a another template on frond end, and a special VM template.
But the problem is this:
When we add a product and save it, the product gets the right created_on date. And the if we save the product again, with or without making any changes, the created_on changes to a strange date...
This results in no "Latest product" since the date is all wrong....
[attachment cleanup by admin]
In default vm view files there are no $today or $createdday variable. Also the default vm core does not use UNIX timestamp.
So it seems the problem must be in your template (FE)...Maybe your template use his own method to display latest products. Your DB image shows the right dates.
Have you tried it with the beez template??
We do have a created_on date variable in our database. Doesn't everyone?
CREATE TABLE
(...)
`created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` int(11) NOT NULL DEFAULT '0',
`modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` int(11) NOT NULL DEFAULT '0',
(...)
I have taken a snapshot of the product table after the first save of the new product, and then again after the second save.
Nothing changes exept the modifying date/time:
INSERT INTO
(`virtuemart_product_id`,`product_s_desc`,`product_desc`,`product_name`,`metadesc`,`metakey`,`customtitle`,`slug`)
After first save:
(10356,'','','test9','','','','test9'),
After second save:
(10356,'','','test9','','','','test9'),
INSERT INTO:
(`pordering`,`virtuemart_product_id`,`virtuemart_vendor_id`,`product_parent_id`,`product_sku`,`product_weight`,
`product_weight_uom`,`product_length`,`product_width`,`product_height`,`product_lwh_uom`,`product_url`,
`product_in_stock`,`product_ordered`,`low_stock_notification`,`product_available_date`,`product_availability`,
`product_special`,`product_sales`,`product_unit`,`product_packaging`,`product_params`,`hits`,`intnotes`,
`metarobot`,`metaauthor`,`layout`,`published`,`created_on`,`created_by`,`modified_on`,`modified_by`,
`locked_on`,`locked_by`)
After first save:
(0,10356,1,0,'1234567','0.0000','KG','0.0000','0.0000','0.0000','CM','',0,0,0,'2013-04-07 00:00:00','',0,0,'KG','0.0000','min_order_level=\"\"|max_order_level=\"\"|step_order_level=\"\"|product_box=\"\"|',NULL,
'','','','0',1,'2013-04-07 08:11:02',314,'2013-04-07 08:11:02',314,'0000-00-00 00:00:00',0);
After second save:
(0,10356,1,0,'1234567','0.0000','KG','0.0000','0.0000','0.0000','CM','',0,0,0,'2013-04-07 00:00:00','',0,0,'KG','0.0000','min_order_level=\"\"|max_order_level=\"\"|step_order_level=\"\"|product_box=\"\"|',NULL,
'','','','0',1,'2013-04-07 08:11:02',314,'2013-04-07 08:11:51',314,'0000-00-00 00:00:00',0);
Then I inserted the debug lines: (see image)
And two different dates were displayed...
[attachment cleanup by admin]
It's a bug in administrator/components/com_virtuemart/models/product.php
explanation below
the problem is in administrator/components/com_virtuemart/models/product.php line ~ 759
just before this the $product object is showing
Debug Line product.php 759 $product->created_on => 2012-10-22 10:36:01
the product price model -
they get a product price array back
e.g.
Debug Line product.php 760 $product->prices[0]
Array
(
[virtuemart_product_price_id] => 1
[virtuemart_product_id] => 5
[virtuemart_shoppergroup_id] =>
[product_price] => 24.99000
[override] => 0
[product_override_price] => 0.00000
[product_tax_id] =>
[product_discount_id] =>
[product_currency] => 144
[product_price_publish_up] => 0000-00-00 00:00:00
[product_price_publish_down] => 0000-00-00 00:00:00
[price_quantity_start] => 0
[price_quantity_end] => 0
[created_on] => 0000-00-00 00:00:00
[created_by] => 0
[modified_on] => 0000-00-00 00:00:00
[modified_by] => 0
[locked_on] => 0000-00-00 00:00:00
[locked_by] => 0
)
as you can see it has an element created_on which is 0000-00-00 00:00:00
this array is then merged with the $product object
$product = (object)array_merge ((array)$product, (array)$product->prices[0]);
and the created_on is overwritten
now the $product object is
Debug Line product.php 765 $product->created_on => 0000-00-00 00:00:00
there's the problem
##########################
to fix
file administrator/components/com_virtuemart/models/product.php find around line 759
$db->setQuery($q);
$product->prices = $db->loadAssocList();
$err = $db->getErrorMsg();
if(!empty($err)){
vmError('getProductSingle '.$err);
} else {
//vmdebug('getProductSingle getPrice query',$q);
// vmdebug('getProductSingle ',$quantity);
//vmTrace('hmpf');
}
if(count($product->prices)===1){
$product = (object)array_merge ((array)$product, (array)$product->prices[0]);
add between these lines
unset($product->prices[0]['created_on'])//GJC fix for created_on
so it looks like
$db->setQuery($q);
$product->prices = $db->loadAssocList();
$err = $db->getErrorMsg();
if(!empty($err)){
vmError('getProductSingle '.$err);
} else {
//vmdebug('getProductSingle getPrice query',$q);
// vmdebug('getProductSingle ',$quantity);
//vmTrace('hmpf');
}
unset($product->prices[0]['created_on']);//GJC fix for created_on
if(count($product->prices)===1){
$product = (object)array_merge ((array)$product, (array)$product->prices[0]);
no idea if this is the best way to do it but it works
the $product object will now be
Debug Line product.php 759 $product->created_on => 2012-10-22 10:36:01
@chrlar
Quote
Have you tried it with the beez template??
It's got nothing to do with templates.. read above -
$product->created_on is always returned as 0000-00-00 00:00:00 by the product model because of what I just explained..
What happens to it later in the template is neither here nor there...
this is right, but the returned 0000-00-00 00:00:00 is not stored in DB ... I tried it
look in the atached DB image from chrlar ... all created_on dates are correct and nothing is 0000-00-00 00:00:00
I think I'll start with the hacking of the core file (administrator/components/com_virtuemart/models/product.php)
And if it work, great... Then I make a note of the changes I do for next time we update VM.
Or if it really is a bug, as John/GJC says, maybe the developer makes the changes too.. ;)
I'll be sure to tell you the result, after having tested it. :)
I'm one of the developers and I've tried the code from John ... but the result is the same ... the stored created_on is never 0000-00-00 00:00:00
look to your atached image from DB ... where is a created_on with 0000-00-00 00:00:00 ?
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..
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);
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]);
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]
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
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... :)
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?
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.