0

This method only applies the url rewrite to store of id 1 when I checked url_rewrite table.

Before I call the removeSuffix() method I also create 2 more store views in a method, but none of them are used for url rewrite.

public function removeSuffix()
{
    $this->_appState->setAreaCode('adminhtml');

    $config = $this->_configFactory->create();
    $config->setDataByPath('catalog/seo/product_url_suffix', '');
    $config->save();

    $config = $this->_configFactory->create();
    $config->setDataByPath('catalog/seo/category_url_suffix', '');
    $config->save();
}

enter image description here

How do I get the url rewrite to apply to all stores in the script?

1 Answer 1

0

You need to use backend model of url suffix (see app/code/Magento/CatalogUrlRewrite/etc/adminhtml/system.xml):

\Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix

/** @var \Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix $urlRewriteSuffix */
$urlRewriteSuffix->load('catalog/seo/product_url_suffix', 'path');
$urlRewriteSuffix->setValue('');
$urlRewriteSuffix->save();

But before run this, be sure that config data was initialized with default values (e.g. just save system configuration in admin)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.