Open
Description
Summary (*)
This is a Developer experience issue. I have created one simple console file that will generate product name, URL etc.
- Magento 2.3.x with sample data
- Use Web Server Rewrites field set to No
- Clear cache if prompted
Examples (*)
- app/code/Custom/Pro/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Console\CommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="checkProductURL" xsi:type="object">Custom\Pro\Console\Command\ProductURLFetch</item>
</argument>
</arguments>
</type>
</config>
- app/code/Custom/Pro/Console/Command/ProductURLFetch.php
<?php
namespace Custom\Pro\Console\Command;
use Magento\Catalog\Api\ProductRepositoryInterfaceFactory;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\App\State;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ProductURLFetch extends \Symfony\Component\Console\Command\Command
{
/**
* @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface
*/
protected $productAttributeRepository;
/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* @var \Magento\Catalog\Model\ResourceModel\Attribute
*/
protected $attributeResource;
/**
* @var State
*/
protected $appState;
protected $_productRepositoryFactory;
/**
* @var \Magento\Framework\EntityManager\EntityMetadata
*/
protected $metadata;
/**
* Object manager factory
*
* @var ObjectManagerFactory
*/
private $objectManagerFactory;
/**
* @var CollectionFactory
*/
private $collectionFactory;
/**
* @param ObjectManagerFactory $objectManagerFactory
* @param CollectionFactory $collectionFactory
* @param State $appState
* @param ProductRepositoryInterfaceFactory $productRepositoryFactory
*/
public function __construct(
ObjectManagerFactory $objectManagerFactory,
CollectionFactory $collectionFactory,
State $appState,
ProductRepositoryInterfaceFactory $productRepositoryFactory
) {
$this->objectManagerFactory = $objectManagerFactory;
$this->appState = $appState;
$this->collectionFactory = $collectionFactory;
$this->_productRepositoryFactory = $productRepositoryFactory;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('catalog:product:showurl');
$this->setDescription('It will just show Product URLs.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
$productCollection = $this->collectionFactory->create();
$output->setDecorated(true);
$productCollection->addAttributeToSelect('name','sku','url');
try {
foreach ($productCollection as $product){
$output->writeln( $product->getProductURL() );
}
$output->writeln("<info>Product URLs has been generated..</info>");
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
} catch (\Exception $exception) {
$output->writeln("");
$output->writeln("<error>{$exception->getMessage()}</error>");
// we must have an exit code higher than zero to indicate something was wrong
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
}
}
}
Execute below console.
php bin/magento catalog:product:showurl
Output
URL in the output will be as follows:
http://www.example.com/magento/kir-1100.html
It should not contain 'magento' as in the URL.
http://www.example.com/kir-1100.html
Proposed solution
Looking into the file /vendor/magento/module-store/Model/Store.php
and function named _updatePathUseRewrites
returns base URL with 'magento'.
Metadata
Metadata
Assignees
Labels
Gate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentA defect with this priority could have functionality issues which are not to expectations.The issue has been reproduced on latest 2.4-develop branchAffects non-critical data or functionality and does not force users to employ a workaround.Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Type
Projects
Status
Pull Request In Progress