【问题标题】:Magento: How to get thumbnail?Magento:如何获得缩略图?
【发布时间】:2012-09-09 21:11:36
【问题描述】:

我下载了一个脚本来创建我的产品的 CSV 数据馈送,并且我还想在缩略图中包含一个 URL。该代码已经包含以下产品图片网址:

$product_data['ImageURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

所以我尝试将其调整为:

$product_data['ThumbnailURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getThumbnail();

显示完全相同的图片网址(不是拇指)。我该如何解决这个问题?

我做了一个var_dump($product);,结果是:

["image"]=> string(18) "/f/i/file_2_18.png" ["small_image"]=> string(18) "/f/i/file_2_18.png" ["thumbnail"]=> string(18) "/f/i/file_2_18.png"

我还需要获取产品的子类别,但我不知道如何调用它。如何查看哪些变量是可能的?例如。 $product->getPrice$product->getName?

【问题讨论】:

标签: php magento csv datafeed


【解决方案1】:

我最近也需要这样做...这是我的方法:

$_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl();

或者另一个例子

您应该为此使用目录产品媒体配置模型。

<?php

//your code ...

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

在您发表评论后编辑。

更新答案

见以下网址

Make all store images the base, small and thumbnail images in Magento?

试试看

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}

希望对你有所帮助!

【讨论】:

【解决方案2】:

如果您想查看可以访问哪些数据,可以试试这个:

<?php var_dump(array_keys($product->getData())); ?>

然后您可以使用两种方法来获取此数据:

<?php $product->getAttributeName() // Use CamcelCase ?>

<?php $product->getData('attribute_name') // underscores ?>

【讨论】:

  • Varien_Object::debug() 提供了更多实用性和洞察力。
猜你喜欢
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 2012-09-29
  • 2015-10-24
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 2014-07-26
相关资源
最近更新 更多