ฉันกำลังสร้างตลาดโดยใช้ Magento2 ด้วยเหตุนี้ฉันจึงจำเป็นต้องโหลดคำสั่งซื้อของลูกค้าโดยใช้ข้อมูลรับรองลูกค้าของผู้ขาย
ปัญหานี้คือ Magento2 ใช้ปลั๊กอินเพื่อตรวจสอบว่ามีเพียงลูกค้าของคำสั่งนี้ (หรือผู้ดูแลระบบ) ที่สามารถโหลดคำสั่งซื้อได้
isAllowed()ในกรณีนี้ผมต้องทั้งแทนที่ปลั๊กอินเป็นทั้งหมดหรือแทนที่วิธีการป้องกัน ฉันจะทำอย่างไรหากไม่มีการแก้ไขแกน
Magento\Sales\Model\ResourceModel\Order\Plugin\Authorization ดูเหมือนว่านี้:
use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class Authorization
{
    /**
     * @var UserContextInterface
     */
    protected $userContext;
    /**
     * @param UserContextInterface $userContext
     */
    public function __construct(
        \Magento\Authorization\Model\UserContextInterface $userContext
    ) {
        $this->userContext = $userContext;
    }
    /**
     * Checks if order is allowed
     *
     * @param \Magento\Sales\Model\ResourceModel\Order $subject
     * @param callable $proceed
     * @param \Magento\Framework\Model\AbstractModel $order
     * @param mixed $value
     * @param null|string $field
     * @return \Magento\Sales\Model\Order
     * @throws NoSuchEntityException
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function aroundLoad(
        \Magento\Sales\Model\ResourceModel\Order $subject,
        \Closure $proceed,
        \Magento\Framework\Model\AbstractModel $order,
        $value,
        $field = null
    ) {
        $result = $proceed($order, $value, $field);
        if (!$this->isAllowed($order)) {
            throw NoSuchEntityException::singleField('orderId', $order->getId());
        }
        return $result;
    }
    /**
     * Checks if order is allowed for current customer
     *
     * @param \Magento\Sales\Model\Order $order
     * @return bool
     */
    protected function isAllowed(\Magento\Sales\Model\Order $order)
    {
        return $this->userContext->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER
            ? $order->getCustomerId() == $this->userContext->getUserId()
            : true;
    }
}