【问题标题】:How to Create a Downloadable Product through Magento API?如何通过 Magento API 创建可下载的产品?
【发布时间】:2011-01-23 12:22:39
【问题描述】:

我是 Magento 的新手,正在使用他们的 API。 我想问的是,是否可以通过API创建可下载的产品? 文档示例仅用于创建新的简单产品,如果我使用 API 查看可下载产品的 product.info,我看不到任何链接到分配给该产品的可下载文件的属性。

任何帮助将不胜感激,谢谢:)

【问题讨论】:

    标签: php api soap magento


    【解决方案1】:

    现在的文档足以了解 Magento SOAP API V1。

    从 SOAP API V1 创建产品,如示例:

    $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
    $sessionId = $proxy->login('apiUser', 'apiKey');
    $filesPath = '/var/www/ws/tests/WebService/etc/Modules/Downloadable/Product/Link';
    $downloadableProductId = 'downloadable_demo_product';
    
    $items = array(
        'small' => array(
            'link' => array(
                'title' => 'Test file',
                'price' => '123',
                'is_unlimited' => '1',
                'number_of_downloads' => '111',
                'is_shareable' => '0',
                'sample' => array(
                    'type' => 'file',
                    'file' =>
                    array(
                        'filename' => 'files/test.txt',
                    ),
                    'url' => 'http://www.magentocommerce.com/img/logo.gif',
                ),
                'type' => 'file',
                'file' =>
                array(
                    'filename' => 'files/test.txt',
                ),
                'link_url' => 'http://www.magentocommerce.com/img/logo.gif',
            ),
            'sample' => array(
                'title' => 'Test sample file',
                'type' => 'file',
                'file' => array(
                    'filename' => 'files/image.jpg',
                ),
                'sample_url' => 'http://www.magentocommerce.com/img/logo.gif',
                'sort_order' => '3',
            )
        ),
        'big' => array(
            'link' => array(
                'title' => 'Test url',
                'price' => '123',
                'is_unlimited' => '0',
                'number_of_downloads' => '111',
                'is_shareable' => '1',
                'sample' => array(
                    'type' => 'url',
                    'file' => array(
                        'filename' => 'files/book.pdf',
                    ),
                    'url' => 'http://www.magentocommerce.com/img/logo.gif',
                ),
                'type' => 'url',
                'file' => array(
                    'filename' => 'files/song.mp3',
                ),
                'link_url' => 'http://www.magentocommerce.com/img/logo.gif',
            ),
            'sample' => array(
                'title' => 'Test sample url',
                'type' => 'url',
                'file' => array(
                    'filename' => 'files/image.jpg',
                ),
                'sample_url' => 'http://www.magentocommerce.com/img/logo.gif',
                'sort_order' => '3',
            )
        )
    );
    
    $result = true;
    foreach ($items as $item) {
        foreach ($item as $key => $value) {
            if ($value['type'] == 'file') {
                $filePath = $filesPath . '/' . $value['file']['filename'];
                $value['file'] = array('name' => str_replace('/', '_', $value['file']['filename']), 'base64_content' => base64_encode(file_get_contents($filePath)), 'type' => $value['type']);
            }
            if ($value['sample']['type'] == 'file') {
                $filePath = $filesPath . '/' . $value['sample']['file']['filename'];
                $value['sample']['file'] = array('name' => str_replace('/', '_', $value['sample']['file']['filename']), 'base64_content' => base64_encode(file_get_contents($filePath)));
            }
            if (!$proxy->call(
                $sessionId,
                'product_downloadable_link.add',
                array($downloadableProductId, $value, $key)
            )
            ) {
                $result = false;
            }
        }
    }
    

    source link

    你可以添加自定义属性

    from here

    【讨论】:

      【解决方案2】:

      我们都是 Magento 的新手,因为文档非常稀缺且不完整。

      我建议你看看这个方法:来自 Product 模型的setTypeInstance。 并进入这个类Mage_Downloadable_Model_Product_Type

      当您通过 API 创建产品时,唯一的问题是找到正确的格式以将此数据放入 API 所需的 productData 数组中。可能在你的数组中你需要这样的东西:

      // this is speculation
      "type" => "downloadable",
      "download_path" => "url"  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-14
        相关资源
        最近更新 更多