12
12
use Magento \Framework \Api \AttributeValueFactory ;
13
13
use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
14
14
use Magento \Framework \App \ObjectManager ;
15
+ use Magento \Framework \DataObject ;
15
16
use Magento \Framework \Exception \NoSuchEntityException ;
16
17
use Magento \Framework \Model \AbstractExtensibleModel ;
17
18
use Magento \Quote \Api \Data \PaymentInterface ;
@@ -1619,7 +1620,7 @@ public function addItem(\Magento\Quote\Model\Quote\Item $item)
1619
1620
* Add product. Returns error message if product type instance can't prepare product.
1620
1621
*
1621
1622
* @param mixed $product
1622
- * @param null|float|\Magento\Framework\ DataObject $request
1623
+ * @param null|float|DataObject $request
1623
1624
* @param null|string $processMode
1624
1625
* @return \Magento\Quote\Model\Quote\Item|string
1625
1626
* @throws \Magento\Framework\Exception\LocalizedException
@@ -1637,11 +1638,12 @@ public function addProduct(
1637
1638
if (is_numeric ($ request )) {
1638
1639
$ request = $ this ->objectFactory ->create (['qty ' => $ request ]);
1639
1640
}
1640
- if (!$ request instanceof \ Magento \ Framework \ DataObject) {
1641
+ if (!$ request instanceof DataObject) {
1641
1642
throw new \Magento \Framework \Exception \LocalizedException (
1642
1643
__ ('We found an invalid request for adding product to quote. ' )
1643
1644
);
1644
1645
}
1646
+ $ invalidProductAddFlag = $ this ->checkForInvalidProductAdd ($ request );
1645
1647
1646
1648
if (!$ product ->isSalable ()) {
1647
1649
throw new \Magento \Framework \Exception \LocalizedException (
@@ -1699,7 +1701,7 @@ public function addProduct(
1699
1701
1700
1702
// collect errors instead of throwing first one
1701
1703
if ($ item ->getHasError ()) {
1702
- if (!$ request -> getForceAddToCart () ) {
1704
+ if (!$ invalidProductAddFlag ) {
1703
1705
$ this ->deleteItem ($ item );
1704
1706
}
1705
1707
foreach ($ item ->getMessage (false ) as $ message ) {
@@ -1719,6 +1721,20 @@ public function addProduct(
1719
1721
return $ parentItem ;
1720
1722
}
1721
1723
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
+
1722
1738
/**
1723
1739
* Adding catalog product object data to quote
1724
1740
*
@@ -1774,8 +1790,8 @@ protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $
1774
1790
* For more options see \Magento\Catalog\Helper\Product->addParamsToBuyRequest()
1775
1791
*
1776
1792
* @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
1779
1795
* @return \Magento\Quote\Model\Quote\Item
1780
1796
* @throws \Magento\Framework\Exception\LocalizedException
1781
1797
*
@@ -1797,9 +1813,9 @@ public function updateItem($itemId, $buyRequest, $params = null)
1797
1813
$ product = clone $ this ->productRepository ->getById ($ productId , false , $ this ->getStore ()->getId ());
1798
1814
1799
1815
if (!$ params ) {
1800
- $ params = new \ Magento \ Framework \ DataObject ();
1816
+ $ params = new DataObject ();
1801
1817
} elseif (is_array ($ params )) {
1802
- $ params = new \ Magento \ Framework \ DataObject ($ params );
1818
+ $ params = new DataObject ($ params );
1803
1819
}
1804
1820
$ params ->setCurrentConfig ($ item ->getBuyRequest ());
1805
1821
$ buyRequest = $ this ->_catalogProduct ->addParamsToBuyRequest ($ buyRequest , $ params );
@@ -2148,7 +2164,7 @@ protected function _clearErrorInfo()
2148
2164
* @param string|null $origin Usually a name of module, that embeds error
2149
2165
* @param int|null $code Error code, unique for origin, that sets it
2150
2166
* @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
2152
2168
* @return $this
2153
2169
*/
2154
2170
public function addErrorInfo (
0 commit comments