Magento 2 xóa lô hàng theo chương trình

Sau đó, để thêm trường tùy chỉnh của bạn vào tổng số, hãy thử viết một plugin liên quan đến một phương thức công khai của lớp này, tôi nghĩ bạn có thể chọn

orderFactory = $orderFactory;
      $this->registry = $registry;
  }   
  public function Order(){
      $orderId = 'xyz';
      if(!$this->order){  
          $this->order = $this->orderFactory->create()->load($orderId);
      }
       return $this->order;
  }
  public function deleteInvoices(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_invoices = $this->Order()->getInvoiceCollection();

      if($_invoices){
          foreach($_invoices as $invoice){
              $invoice->delete();
          }
      }

  }
  /*
  * Shipemrnt delete
  */
  public function deleteShipments(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_shipments = $this->Order()->getShipmentsCollection();

      if($_shipments){
          foreach($_shipments as $_shipment){
              $_shipment->delete();
          }
      }

  }
      /*
  * Credit memo delete
  */
  public function deleteCreditmemos(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_creditmemos = $this->Order()->getCreditmemosCollection();

      if($_creditmemos){
          foreach($_creditmemos as $_creditmemo){
              $_creditmemo->delete();
          }
      }

  }   
}
7 hoặc
orderFactory = $orderFactory;
      $this->registry = $registry;
  }   
  public function Order(){
      $orderId = 'xyz';
      if(!$this->order){  
          $this->order = $this->orderFactory->create()->load($orderId);
      }
       return $this->order;
  }
  public function deleteInvoices(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_invoices = $this->Order()->getInvoiceCollection();

      if($_invoices){
          foreach($_invoices as $invoice){
              $invoice->delete();
          }
      }

  }
  /*
  * Shipemrnt delete
  */
  public function deleteShipments(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_shipments = $this->Order()->getShipmentsCollection();

      if($_shipments){
          foreach($_shipments as $_shipment){
              $_shipment->delete();
          }
      }

  }
      /*
  * Credit memo delete
  */
  public function deleteCreditmemos(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_creditmemos = $this->Order()->getCreditmemosCollection();

      if($_creditmemos){
          foreach($_creditmemos as $_creditmemo){
              $_creditmemo->delete();
          }
      }

  }   
}
8, theo cách này, trường tùy chỉnh của bạn sẽ được thêm vào mảng
orderFactory = $orderFactory;
      $this->registry = $registry;
  }   
  public function Order(){
      $orderId = 'xyz';
      if(!$this->order){  
          $this->order = $this->orderFactory->create()->load($orderId);
      }
       return $this->order;
  }
  public function deleteInvoices(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_invoices = $this->Order()->getInvoiceCollection();

      if($_invoices){
          foreach($_invoices as $invoice){
              $invoice->delete();
          }
      }

  }
  /*
  * Shipemrnt delete
  */
  public function deleteShipments(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_shipments = $this->Order()->getShipmentsCollection();

      if($_shipments){
          foreach($_shipments as $_shipment){
              $_shipment->delete();
          }
      }

  }
      /*
  * Credit memo delete
  */
  public function deleteCreditmemos(){

      if(!$this->Order()){
          return;
      }

      if($this->registry->registry('isSecureArea')){
          $this->registry->unregister('isSecureArea');
      }
      $this->registry->register('isSecureArea', true);

      $_creditmemos = $this->Order()->getCreditmemosCollection();

      if($_creditmemos){
          foreach($_creditmemos as $_creditmemo){
              $_creditmemo->delete();
          }
      }

  }   
}
9 và nó sẽ được in