Been stuck for days trying to figure out the reason but I can’t locate it.
API always returns an error when I open the cart or add to the cart
main.CRITICAL: ReflectionException: Class "" does not exist in /var/www/vhosts/example.com/public_html/vendor/magento/framework/Webapi/ServiceInputProcessor.php:278
Stack trace:
#0 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Webapi/ServiceInputProcessor.php(278): ReflectionClass->__construct()
#1 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Webapi/ServiceInputProcessor.php(524): MagentoFrameworkWebapiServiceInputProcessor->_createFromArray()
#2 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Webapi/ServiceInputProcessor.php(200): MagentoFrameworkWebapiServiceInputProcessor->convertValue()
#3 /var/www/vhosts/example.com/public_html/vendor/magento/module-webapi/Controller/Rest/InputParamsResolver.php(115): MagentoFrameworkWebapiServiceInputProcessor->process()
#4 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoWebapiControllerRestInputParamsResolver->resolve()
#5 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(138): MagentoWebapiControllerRestInputParamsResolverInterceptor->___callParent()
#6 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoWebapiControllerRestInputParamsResolverInterceptor->MagentoFrameworkInterception{closure}()
#7 /var/www/vhosts/example.com/public_html/generated/code/Magento/Webapi/Controller/Rest/InputParamsResolver/Interceptor.php(23): MagentoWebapiControllerRestInputParamsResolverInterceptor->___callPlugins()
#8 /var/www/vhosts/example.com/public_html/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(85): MagentoWebapiControllerRestInputParamsResolverInterceptor->resolve()
#9 /var/www/vhosts/example.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(188): MagentoWebapiControllerRestSynchronousRequestProcessor->process()
#10 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoWebapiControllerRest->dispatch()
#11 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(138): MagentoWebapiControllerRestInterceptor->___callParent()
#12 /var/www/vhosts/example.com/public_html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoWebapiControllerRestInterceptor->MagentoFrameworkInterception{closure}()
#13 /var/www/vhosts/example.com/public_html/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(23): MagentoWebapiControllerRestInterceptor->___callPlugins()
#14 /var/www/vhosts/example.com/public_html/vendor/magento/framework/App/Http.php(116): MagentoWebapiControllerRestInterceptor->dispatch()
#15 /var/www/vhosts/example.com/public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): MagentoFrameworkAppHttp->launch()
#16 /var/www/vhosts/example.com/public_html/vendor/magento/framework/App/Bootstrap.php(264): MagentoFrameworkAppHttpInterceptor->launch()
#17 /var/www/vhosts/example.com/public_html/pub/index.php(30): MagentoFrameworkAppBootstrap->run()
#18 {main}
The custom webapi.xml
file
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<!-- <route url="/V1/carts/:cartId/updateCart" method="POST">
<service class="TAGCartManagerApiCartManagementInterface" method="updateCart"/>
<resources>
<resource ref="Magento_Cart::manage"/>
</resources>
</route> -->
<route url="/V2/get-details" method="GET">
<service class="NewCustomApiApiDetailsInterface" method="getData" />
<resources>
<!-- <resource ref="anonymous" /> -->
<resource ref="self" />
</resources>
</route>
<route url="/V2/customer/login" method="POST">
<service class="NewCustomApiApiCustomerInterface" method="login" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/login/socialmedia" method="POST">
<service class="NewCustomApiApiCustomerInterface" method="loginWithSocialMedia" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/logout" method="POST">
<service class="NewCustomApiApiCustomerInterface" method="logout" />
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
<route url="/V2/customer/me/profile" method="GET">
<service class="MagentoCustomerApiCustomerRepositoryInterface" method="getById" />
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
<route url="/V2/customer/me/profile" method="PUT">
<service class="MagentoCustomerApiCustomerRepositoryInterface" method="save" />
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="customer.id" force="true">%customer_id%</parameter>
</data>
</route>
<route url="/V2/customer/registration" method="POST">
<service class="MagentoCustomerApiAccountManagementInterface" method="createAccount" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/registration/socialmedia" method="POST">
<service class="NewCustomApiApiCustomerInterface" method="createAccountWithSocialMedia" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/resetPassword" method="POST">
<service class="MagentoCustomerApiAccountManagementInterface" method="resetPassword" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/rest/password" method="PUT">
<service class="MagentoCustomerApiAccountManagementInterface" method="initiatePasswordReset" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/customer/changePassword" method="PUT">
<service class="MagentoCustomerApiAccountManagementInterface" method="changePasswordById"/>
<resources>
<resource ref="self"/>
</resources>
</route>
<route url="/V2/customer/saveAddress" method="POST">
<service class="MagentoCustomerApiAddressRepositoryInterface" method="save"/>
<resources>
<resource ref="self"/>
</resources>
</route>
<route url="/V2/customer/deleteAddress" method="DELETE">
<service class="MagentoCustomerApiAddressRepositoryInterface" method="deleteById"/>
<resources>
<resource ref="self"/>
</resources>
</route>
<!-- Products Functions -->
<!-- get all products details -->
<route url="/V2/products" method="GET">
<service class="NewCustomApiApiProductInterface" method="getList" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- search products -->
<route url="/V2/searchProducts" method="GET">
<service class="MagentoCatalogApiProductRepositoryInterface" method="getList" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/products/search/:value" method="GET">
<service class="NewCustomApiApiProductInterface" method="searchProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get product details by product id -->
<route url="/V2/products/:id" method="GET">
<service class="NewCustomApiApiProductInterface" method="getProductById" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/products/instock" method="GET">
<service class="NewCustomApiApiProductInterface" method="isInStock" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get product details by product sku -->
<route url="/V2/products/sku" method="GET">
<service class="NewCustomApiApiProductInterface" method="getProductBySku" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get configurable product details -->
<route url="/V2/configurable-products/:sku/details" method="GET">
<service class="NewCustomApiApiProductInterface" method="getProductConfigurableDetails" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get configurable product children -->
<route url="/V2/configurable-products/:sku/children" method="GET">
<service class="MagentoConfigurableProductApiLinkManagementInterface" method="getChildren" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get configurable product options -->
<route url="/V2/configurable-products/:sku/options" method="GET">
<service class="MagentoConfigurableProductApiOptionRepositoryInterface" method="getList" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get configurable product details -->
<route url="/V2/bundle-products/:sku/details" method="GET">
<service class="NewCustomApiApiProductInterface" method="getProductBundleDetails" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get bundle product children -->
<route url="/V2/bundle-products/:productSku/children" method="GET">
<service class="MagentoBundleApiProductLinkManagementInterface" method="getChildren" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get bundle product options -->
<route url="/V2/bundle-products/:sku/options" method="GET">
<service class="MagentoBundleApiProductOptionRepositoryInterface" method="getList" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get Featured products -->
<route url="/V2/products/featured" method="GET">
<service class="NewCustomApiApiProductInterface" method="getFeaturedProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get Best Seller products -->
<route url="/V2/products/bestseller" method="GET">
<service class="NewCustomApiApiProductInterface" method="getBestSellersProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get Special Offer products -->
<route url="/V2/products/specialoffer" method="GET">
<service class="NewCustomApiApiProductInterface" method="getSpecialOfferProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get product attributeId by code-->
<route url="/V2/products/attributeid/:attrCode" method="GET">
<service class="NewCustomApiApiProductInterface" method="getAttributeId" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get product attributevalue by valueIndex-->
<route url="/V2/products/attributevalue/:attrId" method="GET">
<service class="NewCustomApiApiProductInterface" method="getAttributeValue" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get categories tree -->
<route url="/V2/categoriestree" method="GET">
<service class="MagentoCatalogApiCategoryManagementInterface" method="getTree" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get categories -->
<route url="/V2/categories" method="GET">
<service class="NewCustomApiApiProductInterface" method="getCategories" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get product details by category id -->
<route url="/V2/categories/:categoryId/products" method="GET">
<service class="NewCustomApiApiProductInterface" method="getCategoryProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- Checkout APIs -->
<!-- Create empty cart for guest-->
<route url="/V2/checkout/createGuestCart" method="POST">
<service class="MagentoQuoteApiCartManagementInterface" method="createEmptyCart" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- Create empty cart for customer-->
<route url="/V2/checkout/:customerId/cart" method="POST">
<service class="NewCustomApiApiCheckoutInterface" method="createCustomerEmptyCart" />
<resources>
<resource ref="self" />
</resources>
</route>
<!-- add to cart -->
<route url="/V2/checkout/cart/add" method="POST">
<service class="MagentoQuoteApiCartItemRepositoryInterface" method="save" />
<resources>
<resource ref="anonymous" />
</resources>
<data>
<parameter name="cartId" force="true">%cart_id%</parameter>
</data>
</route>
<!-- override cart -->
<route url="/V2/checkout/cart/:cartId/add/:itemId" method="PUT">
<service class="MagentoQuoteApiCartItemRepositoryInterface" method="save" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- remove from cart -->
<route url="/V2/checkout/cart/:cartId/delete" method="DELETE">
<service class="MagentoQuoteApiCartItemRepositoryInterface" method="deleteById" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/checkout/cart/:cartId/deleteAll" method="DELETE">
<service class="NewCustomApiApiCheckoutInterface" method="removeCartItems" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get cart items -->
<route url="/V2/checkout/cart/:cartId/items" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getCartItems" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- override cart by product id-->
<route url="/V2/checkout/cart/overridebyproduct" method="PUT">
<service class="NewCustomApiApiCheckoutInterface" method="overrideCartItemByProductId" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get cart totals -->
<route url="/V2/checkout/cart/:cartId/totals" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getCartTotals" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- assign cart to customer -->
<route url="/V2/checkout/assigncustomer/:cartId" method="PUT">
<service class="NewCustomApiApiCheckoutInterface" method="assignCustomer" />
<resources>
<resource ref="self" />
</resources>
</route>
<!-- get shipment method based on address -->
<route url="/V2/checkout/shipping-information/:cartId/methods" method="POST">
<service class="MagentoQuoteApiShipmentEstimationInterface" method="estimateByExtendedAddress" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- save shipping information -->
<route url="/V2/checkout/shipping-information/:cartId/save" method="POST">
<service class="NewCustomApiApiCheckoutInterface" method="saveAddressInformation" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- Managing shipping guest information -->
<!--<route url="/V2/checkout/guest-carts/shipping-information/:cartId/save" method="POST">-->
<!-- <service class="NewCustomApiApiCheckoutInterface" method="saveGuestAddressInformation"/>-->
<!-- <resources>-->
<!-- <resource ref="anonymous" />-->
<!-- </resources>-->
<!--</route>-->
<!-- apply shipping information -->
<route url="/V2/checkout/shipping-information/:cartId/applymethod" method="POST">
<service class="NewCustomApiApiCheckoutInterface" method="set" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- Place Order -->
<route url="/V2/checkout/placeOrder" method="PUT">
<service class="NewCustomApiApiCheckoutInterface" method="placeOrder" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/checkout/orders" method="GET">
<!-- <service class="MagentoSalesApiOrderRepositoryInterface" method="getList" /> -->
<service class="NewCustomApiApiCheckoutInterface" method="getOrders"/>
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/checkout/defaultcountry" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getDefaultCountryCode" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/checkout/regions/:countryCode" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getRegions" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- start custom for example.com -->
<route url="/V2/checkout/cities/:regionId" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getCities" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/checkout/areas/:cityId" method="GET">
<service class="NewCustomApiApiCheckoutInterface" method="getAreas" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- end custom for example.com -->
<!-- Wishlist APIs -->
<route url="/V2/wishlist/items" method="GET">
<service class="NewCustomApiApiWishlistManagementInterface" method="getWishlistForCustomer" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/wishlist/add/:productId" method="POST">
<service class="NewCustomApiApiWishlistManagementInterface" method="addWishlistForCustomer" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/wishlist/remove/:itemId" method="DELETE">
<service class="NewCustomApiApiWishlistManagementInterface" method="removeWishlistItem" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/wishlist/removeAll/:customerId" method="DELETE">
<service class="NewCustomApiApiWishlistManagementInterface" method="removeWishlistItems" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/wishlist/remove/:itemId" method="DELETE">
<service class="NewCustomApiApiWishlistManagementInterface" method="removeWishlistItem" />
<resources>
<resource ref="self" />
</resources>
</route>
<route url="/V2/wishlist/item/in" method="GET">
<service class="NewCustomApiApiWishlistManagementInterface" method="isProductInWishlist" />
<resources>
<resource ref="self" />
</resources>
</route>
<!-- add to cart -->
<route url="/V2/wishlist/addAllCart" method="POST">
<service class="NewCustomApiApiWishlistManagementInterface" method="addAllToCart" />
<resources>
<resource ref="self" />
</resources>
</route>
<!-- GENERAL -->
<route url="/V2/currencies" method="GET">
<service class="MagentoDirectoryApiCurrencyInformationAcquirerInterface" method="getCurrencyInfo"/>
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get general information -->
<route url="/V2/general/information" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getGeneralInformation" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get banners -->
<route url="/V2/general/banners" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getBannersBySlider" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get CMS page content -->
<route url="/V2/general/pageContent" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getCmsPageDetails" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<!-- get CMS block content -->
<route url="/V2/general/blockContent" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getCmsBlockDetails" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/featuredcategories" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getFeaturedSubCategories" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/advertisement" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getAdvertisement" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/supplier" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getSupplier" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/contactus" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getContactUsDetails" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/sociallinks" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getSocialLinks" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V2/general/homeproducts" method="GET">
<service class="NewCustomApiApiGeneralInterface" method="getHomeProducts" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
</routes>
Method to get cart items
/**
* {@inheritdoc}
*/
public function getCartItems($cartId, $currencyCode)
{
$response = [];
$list = $this->cartItemRepository->getList($cartId);
$items = [];
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$mediaPath = $objectManager->get('MagentoStoreModelStoreManagerInterface')
->getStore()
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$totalQty = 0;
foreach ($list as $item) {
$data = [];
$data['item_id'] = $item->getItemId();
$data['id'] = $item->getProduct()->getId();
$data['name'] = $item->getName();
$data['qty'] = $item->getQty();
$data['sku'] = $item->getSku();
$data['price'] = $this->helper->convertPriceFromCurrentToAnotherCurrency($item->getPrice(), $currencyCode);
$image = $item->getProduct()->getData("image");
if ($image == null || $image == '')
$image = $item->getProduct()->getData("thumbnail");
if ($image != null && $image != '')
$data['image'] = $mediaPath . "catalog/product" . $item->getProduct()->getData("thumbnail");
else
$data['image'] = '';
$items[] = $data;
$totalQty += $item->getQty();
}
$response['items'] = $items;
$response['count'] = count($list);
$response['total_qty'] = $totalQty;
return [$response];
}