Skip to content

URL key for specified store already exists. #1225

Closed
@sivajik34

Description

@sivajik34

I have created command for product delete by given sku.its working fine except url rewrite.
for example i added product named "shirt123" in back end.and url key also shirt123.html
case 1:if i delete same product using my custom command in terminal..its deleted product.but in table url_rewrite still associated rows are existed.
if i try to add with same product name and url key i'm getting following error
" URL key for specified store already exists."
case 2:if i delete same product from back end ...all is well.
So problem is my code or its a magento bug?

registry = $registry; $this->_productRepository =$_productRepository; parent::__construct(); } /** - {@inheritdoc} */ protected function configure() { $this->setName('delete_product') ->setDescription('Delete the product by given sku')->setDefinition($this->getOptionsList()); parent::configure(); } public function getOptionsList() { return [ new InputArgument(self::SKU, InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'SKU') ]; } /** - {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getArgument(self::SKU)) { throw new \InvalidArgumentException('Missing Argument ' . self::SKU); } $this->registry->register('isSecureArea', true); $skus=$input->getArgument(self::SKU); foreach($skus as $sku) { $this->_productRepository->deleteById($sku); $output->writeln('product deleted, sku: ' . $sku . ''); } } }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions