简体   繁体   中英

How to update a new atribute in Magento with CSV file thorugh API

I have a big numbers from Products in Magneto and i must add EAN Numbers to all the Products. How could i update the new attribute from the CSV file through API.i want to update the EAN numbers from a ssh server through API SOAP.

This is not a full solution for you, but it is definitely a starting point for you. Good Luck

$productData = array(
    'additional_attributes' => array(
        'single_data' => array(
            array(
                'key' => 'ean',
                'value' => 'value',
            ),
        ),
    ),
);
$productId = '1000000';

$soap = new SoapConnection('1','2','3');
echo $soap->_catalogProductUpdate($productId,$productData); 


class SoapConnection
{
    protected $soap_client;
    protected $session_id;

    function __construct($soap_host, $api_user, $api_pass)
    {
        try{
            echo "Connecting to $soap_host\n";
            $this->soap_client = new SoapClient( $soap_host, array('trace' =>true,
                'connection_timeout' => 30,
                'cache_wsdl' => WSDL_CACHE_NONE,
                'keep_alive' => false
                ));
            $this->session_id = $this->soap_client->login( $api_user, $api_pass);
            echo "Connected with session id ".$this->session_id."\n";
            return true;
        } catch (SoapFault $e) {
            echo "Soap Exception connecting to $soap_host: ".  $e->getMessage(). "\n";
            var_dump($this->soap_client->__getLastRequest()); var_dump($this->soap_client->__getLastResponse());
            return false;
        }
    }

    function _catalogProductUpdate($sku, $args)
    {
        try
        {
            return $this->soap_client->catalogProductUpdate($this->session_id, $sku, $args);
        } catch (SoapFault $e) {
            echo "Soap Exception _catalogProductUpdate: ".  $e->getMessage(). "\n";
            return false;
        }
    }
}

EDIT:

here is how to read a csv:

$file = fopen("my file path .csv","r");

while($row = fgetcsv($file))
{
    $row[0];//column1
    $row[1];//column2 etc etc etc
}
fclose($file);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM