I'm using cybersource Payment gateway for my Magento 2 install, the gateway require some Merchant Data fields to be populated with the oeder, one of the fields is the product category, currently i'm using the below method:
$name = $categories = []; foreach ($order->getAllVisibleItems() as $_item) { array_push($name, $_item->getName()); $product = $this->productModel->load($_item->getProductId()); $cats = $product->getCategoryIds(); foreach($cats as $cat){ $category = $this->categoryModel->load($cat); array_push($categories, $category->getName()); } }
Then i'm calling the category using
'product_category' => implode(',', $categories),
but the issue is, when i'm creating an order with more than one product from the same category lets say 3 products from the same category, it show in the response the categories 3 times, and in this way i receive an error in cybersource that the product category fields has an invalid value.
how to show only the product category only one time?
12-26-2022 05:18 AM