News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

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

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

Previous topic - Next topic

chrlar

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]

chrlar


K&K media production

You have a UNIX time stamp? In database there is the date stored like 2012-10-25 10:36:01

chrlar

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]

K&K media production

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

K&K media production

#5
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);

chrlar

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]

K&K media production

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

chrlar

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]

GJC Web Design

#9
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
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

@chrlar

Quote
Have you tried it with the beez template??

GJC Web Design

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

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

chrlar

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

K&K media production

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 ?