Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'magento' adding in the URL when Use Web Server Rewrites set to NO using Console Command #25976

Open
sandip5678 opened this issue Dec 10, 2019 · 4 comments · May be fixed by #34639
Open

'magento' adding in the URL when Use Web Server Rewrites set to NO using Console Command #25976

sandip5678 opened this issue Dec 10, 2019 · 4 comments · May be fixed by #34639
Assignees
Labels
Component: CatalogUrlRewrite Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@sandip5678
Copy link

Summary (*)

This is a Developer experience issue. I have created one simple console file that will generate product name, URL etc.

  1. Magento 2.3.x with sample data
  2. Use Web Server Rewrites field set to No
  3. Clear cache if prompted

Examples (*)

  1. 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>
  1. 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'.

@m2-assistant
Copy link

m2-assistant bot commented Dec 10, 2019

Hi @sandip5678. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@sandip5678 do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Dec 10, 2019
@sandip5678 sandip5678 changed the title Magento adding 'magento' in URL when Use Web Server Rewrites set to NO using Console Command 'magento' adding in the URL when Use Web Server Rewrites set to NO using Console Command Dec 10, 2019
@krishprakash krishprakash added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Dec 11, 2019
@engcom-Charlie engcom-Charlie self-assigned this Dec 12, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 12, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Charlie engcom-Charlie added Component: CatalogUrlRewrite Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch labels Dec 13, 2019
@ghost ghost removed the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Dec 13, 2019
@ghost ghost unassigned engcom-Charlie Dec 13, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Dec 13, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-29753 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added this to Ready for Dev in Community Backlog Mar 24, 2020
@sdzhepa sdzhepa added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jul 16, 2020
ravi-chandra3197 added a commit to ravi-chandra3197/magento2 that referenced this issue Aug 29, 2020
@ghost ghost moved this from Ready for Dev to PR In Progress in Community Backlog Aug 29, 2020
@ghost ghost added Progress: PR in progress Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Priority: P3 May be fixed according to the position in the backlog. and removed Progress: ready for dev labels Aug 29, 2020
@sidolov sidolov added this to Ready for Development in Low Priority Backlog Sep 24, 2020
@m2-community-project m2-community-project bot moved this from Ready for Development to Pull Request In Progress in Low Priority Backlog Sep 24, 2020
@m2-community-project m2-community-project bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: PR in progress labels Sep 24, 2020
@ghost ghost unassigned ravi-chandra3197 Oct 8, 2020
@github-jira-sync-bot github-jira-sync-bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. and removed Priority: P3 May be fixed according to the position in the backlog. labels Oct 20, 2021
@m2-community-project m2-community-project bot added this to Ready for Development in High Priority Backlog Oct 20, 2021
@m2-community-project m2-community-project bot removed this from PR In Progress in Community Backlog Oct 20, 2021
@m2-community-project m2-community-project bot removed this from Pull Request In Progress in Low Priority Backlog Oct 20, 2021
@m2-community-project m2-community-project bot removed the Progress: PR Created Indicates that Pull Request has been created to fix issue label Oct 20, 2021
@rmsundar1
Copy link
Contributor

@magento I am working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CatalogUrlRewrite Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
High Priority Backlog
  
Pull Request In Progress
8 participants