magento api

http://devdocs.magento.com/guides/m1x/api/soap/introduction.html

The Magento SOAP v1 API provides you with the ability to manage your eCommerce stores by providing calls for working with resources such as customers, categories, products, and sales orders. It also allows you to manage shopping carts and inventory.

A SOAP v2 API version has been available since Magento 1.3, and a WS-I compliant version has been available since Magento 1.6.

http://www.hellokeykey.com/magento-api-update-product-images/


<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/4 0004
 * Time: 下午 4:20
 */
require_once('../app/Mage.php');
umask(0);
Mage::app();
function doProductMigration($productType, $setId, $sku, $productData)
{
    $result = array();
    $client = new SoapClient('http://www.host.com/api/soap/?wsdl');
    $session = $client->login('user', 'key');

    $client->call($session, 'product.create', array($productType, $setId, $sku, $productData));
    $result = $client->call($session, 'product.info', $sku);

    //省略初始化Api过程,见我的其余magento API文章 www.hellokeykey.com
//        产品图片
//        初始化产品图片信息,注意自己上传个产品图片到magento的产品图片文件夹
//        $imagePath为图片路径,如果你使用相对路径,注意测试下是正确
//        label为图片的alt属性
//        position 为图片的显示顺序
//        type 为此图片作为'thumbnail','small_image','image'中的哪一个
//        mime为图片类型
    $imagePath = "https://d5yjppyekae0b.cloudfront.net/large/2017/9/29/Blush-5661_3C.jpg";  //产品图片路径
    $newImage = array(
        'file' => array(
            'name' => 'file_name',
            'content' => base64_encode(file_get_contents($imagePath)),
            'mime' => 'image/jpeg'
        ),
        'label' => 'Cool Image Through Soap',
        'position' => 1,
        'types' => array('thumbnail', 'small_image', 'image'),
        'exclude' => 0
    );
//使用 Api创建产品图片
    $imageFilename = $client->call($session, 'product_media.create', array($sku, $newImage));

    return $result;
    $client->endSession($session);
}

$newProductData = array(
    'name' => 'Product Name 1',
    'lee_size' => '125',
    'websites' => array(1),
    'description' => '',
    'price' => 9.99,
    'category_ids' => '',
    'visibility' => 4,
    'status' => 1,
    'weight' => 1,
    'tax_class_id' => 2,
);
$sku_c = 'cc' . rand();
$productOne = doProductMigration('simple', '4', $sku_c, $newProductData);
echo '<p>productOne strat------------------------</p>';
print_r($productOne);
echo '<p>productOne end</p>';

$newProductData = array(
    'name' => 'Product Name 2',
    'lee_size' => '126',
    'websites' => array(1),
    'description' => '',
    'price' => 9.99,
    'category_ids' => '',
    'visibility' => 4,
    'status' => 1,
    'weight' => 1,
    'tax_class_id' => 2,
);
$sku_c = 'cc' . rand();
$productTwo = doProductMigration('simple', '4', $sku_c, $newProductData);
echo '<p>productTwo strat-----from-www.hellokeykey.com----------</p>';
print_r($productTwo);
echo '<p>productTwo end</p>';

$configurableProductsData = array(
    $productOne['product_id'] => array(
        'attribute_id' => 950, //[44]=> array(5) { ["attribute_id"]=> string(3) "502" ["code"]=> string(9) "shoe_size" ["type"]=> string(6) "select" ["required"]=> string(1) "1" ["scope"]=> string(6) "global" }
        'label' => 'option 1', //[1]=> array(2) { ["value"]=> string(2) "46" ["label"]=> string(1) "3" }
        'value_index' => 125, //The option id
        'is_percent' => 0,
        'pricing_value' => ''
    ),
    $productTwo['product_id'] => array(
        'attribute_id' => 950, //The attribute id
        'label' => 'option 2',
        'value_index' => 126, //The option id
        'is_percent' => 0,
        'pricing_value' => ''
    )
);
//        /Create the configurable attributes data
$configurableAttributesData = array(
    '0' => array(
        'id' => NULL,
        'label' => '', //optional, will be replaced by the modified api.php
        'position' => NULL,
        'values' => array(
            0 => array(
//                        'attribute_id' => 950, //The attribute id
//                        'label' => 'lee size',
//                        'value_index' => 125, //The option id
                'is_percent' => 0,
                'pricing_value' => ''
            ),
            1 => array(
//                        'attribute_id' => 950, //The attribute id
//                        'label' => 'option 2',
//                        'value_index' => 126, //The option id
                'is_percent' => 0,
                'pricing_value' => ''
            )
        ),
        'attribute_id' => 950, //get this value from attributes api call
        'attribute_code' => 'lee_size', //get this value from attributes api call
        'frontend_label' => 'lee size', //optional, will be replaced by the modifed api.php
        'html_id' => 'config_super_product__attribute_0'
    )
);

//add configurable product
$newProductData = array(
    'name' => 'Product Group Name',
    'websites' => array(1),
    'description' => 'Group description',
    'category_ids' => array(1),
    'visibility' => 4,
    'status' => 1,
    'weight' => 0,
    'price' => 9.99,
    'tax_class_id' => 2,
    'weight' => 0,
    'configurable_products_data' => $configurableProductsData,
    'configurable_attributes_data' => $configurableAttributesData
);
$sku_c = 'cc' . rand();
$result = doProductMigration('configurable', '4', $sku_c, $newProductData);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值