eZ Community » Forums » Developer » Set ezprice attribute in Product via...
expandshrink

Set ezprice attribute in Product via php code

Set ezprice attribute in Product via php code

Monday 28 November 2011 11:50:20 am - 4 replies

How to set ezprice attribute in products by php code?

This is my current code, but i have problem to set price.

$params = array();
$params['class_identifier'] = 'product'; //class name
$params['creator_id'] = $user->attribute( 'contentobject_id' );
$params['parent_node_id'] = $parent_node->attribute( 'node_id' );
$params['section_id'] = $parent_node->attribute( 'object' )->attribute( 'section_id' );
$attributesData = array();
$attributesData['name'] = $user->attribute( 'contentobject_id' )."_".$_POST["IDDEVICE"]."_".uniqid();
$attributesData['product_number'] = "";
$attributesData['price'] = $_POST["PRICE"];
$attributesData['tags'] = "";
//Wallpaper
if(isset($_FILES['WALLPAPER']))
{
    $file = $_FILES['WALLPAPER'];
    if($file["name"] != "")
    {
        if($file["error"] == 0)
        {
            try
            {
                $split_file = explode("/", $file['tmp_name']);
                $filename_without_extension = $user->attribute( 'contentobject_id' )."_".$_POST["IDDEVICE"]."_".$split_file[count($split_file)-1];
                $filename = $filename_without_extension.".jpg";
                $directory_path = $_SERVER['DOCUMENT_ROOT'] . '/var/ezwebin_site/storage/import_images/';
                copy($file['tmp_name'], $directory_path.$filename);
                $params['storage_dir' ] = $directory_path;
                $attributesData ['image'] = $filename;
            }catch(MyException $e){
                print_r($e);
            }
        }
    }
}
//publishing node
$params['attributes'] = $attributesData;
$imageObject = eZContentFunctions::createAndPublishObject($params);

Thank you.

Domenico

Modified on Monday 28 November 2011 11:51:05 am by Domenico Garozzo

Monday 28 November 2011 12:31:28 pm

Hello Domenico,

Consider refering to the article about using this PHP functionality in eZ Publish with detailed background information (related to your core issue, what format is used for what datatype), 

Quote: "Although the basic process is straightforward, there are a couple of things to look out for so we’ll look at importing different content in turn. eZ Publish makes use of the fromString methods when carrying out the import. If the object you are creating contains fields of types we are not covering here, I’d recommend checking out the fromString documentation found here."

From: http://share.ez.no/layout/set/print/learn/ez-publish/creating-ez-publish-objects-in-php#eztoc378535_5

See this ezpedia doc, search for 'ezprice'

http://ezpedia.org/ez/simple_fromstring_and_tostring_interface_for_attributes

Read the original doc on the subject, https://github.com/ezsystems/ezpublish/blob/master/doc/features/3.9/to_from_string_datatype_functionality.txt

Mentioned here in this related thread, http://share.ez.no/forums/developer/import-csv-in-ezp-3.9-missing-doc

You can also review the ezpricetype PHP class method which implements the datatype's fromString support, https://github.com/ezsystems/ezpublish/blob/master/kernel/classes/datatypes/ezprice/ezpricetype.php#L231

and the related toString method in action, https://github.com/ezsystems/ezpublish/blob/master/kernel/classes/datatypes/ezprice/ezpricetype.php#L221

 

This background information should help you reach your goal. Best wishes!

 

I hope this helps ...

 

Cheers,

Heath

Monday 28 November 2011 12:43:31 pm

Thank you Heath!

I haven't known "Simple fromString and toString interface for attributes" article.

My problem is solved!

Thank you again!

Monday 28 November 2011 9:31:37 pm

Hello Domenico,

Great! I'm glad your issue is now resolved.

 

Could you help us out and login to share.ez.no and click the question resolved icon at the top of your original forum message?

 

Cheers,

Heath

Tuesday 29 November 2011 10:33:20 am

I do it!

Thank you.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from