gpt4 book ai didi

php - 在 magento 中获取产品图像时找不到图像文件

转载 作者:搜寻专家 更新时间:2023-10-31 20:37:13 28 4
gpt4 key购买 nike

我正在尝试获取产品图片,但 magento 显示找不到错误图片文件

There has been an error processing your request
Image file was not found.

Trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Catalog/Helper/Image.php(166): Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
#1 /Applications/XAMPP/xamppfiles/htdocs/whi/app/design/adminhtml/default/default/template/whi/brand/my_collections/brand_indi_collection_view.phtml(98): Mage_Catalog_Helper_Image->init(Object(Mage_Catalog_Model_Product), 'thumbnail')
#2 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(241): include('/Applications/X...')
#3 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#4 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#5 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#6 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#7 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#8 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#9 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#10 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#11 /Applications/XAMPP/xamppfiles/htdocs/whi/app/design/adminhtml/default/default/template/whohasitadmin/layout/admin.phtml(224): Mage_Core_Block_Abstract->getChildHtml('content')
#12 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(241): include('/Applications/X...')
#13 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#14 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#15 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#16 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#17 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#18 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#19 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/local/Whi/Brands/controllers/MycollectionController.php(358): Mage_Core_Controller_Varien_Action->renderLayout()
#20 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Whi_Brands_MycollectionController->individual_collection_viewAction()
#21 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('individual_coll...')
#22 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#23 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#24 /Applications/XAMPP/xamppfiles/htdocs/whi/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#25 /Applications/XAMPP/xamppfiles/htdocs/whi/index.php(90): Mage::run('', 'store')
#26 {main}

Error log record number: 1154029962119

这是我的 Controller 。

public function individual_collection_viewAction() {

$Params = $this->getRequest()->getParams();
$category = new Mage_Catalog_Model_Category();

$category->load($Params['id']);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
$data['products'] = $collection->load();

$this->loadLayout();

$block = Mage::app()->getLayout()->getBlock('mycollection_individual_view');

if ($block) {
$block->setData($data);

}
$this->renderLayout();
}

这是我的观点:

    <?php 
foreach ($data['products'] as $product) {
$productName = $product->getName();
$proimage = Mage::helper('catalog/image')->init($product, 'thumbnail');
//$productImage = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" .$product->getImage();
?>

产品名称已成功获取,但当我尝试获取图像时,它会重新找到图像。谁能帮我解决这个问题。

最佳答案

首先,您需要验证在 Magento 管理中选择了基本图像、小图像和缩略图。

admin->catalog->manage product->product->image

然后你调用图像使用

$proimage = (string)Mage::helper('catalog/image')->init($product, 'thumbnail');//image,smallimage

$proimage = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail()); //getSmallImage(), getImage()

编辑:

foreach ($data['products'] as $product) { 
$product = Mage::getModel('catalog/product')->load($product->getId());
$productName = $product->getName();
$proimage = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail());
}

关于php - 在 magento 中获取产品图像时找不到图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32263500/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com