如何在Magento 1.9.2中以编程方式添加产品图像

时间:2016-04-27 12:54:07

标签: php magento magento-1.9.2.1

Hello Guys我正在通过提交表单从前端以编程方式创建产品,但是当我这样做时:

$this->getRequest()->getPost();

我没有在阵列中获取图像数据。

另外,我想在产品中添加如何做到这一点,请指导我。

这里是我前端形式的代码:

<form action="<?php echo $this->getUrl('custom_abc/customProduct/addProduct') ?>" method="post" name="add-product" autocomplete="off" id="add-product-form" class="scaffold-form" enctype="multipart/form-data">
    <div class="field product-image">
        <label for="product-image" class="required"><em>*</em>Product Image</label>
        <div class="input-box">
            <input type="file" id="product-image" name="product-image" title="Product Image" class="input-text required-entry">
        </div>
    </div>
</form>

以下是我的产品添加的代码:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$product = Mage::getModel('catalog/product')->load($productData['productId']);

try {
        $product
                ->setMediaGallery(array('images' => array(), 'values' => array())) //media gallery initialization
                ->addImageToMediaGallery('not understanding what to do here', array('image', 'thumbnail', 'small_image'), false, false) //assigning image, thumb and small image to media gallery

        if ($product->save()) {

            Mage::getSingleton('core/session')->addSuccess('Your Product Uploaded Successfully');
            $this->_redirect('custom_abc/CustomAccount/manageCustomProduct');
            return;
        }else{

            Mage::getSingleton('core/session')->addError('Error in uploading Product');
            $this->_redirect('custom_abc/CustomAccount/manageCustomProduct');
            return;
        }
    } catch (Exception $e) {
        Mage::log($e->getMessage());
    }

0 个答案:

没有答案