【发布时间】:2011-04-23 15:49:33
【问题描述】:
提前致谢。
我是 Magento 的新手,我创建了一个模块,可以将产品直接显示到 Magento 的前面。
在这个模块中,我在客户帐户部分创建了一个表格,客户可以在其中填写产品的必要数据。产品数据已成功保存,但我看不到前面的图像。我已经检查了从客户部分上传的产品的所有内容,也转到管理部分进行审批。
我只想展示我上传的产品图片。我的产品保存和图片上传代码如下。
对不起我的英语。
-吉特
$magentoProductModel = Mage::getModel('catalog/product');
$magentoProductModel->setWebsiteIds(array(Mage::app()->getStore()->getId()));
$magentoProductModel->setAttributeSetId(4);//old
//$magentoProductModel->setAttributeSetId(1);
$magentoProductModel->setTypeId('simple');
$magentoProductModel->setName($data[name]);
$magentoProductModel->setDescription($data[description]);
$magentoProductModel->setPrice($data[price]);
$magentoProductModel->setShortDescription($data[short_description]);
$magentoProductModel->setWeight($data[weight]);
$magentoProductModel->setStatus(1);
$magentoProductModel->setCategoryIds(array(3));
$magentoProductModel->setTaxClassId('None');
//$magentoProductModel->setSku('rand-sku-' .rand(1,20000) );
/* upload product image*/
$customerProductId=34;
$mediDir = Mage::getBaseDir('media');
$imagesdir = $mediDir . '/customersproducts/' . $customerProductId . '/';
if(!file_exists($imagesdir)){
return false;
}
foreach (new DirectoryIterator($imagesdir) as $fileInfo) {
//print_r($fileInfo);
if($fileInfo->isDot() || $fileInfo->isDir()) continue;
if($fileInfo->isFile()) {
//echo $fileInfo->getPathname();
$magentoProductModel->addImageToMediaGallery($fileInfo->getPathname(),array('image','small_image','thumbnail'), true, false, true);
}
//else {
//echo "no";
//}
}
print_r($magentoProductModel);
/*upload script end */
$saved = $magentoProductModel->save();
$lastId = $saved->getId();
$customerProduct = Mage::getModel('customerpartner/customerpartner_product')->load($lastId);
$customerProduct->setProductId($lastId);
$logged_in_user=Mage::getSingleton('customer/session')->getCustomer()->getId();
$customerProduct->setCustomerId($logged_in_user);
$customerProduct->setCustomerId();
$customerProduct->save();
【问题讨论】:
-
为了将来参考,请使用帖子表单上的“101010”按钮将您的文本格式化为代码。它还有助于使其始终缩进,以便其他人可以阅读它。最后,请检查帖子下方的预览框,以便您可以提前看到这些东西。很高兴您解决了自己的问题,感谢您分享您的答案!
标签: magento