【问题标题】:Wrong product URLs magento错误的产品 URL magento
【发布时间】:2013-08-07 10:44:03
【问题描述】:

我一直在编写自定义向上销售相关产品脚本,它显示 4 个随机产品。

问题是:

正常的产品网址是:

/shop/$产品名称

这有时会生成如下网址:/$productname/

或类似网址:/catalog/product/view/id/$productID/4/s/$productname/category/$categoryid/

我希望我的所有网址都相同:/shop/$productname

<div class="upsell">
<h2>You might be interested in</h2>
    <?php // List mode ?>
    <?php $_iterator = 0; ?>
    <?php // Grid Mode ?>
    <table class="products-grid upsell" id="upsell-product-table">
                    <tbody>
                    <tr>
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); $_columnCount=4; ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <?php endif ?>
            <td>
            <?php // Initiate product model
$product = Mage::getModel('catalog/product');

// Load specific product whose tier price want to update
$product ->load($_product->getId()); ?>
                <a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(170); ?>" width="125" height="125" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                 <h3 class="product-name"><a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($product, $product->getName(), 'name') ?></a></h3>
                <?php echo $this->getPriceHtml($product, true) ?>

            </td>
        <?php endforeach; ?>
        </tr>
        </tbody>
        </table>
</div>

【问题讨论】:

    标签: php magento zend-framework


    【解决方案1】:

    试试

    $this->getUrl('shop').$product->getUrlPath()
    

    而不是

    $product->getProductUrl()
    

    图片和产品标题。

    【讨论】:

      【解决方案2】:

      如果你的索引是最新的,那么

      $product->getProductUrl() 
      

      应该给你正确的产品网址。
      不要尝试从 url_key 或 url_path 和基本 url 之类的部分自己构建 url。如果您将网站移至其他服务,您将遇到一些问题。此外,如果您更改产品 url 中类别的配置设置,您可能会遇到问题。

      【讨论】:

      • 我的索引似乎是最新的,但它不工作,只是部分链接工作正常,删除所有重写网址可以解决吗?并再次创建它们?
      • 你可以试试,但要先备份。
      • 清除了所有的重写,还是同​​样的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 2013-01-25
      • 1970-01-01
      相关资源
      最近更新 更多