I have the next error when a product is added to the cart:
Requested product doesn't exist
This comes from the following method:
\Magento\Catalog\Model\ProductRepository
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
{
$cacheKey = $this->getCacheKey([$editMode, $storeId]);
if (!isset($this->instancesById[$productId][$cacheKey]) || $forceReload) {
$product = $this->productFactory->create();
if ($editMode) {
$product->setData('_edit_mode', true);
}
if ($storeId !== null) {
$product->setData('store_id', $storeId);
}
$this->logger->debug('Repo2' . $productId);
$product->load($productId); // $this->logger->debug(var_export(get_class_methods($product), true));
if ($productId == '') {
return nulL;
}
if (!$product->getId()) {
throw new NoSuchEntityException(__('Requested product doesn\'t exist'));
}
$this->cacheProduct($cacheKey, $product);
}
return $this->instancesById[$productId][$cacheKey];
}
With the logger I see that three calls are made and the third the $productId has no value and skip the exception
log:
I need to know where the third call is made to see the values it sends.
EDIT:
I have found the third call, it is at the time of validating the sales-rule:
This returns a null object:
$product = $model->getProduct();
\Magento\SalesRule\Model\Rule\Condition\Product
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
//@todo reimplement this method when is fixed MAGETWO-5713
/** @var \Magento\Catalog\Model\Product $product */
$product = $model->getProduct();
$this->logger->debug(var_export(get_class_methods($product), true));
if (!$product instanceof \Magento\Catalog\Model\Product) {
$product = $this->productRepository->getById($model->getProductId());
}
$product->setQuoteItemQty(
$model->getQty()
)->setQuoteItemPrice(
$model->getPrice() // possible bug: need to use $model->getBasePrice()
)->setQuoteItemRowTotal(
$model->getBaseRowTotal()
);
$attrCode = $this->getAttribute();
if ($attrCode === 'category_ids') {
return $this->validateAttribute($this->_getAvailableInCategories($product->getId()));
}
if ($attrCode === 'quote_item_price') {
$numericOperations = $this->getDefaultOperatorInputByType()['numeric'];
if (in_array($this->getOperator(), $numericOperations)) {
$this->setData('value', $this->getFormattedPrice($this->getValue()));
}
}
return parent::validate($product);
}
I have the same error but if I comment all the code and return directly true it is possible to add products to the checkout. But it is not a good solution since here it validates the offers.