bera_ramazan Posted September 19, 2017 Share Posted September 19, 2017 I have a xml import product prestashop how to create product image to get on url ex xml: <item><name>Note 8</name>....<image>http://xxxx.jpg</image></item> Prestashop add new product $createProduct = new Product();....$createProduct->add(); How to add image on xml url Good days My Code: $url = 'http://www.fyazilim.com/31-thickbox_default/ayakkabi-temasi-pro.jpg'; $product = new Product(); $image = new Image(); $langId = (int) (Configuration::get('PS_LANG_DEFAULT')); $name = Tools::getValue('product_name'); $product->name = array($langId => $name); $product->price = Tools::getValue('price'); $product->wholesale_price = Tools::getValue('wholesale_price'); $product->active = false; $product->is_virtual = true; $product->cache_has_attachments = true; $product->id_category_default=3; $product->reference = $this->context->cookie->id_customer; $product->link_rewrite = array($langId => Tools::link_rewrite($name)); $product->add(); $image->id_product = intval($product->id); $image->position = Image::getHighestPosition($product->id) + 1; if(Image::getImagesTotal($product->id)>0) $image->cover = false; else $image->cover = true; $languages = Language::getLanguages(); foreach ($languages as $language) $image->legend[$language['id_lang']] = 'Click to view'; $id_image = $image->id; $tmpName = tempnam(_PS_IMG_DIR_, 'PS'); $path = _PS_IMG_DIR_.'tmp'; function getImage ($url,$path,$name,$ext) { $options = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad ) ); $context = stream_context_create($options); $file = @file_get_contents($url, false, $context); $filename = $path."/".$name."_".$ext ; $copy = file_put_contents($path."/".$filename,$file,FILE_APPEND); if ($copy) { return true ; } else { return true ; } } $image->add(getImage($url,$path,$image->id_product, 'jpg' )); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now