1

I'm basically having this problem Getting started with Order Adjuster plugin

I have the file plugins/carbonbalance/carbonBalancePlugin.php containing;

<?php

namespace Craft;
Craft::import('plugins.carbonbalance.adjusters.carbonBalanceAdjuster');

class CarbonBalancePlugin extends BasePlugin {

    ... usual standard plugin methods ...

    public function init()
    {       
    }

    public function commerce_registerOrderAdjusters()
    {
        return [
            new CarbonBalanceAdjuster
        ];
    }

}

and then in plugins/carbonbalance/adjusters/carbonBalanceAdjuster.php I have

<?php

namespace Commerce\Adjusters;
use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class CarbonBalanceAdjuster implements Commerce_AdjusterInterface {

    public function adjust(Commerce_OrderModel &$order, array $lineItems = []){

    $myAdjuster = new Commerce_OrderAdjustmentModel();

    return [$myAdjuster];

   }

}

But I get the following error message

Class 'Craft\CarbonBalanceAdjuster' not found

I understand this is most likely a naming issue, but I cannot see where I'm going wrong in that respect.

Update I think I have got past this problem by using;

public function init()
    {       
        //Craft::import('plugins.carbonbalance.adjusters.carbonBalanceAdjuster');
        require_once('adjusters/carbonBalanceAdjuster.php');

    }

public function commerce_registerOrderAdjusters()
    {
        return [
            new \Commerce\Adjusters\CarbonBalanceAdjuster
        ];
    }

This appears to load the Adjuster, but shows other errors because I haven't yet completed the adjust method.

1

carbonBalanceAdjuster.php should be CarbonBalanceAdjuster.php since the name of the class is CarbonBalanceAdjuster and you're probably on a case-sensitive file system, which is why auto-loading can't find it.

The same goes for your other plugin files as well. You can use https://pluginfactory.io to generate boilerplate plugin code to help avoid case-sensitivity issues like this.

1
  • I'll give that a go, thanks. In the meantine, changing the registerOrderAdjusters method to use new \Commerce\Adjusters\CarbonBalanceAdjuster sorted it out.
    – foamcow
    Sep 13 '17 at 9:41

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.