0

I am seeking assistance with a specific task related to the admin order creation page in our system. Currently, the process involves navigating to Sales -> Orders -> Create new order -> Select the customer.

enter image description here

http://domainame.com/admin/sales/order_create/index/

However, I am looking to streamline this process by eliminating the store selection step. Our application operates with a single 'default store view,' and I would like to set this programmatically.

Any guidance on how to achieve this would be greatly appreciated.

Thank you in advance

1 Answer 1

0

Try the following way:

app/code/Vendor/Sales/etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Block\Adminhtml\Order\Create\Form">
        <plugin name="set_default_store_id_for_new_order" type="Vendor\Sales\Block\Adminhtml\Order\Create\Form" sortOrder="1"/>
    </type>
</config>

app/code/Vendor/Sales/Block/Adminhtml/Order/Create/Form.php

<?php

namespace Vendor\Sales\Block\Adminhtml\Order\Create;

use Magento\Sales\Block\Adminhtml\Order\Create\Form as BaseForm;
use Magento\Framework\Serialize\Serializer\Json;

class Form
{
    /**
     * @param Json $json
     */
    public function __construct(
        private Json $json
    ) {

    }

    /**
     * @param BaseForm $subject
     * @param $data
     * @return bool|string
     */
    public function afterGetOrderDataJson(
        BaseForm $subject,
        $data
    ) {
        $data = $this->json->unserialize($data);
        $data['store_id'] = 1;
        return $this->json->serialize($data);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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