Jump to content

PHP script upload image for product not work


leifermendez

Recommended Posts

<?php
include_once 'config/config.inc.php';
include(dirname(__FILE__).'/init.php');
 //Create product
    $product = new Product(); 
    $product->ean13 = 12456;
    $product->name = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'Motofef2d3');
    $product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => 'testdeee');
    $product->id_category = 3;
    $product->id_category_default = 3;
    $product->redirect_type = '404';
    $product->price = 33;
    $product->wholesale_price = 25;
    $product->minimal_quantity = 1;
    $product->show_price = 1;
    $product->on_sale = 0;
    $product->online_only = 1;
    $product->meta_keywords = 'tedeast';
    $product->id_tax_rules_group = 0;

    $product->add();
    $product->addToCategories(array(3));
    StockAvailable::setQuantity($product->id,'',10);


    //Add  main product image
    $id_product = $product->id;
    $url = 'http://images.mcn.bauercdn.com/upload/280825/images/480x320/flint-moto2.jpg';
    $shops = Shop::getShops(true, null, true);    
    $image = new Image();
    $image->id_product = $id_product;
    $image->position = Image::getHighestPosition($id_product) + 1;
    $image->cover = true; // or false;
    if (($image->validateFields(false, true)) === true &&
    ($image->validateFieldsLang(false, true)) === true && $image->add())
    {
        $image->associateTo($shops);
        if (!AdminImportController::copyImg($id_product, $image->id, $url))
        {
            $image->delete();
        }
    }
	
?>

Hi, excuseme for my english is very basic,

I nned help, for my script php, the script work fine, but the problem the upload image not work.

ks1g2XA.png

Link to comment
Share on other sites

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