1212use Magento \Framework \Api \AttributeValueFactory ;
1313use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
1414use Magento \Framework \App \ObjectManager ;
15+ use Magento \Framework \DataObject ;
1516use Magento \Framework \Exception \NoSuchEntityException ;
1617use Magento \Framework \Model \AbstractExtensibleModel ;
1718use Magento \Quote \Api \Data \PaymentInterface ;
@@ -1619,7 +1620,7 @@ public function addItem(\Magento\Quote\Model\Quote\Item $item)
16191620 * Add product. Returns error message if product type instance can't prepare product.
16201621 *
16211622 * @param mixed $product
1622- * @param null|float|\Magento\Framework\ DataObject $request
1623+ * @param null|float|DataObject $request
16231624 * @param null|string $processMode
16241625 * @return \Magento\Quote\Model\Quote\Item|string
16251626 * @throws \Magento\Framework\Exception\LocalizedException
@@ -1637,11 +1638,12 @@ public function addProduct(
16371638 if (is_numeric ($ request )) {
16381639 $ request = $ this ->objectFactory ->create (['qty ' => $ request ]);
16391640 }
1640- if (!$ request instanceof \ Magento \ Framework \ DataObject) {
1641+ if (!$ request instanceof DataObject) {
16411642 throw new \Magento \Framework \Exception \LocalizedException (
16421643 __ ('We found an invalid request for adding product to quote. ' )
16431644 );
16441645 }
1646+ $ invalidProductAddFlag = $ this ->checkForInvalidProductAdd ($ request );
16451647
16461648 if (!$ product ->isSalable ()) {
16471649 throw new \Magento \Framework \Exception \LocalizedException (
@@ -1699,7 +1701,7 @@ public function addProduct(
16991701
17001702 // collect errors instead of throwing first one
17011703 if ($ item ->getHasError ()) {
1702- if (!$ request -> getForceAddToCart () ) {
1704+ if (!$ invalidProductAddFlag ) {
17031705 $ this ->deleteItem ($ item );
17041706 }
17051707 foreach ($ item ->getMessage (false ) as $ message ) {
@@ -1719,6 +1721,20 @@ public function addProduct(
17191721 return $ parentItem ;
17201722 }
17211723
1724+ /**
1725+ * Checks if invalid products should be added to quote
1726+ *
1727+ * @param DataObject $request
1728+ * @return bool
1729+ */
1730+ private function checkForInvalidProductAdd (DataObject $ request ): bool
1731+ {
1732+ $ forceAdd = $ request ->getAddToCartInvalidProduct ();
1733+ $ request ->unsetData ('add_to_cart_invalid_product ' );
1734+
1735+ return (bool ) $ forceAdd ;
1736+ }
1737+
17221738 /**
17231739 * Adding catalog product object data to quote
17241740 *
@@ -1774,8 +1790,8 @@ protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $
17741790 * For more options see \Magento\Catalog\Helper\Product->addParamsToBuyRequest()
17751791 *
17761792 * @param int $itemId
1777- * @param \Magento\Framework\ DataObject $buyRequest
1778- * @param null|array|\Magento\Framework\ DataObject $params
1793+ * @param DataObject $buyRequest
1794+ * @param null|array|DataObject $params
17791795 * @return \Magento\Quote\Model\Quote\Item
17801796 * @throws \Magento\Framework\Exception\LocalizedException
17811797 *
@@ -1797,9 +1813,9 @@ public function updateItem($itemId, $buyRequest, $params = null)
17971813 $ product = clone $ this ->productRepository ->getById ($ productId , false , $ this ->getStore ()->getId ());
17981814
17991815 if (!$ params ) {
1800- $ params = new \ Magento \ Framework \ DataObject ();
1816+ $ params = new DataObject ();
18011817 } elseif (is_array ($ params )) {
1802- $ params = new \ Magento \ Framework \ DataObject ($ params );
1818+ $ params = new DataObject ($ params );
18031819 }
18041820 $ params ->setCurrentConfig ($ item ->getBuyRequest ());
18051821 $ buyRequest = $ this ->_catalogProduct ->addParamsToBuyRequest ($ buyRequest , $ params );
@@ -2148,7 +2164,7 @@ protected function _clearErrorInfo()
21482164 * @param string|null $origin Usually a name of module, that embeds error
21492165 * @param int|null $code Error code, unique for origin, that sets it
21502166 * @param string|null $message Error message
2151- * @param \Magento\Framework\ DataObject|null $additionalData Any additional data, that caller would like to store
2167+ * @param DataObject|null $additionalData Any additional data, that caller would like to store
21522168 * @return $this
21532169 */
21542170 public function addErrorInfo (
0 commit comments