如何在magento中获得更大的图像?

时间:2016-09-14 14:36:25

标签: php magento

我正在使用带有扩展名的magento rwd主题 - 用于选定的产品小部件。

问题我无法增加图像的大小。 相关代码是这样的:

<?php


$products = $this->getProductCollection();?>
<?php if ($products && $products->getSize()): ?>
<div class="block block-products selected-products">
    <div class="block-title">
        <strong><span><?php echo $this->getBlockName() ?></span></strong>
    </div>
    <div class="block-content">
        <div class="products-block">
            <?php foreach ($products->getItems() as $product): ?>
                <?php /** @var $product Mage_Catalog_Model_Product */ ?>
                <div class="item">
                    <a class="product-image"
                       href="<?php echo $product->getProductUrl() ?>"
                       title="<?php echo $this->stripTags($product->getName(), null, true) ?>">
                        <img
                            src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(300,400) ?>"
                            alt="<?php echo $this->stripTags($product->getName(), null, true) ?>" />
                    </a>

                    <div class="product-details">
                        <p class="product-name">
                            <a href="<?php echo $product->getProductUrl() ?>"
                               title="<?php echo $this->stripTags($product->getName(), null, true) ?>)">
                                <?php echo $this->helper('catalog/output')->productAttribute($product, $product->getName(), 'name') ?>
                            </a>
                        </p>
                        <?php if ($product->getIsSalable()): ?>
                            <div class="product-price">
                                <?php echo $this->getPriceHtml($product, true) ?>
                            </div>
                            <button type="button"
                                    title="<?php echo $this->__('Add to Cart') ?>"
                                    class="button btn-cart"
                                    onclick="setLocation('<?php echo $this->getAddToCartUrl($product) ?>')">
                                <span><span><?php echo $this->__('Add to Cart') ?></span></span>
                            </button>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>

我已将调整大小设置为300x400,但我得到它 - 118x157

网站链接供参考 - Change your Belief for Success

1 个答案:

答案 0 :(得分:0)

在调整大小之前,您必须在图像助手上将constrainOnly设置为true:

$this->helper('catalog/image')
    ->init($product, 'image')
    ->constrainOnly(true)
    ->resize(300,400);

从方法的PHPDoc:

Guarantee, that image picture will not be bigger, than it was.
Applicable before calling resize()
It is false by default