1

I'm trying to implement @jsacksick solution which should force displaying shipping costs on cart page (normally it doesn't exist at that step yet). I created a new module for this and it's structure is simple:

shipping_fix
  src
    ShippingOrderProcessor.php
  shipping_fix.info.yml
  shipping_fix.module
  shipping_fix.services.yml

ShippingOrderProcessor.php is exact copy of @jsacksick class: https://gist.github.com/jsacksick/fde031197df92236ef5a916775e17a2e

info file contains:

name: Shipping fix
description: Fixes missing shipping info on cart page
type: module
core: 8.x
dependencies:

module file is empty and services file contains:

services:
  shipping_fix.shipping_order_processor:
    class: Drupal\shipping_fix\ShippingOrderProcessor
    tags:
      - { name: commerce_shipping.shipping_order_processor, priority: -300 }

But it's not working. I tried setting break points inside __construct() and process() methods of that class, but they are never reached.

Tried changing last row here to:

 - { name: commerce_order.order_processor, priority: -300 }

as explained here: https://docs.drupalcommerce.org/commerce2/developer-guide/orders/order-refresh-and-process

but then my site crashes when I try to clear the cache?

So to me it looks like that I didn't register this processor object well. Most likely problem is in services file, but I can't figure out what it is ("commerce_shipping.shipping_order_processor" is correct value?).

Tried dumping services with drush like:

drush devel:services
drush devel-container-services
drush devel-services

and even devel mode is turned on for each try I get: Command "devel-container-services" is not defined. or similar.

I activated the my module of course, tried clearing caches, but didn't help.

Update: The error which I get when I change last row of services file to:

 - { name: commerce_order.order_processor, priority: -300 }

is:

Service 'shipping_fix.shipping_order_processor' for consumer 'commerce_order.order_refresh' does not implement Drupal\commerce_order\OrderProcessorInterface.

And ShippingOrderProcess.php file starts with:

<?php declare(strict_types=1);

namespace Drupal\my_module\OrderProcessor;

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\OrderProcessorInterface;
use Drupal\commerce_shipping\ShipmentManagerInterface;
use Drupal\commerce_shipping\ShippingOrderManagerInterface;
use Drupal\profile\Entity\Profile;

/**
 * Ensures there are shipments from the start.
 */
final class ShippingProcessor implements OrderProcessorInterface {

  /**
   * The shipping order manager.
   *
   * @var \Drupal\commerce_shipping\ShippingOrderManagerInterface
   */
  protected $shippingOrderManager;

  /**
   * The shipment manager.
   *
   * @var \Drupal\commerce_shipping\ShipmentManagerInterface
   */
  protected $shipmentManager;


  public function __construct(ShippingOrderManagerInterface $shippingOrderManager, ShipmentManagerInterface $shipmentManager) {
    $this->shippingOrderManager = $shippingOrderManager;
    $this->shipmentManager = $shipmentManager;
  }

...

Update 2:

Managed to clear the cache: For my file structure name space has to be:

namespace Drupal\shipping_fix;

Also changed servies file and now it looks like:

services:
  shipping_fix.shipping_order_processor:
    class: Drupal\shipping_fix\ShippingProcessor
    arguments: ['@commerce_shipping.order_manager', '@commerce_shipping.shipment_manager']
    tags:
      - { name: commerce_order.order_processor, priority: -300 }

Now cache clearing works, but I still don't see shipping costs on cart page...

5
  • but then my site crashes when I try to clear the cache? what error do you get?
    – No Sssweat
    Oct 21 '20 at 10:24
  • "Service 'shipping_fix.shipping_order_processor' for consumer 'commerce_order.order_refresh' does not implement Drupal\commerce_order\OrderProcessorInterface." ?!?
    – MilanG
    Oct 21 '20 at 11:21
  • 1
    In ShippingOrderProcessor.php you probably have namespace Drupal\my_module\OrderProcessor; and forgot to replace the my_module part with shipping_fix.
    – No Sssweat
    Oct 21 '20 at 11:33
  • Yes, that was the case, but do I have also to pass somehow those parameters for the constructor?
    – MilanG
    Oct 21 '20 at 11:35
  • Should I add something like: arguments: ['@commerce_shipping.order_manager', '@commerce_shipping.shipment_manager']
    – MilanG
    Oct 21 '20 at 11:43
0

enter image description here

In this case, you'll want to run this before the commerce_shipping.early_order_processor, set priority to 300

services:
  shipping_fix.shipping_order_processor:
    class: Drupal\shipping_fix\ShippingProcessor
    arguments: ['@commerce_shipping.order_manager', '@commerce_shipping.shipment_manager']
    tags:
      - { name: commerce_order.order_processor, priority: 300 }
1
  • I'm afraid to say it (after all this trouble) but it seems to work! Thank you so much for helping me!
    – MilanG
    Oct 22 '20 at 8:50

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.