0

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 1

0

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
    }
?>
1
  • 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 one Nov 5, 2021 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.