Jump to content

Creating full new Product(1) without Context


Richard S

Recommended Posts

Hi there,

so I have another question.

 

So if I create a new Product(1, TRUE) without Context (meaning Cron job etc.) it will not still create good object and when I try to ->update() or ->save() it shows a lot of error of missing values.

So on this occasion when I need full product information the only thing is to call SQL query which would get it?

Link to comment
Share on other sites

What is your prestashop version ?

object update() or save() will thrown errors if there are invalid/missing data within your object value.

Take a look the classes file Product.php in public static $definition

 

You cannot add whatever you want as object variable value, it's should passed the validation,

and the required object fields should have a value

Link to comment
Share on other sites

It seems that moderators of this forum tries to post as many as possible messages which are worthless.

I know everything you have mentioned and it does not answer my question at all.

When I create an object without cookie/context (for example, doing cron) I get lots of that missing data errors. I've investigated code and saw that for proper update and saving context is needed which is a big problem in PrestaShop architecture, so I want to get some response from Benjamin or someone else at PrestaShop to make sure if I am right.

 

I am using newest PS version PS1.6.0.9.

 

In addition, my problem is that  have an existing VALID product in database and I am trying to initiate it with new Product construct and it does not initiate it properly without cookie being available.

Edited by Richard S (see edit history)
Link to comment
Share on other sites

It seems that moderators of this forum tries to post as many as possible messages which are worthless.

 

I was really sad read your statement, i'm here to help, but then ...

 

But okay ... i'll still wanna try to help you, and if you still felt what I'm trying to do here are worthless ... i'll walked out from this thread.

 

Simple example :

 

If i've created a file on my Prestashop

http://myprestashop.com/ps-admin/print_product.php
<?php
// file : print_product.php

if (!defined('_PS_ADMIN_DIR_'))
	define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');

// determine id_product
$id_product = Tools::getValue('id_product');

// initialize product object
$product = new Product((int)$id_product, true);

// for example, i want to change Product name
$new_name = Tools::getValue('new_name');
foreach(Language::getLanguages() as $lang)
    $product->name[(int)$lang['id_lang']] = $new_name;

// TO UPDATE this product object name, just uncomment below
// $product->update();

// print product object and die ...
d($product);

.

And then i call that url on my wordpress site

http://mywordpress.com/getPrestashopProductObject.php
<?php
// file : getPrestashopProductObject.php

$host = 'http://myprestashop.com/ps-admin/';
$getContent = file_get_contents($host.'print_product.php?id_product=1&new_name=New-Name');

die($getContent);

I will be able to see Prestashop product object (full) on this page, with new Product name = "New-Name"

Of course I won't be able to update this Prestashop product object on my wordpress site.

 

But if i'm adding following line of code into the php source file on

http://myprestashop.com/ps-admin/print_product.php

@see comment // TO UPDATE

$product->update();

Then i can updating Prestashop product object through my wordpress site.

 

Want to automate the process with cron ?

I just need to set that URL on my cron jobs.

 

Hope that's help anyone else who needed, thank you and good bye.

(END)

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...