How to fix the «Unique constraint violation found» / «Duplicate entry for key 'AMASTY_PGRID_QTY_SOLD_PRODUCT_ID'» bug in the Amasty's «Extended Product Grid with Editor» module?

Locate the Amasty\Pgrid\Model\Indexer\QtySold::doReindex() method.

Replace the $queryRemained = $this->connection->insertFromSelect($remainedProductsSelect, $table); line with the following code block:

$queryRemained = $this->connection->insertFromSelect(
	$remainedProductsSelect
	,$table
	,[]
	,\Magento\Framework\DB\Adapter\AdapterInterface::REPLACE
);

See also: