ambimax/magento-module-ambimax-productnotfoundhandler

处理产品重定向,如果URL中找到sku

1.0.2 2019-07-08 13:12 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:20:53 UTC


README

在导入产品时,url-key会通过一个连续的数字扩展,使其变得唯一。此外,还会从旧URL到新URL创建一个永久重定向。因此,core_url_rewrite表会迅速增长,导致许多Magento网站变慢。

为了解决这个问题,我们将sku添加到URL中,并使旧URL永久(只要存在具有相同sku的产品)可重定向,而不产生任何开销。本模块从URL中读取sku并将其重定向到新URL。

用法

URL必须使用此模式

http://domain.tld/any-string-{sku}-{skuLength}/

sku不得包含任何字符,仅限于#[^0-9a-z]+#i

Composer

composer require ambimax/magento-module-ambimax-productnotfoundhandler

安装

  1. 像安装其他(modman/composer)模块一样安装

  2. 要启用它,请设置配置 > 网络 > 默认页面 > CMS无路由页面(web/default/no_route)为productnotfoundhandler/index/noRoute(默认:cms/index/noRoute)

  3. 将sku和skuLength添加到所有产品的所有url-key属性中

示例导入用法


    /**
     * Prepare product data on import
     *
     * @param array $productData
     * @return array
     */
    public function row(array $productData)
    {
        // ...
        $url = array($productData['amazon_titel'], $productData['sku'], strlen($productData['sku']));
        $product['url_key'] = $this->formatUrlKey(implode(' ', $url));
        
        // ...
        
        return $productData;
    }

    /**
     * Format Key for URL
     *
     * @param string $str
     * @return string
     */
    public function formatUrlKey($str)
    {
        $urlKey = preg_replace('#[^0-9a-z]+#i', '-', strtolower(Mage::helper('catalog/product_url')->format($str)));
        $urlKey = trim($urlKey, '-');

        return $urlKey;
    }
    

免责声明

本模块绝对没有任何保证。

许可证

MIT许可证

作者信息