I want to split the order into two parts. I created a custom attribute called custom_order. One will contain only products with custom_order has set to Yes and the Other order with only products with custom_order set to No.
1 Answer
Add below code in your helper: app/code/YourCustomOrder/YourCustomAttribute/Helper/Data.php
<?php namespace YourCustomOrder\YourCustomAttribute\Helper; ... use Magento\Framework\App\Helper\AbstractHelper; use Magento\Customer\Model\Session as CustomerSession; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Helper\Context; class Data extends AbstractHelper { ... protected $customerRepository; public function __construct( ... CustomerSession $customerSession, CustomerRepositoryInterface $customerRepository, Context $context ) { ... $this->customerSession = $customerSession; $this->customerRepository = $customerRepository; parent::__construct($context); } ... public function getCustomOrderAttributeValue() { $customerId = $this->customerSession->getCustomer()->getId(); $customer = $this->customerRepository->getById($customerId); return $customer->getCustomAttribute('custom_order')->getValue(); } } And modify your template file in the following way:
<?php $dataHelper = $this->helper('YourCustomOrder\YourCustomAttribute\Helper\Data'); $customOrderAttribute = $dataHelper->getCustomOrderAttributeValue(); if ($customOrderAttribute == "Yes" || $customOrderAttribute == 1) { # Get orders with only products with 'custom_order' attribute has set to Yes } else { # Get orders with only products with 'custom_order' attribute has set to No } ?> - Thanks for answering. I think you understood my questions wrong. I want to split order based on product attributes when the order is placed. When you checkout two items one with custom order 'Yes' and other with custom order 'No' two orders should be placed instead of onepon aravind– pon aravind2021-11-05 06:19:39 +00:00Commented Nov 5, 2021 at 6:19