【问题标题】:I duplicated products magento and my urls are product-1.html product-2.html我复制了 magento 产品,我的网址是 product-1.html product-2.html
【发布时间】:2014-12-19 16:29:51
【问题描述】:

我已经创建了我的 magento 商店(社区) 我在很多产品上都使用了重复的产品,但我没有意识到我认为我可以自行解决的每个产品的 URL 键字段都必须更改。

现在我有大约 100 种产品,不幸的是它们现在被命名为示例:

/HaircolorBlack.html , /haircolorblack-1.html, /haircolorblack-2.html 等等。

我想知道是否有任何方法可以轻松地让 magento 在产品元标题之后重新创建 url?

这将非常有帮助。

我看到这篇两年前的帖子大约是同一件事,但我不想使用那个脚本,因为我不知道它是否会破坏我的 magento 中的任何内容,因为它已经更新了很多。这是链接:Clearing URL keys in Magento

我还需要关于将脚本放在哪里的完全白痴说明。对不起;)

非常感谢。

S

【问题讨论】:

  • 我尝试使用链接帖子中的脚本,但无法访问管理页面。一切都变成空白,但当我再次删除脚本时又恢复正常。

标签: magento url rewrite


【解决方案1】:

您可以使用 magento 本身创建一个一次性脚本。将此脚本添加到您的 magento 根文件夹中的某个位置(在 index.php 旁边):

<?php

  require_once "app/Mage.php";

  Mage::app('admin'); // must be admin to do changes

  function convertToUrlKey($string) {
    return $string; // I WILL LEAVE YOU TO SOLVE THIS PART
  }

  foreach(Mage::getModel('catalog/product')->getCollection() as $product):

     $metaTitle = $product->getMetaTitle();
     $urlKey = convertToUrlKey($metaTitle);

     try {
         $product->setUrlKey($urlKey);
         $product->save();
         echo "Assigned url key {$urlKey} to {$product->getName()}.\n";
     } catch(Exception $ex) {
        echo "ERROR: {$ex->getMessage()}";
     }

  endforeach;

显然这不是一个完整的解决方案,因为您必须重新创建 convertToUrlKey 函数才能正确地将“Black Hair Color”转换为“black-hair-color”,并确保不会出现生成了重复的 url 键..

您可以通过浏览或通过 SSH 运行脚本来运行:

$ cd magentoProject
$ php -f changeUrlkeys.php

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多