<p>the adjuster had the wrong namespace, changing it to:</p>

<p><code>namespace hendrikeng\friendsdiscount\adjusters</code></p>

<p>fixed the issue</p>

CC BY-SA 4.0
2018-09-12T16:33:18.687Z
2018-09-12T16:33:18.687Z
HendrikEng
<p>I wrote a little commerce 2 price adjuster that works fine if i place it in 
<code>/vendor/craftcms/commerce/src/adjusters/FriendsDiscountAdjuster.php</code> and register it manually in <code>/vendor/craftcms/commerce/src/services/OrderAdjustments.php</code> </p>

<p>However, i wanted to port it to a plugin, but i do fail registering the adjuster to commerce.</p>

<p>I placed the adjuster in my <code>vendor/pluginName/src/adjusters/</code> folder 
and added it to my plugin. </p>

<p>It fails with:
<code>Cannot declare class craft\commerce\adjusters\FriendsDiscountAdjuster, because the name is already in use</code></p>

<p>this is my main plugin file Friendsdiscount.php:</p>

<pre><code>&lt;?php
namespace hendrikeng\friendsdiscount;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\commerce\services\OrderAdjustments;
use craft\events\RegisterComponentTypesEvent;
use hendrikeng\friendsdiscount\adjusters\FriendsDiscountAdjuster;

use yii\base\Event;

class Friendsdiscount extends Plugin
{
    public static $plugin;

    public $schemaVersion = '1.0.0';

    public function init()
    {
        parent::init();
        self::$plugin = $this;

        Event::on(
            OrderAdjustments::class,
            OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS,
            function(RegisterComponentTypesEvent $event) {
                $event-&gt;types[] = FriendsDiscountAdjuster::class;
            }
        );
    }
}
</code></pre>

<p>the src/adjusters/FriendDiscountAdjuster.php:</p>

<pre><code>&lt;?php

namespace craft\commerce\adjusters;

use Craft;
use craft\commerce\base\AdjusterInterface;
use craft\commerce\elements\Order;
use craft\commerce\models\OrderAdjustment;
use craft\commerce\Plugin;

class FriendsDiscountAdjuster implements AdjusterInterface
{
  // ...Adjust something
}
</code></pre>

<craft3><plugin-craftcommerce2>
Using a custom Commerce 2 Adjuster in a Craft Plugin
# Using a custom Commerce 2 Adjuster in a Craft Plugin

(Asked by: username_0 on 2018-09-11)

I wrote a little commerce 2 price adjuster that works fine if i place it in 
/vendor/craftcms/commerce/src/adjusters/FriendsDiscountAdjuster.php and register it manually in /vendor/craftcms/commerce/src/services/OrderAdjustments.php 
However, i wanted to port it to a plugin, but i do fail registering the adjuster to commerce.
I placed the adjuster in my vendor/pluginName/src/adjusters/ folder 
and added it to my plugin. 
It fails with:
Cannot declare class craft\commerce\adjusters\FriendsDiscountAdjuster, because the name is already in use
this is my main plugin file Friendsdiscount.php:
types[] = FriendsDiscountAdjuster::class;
            }
        );
    }
}

the src/adjusters/FriendDiscountAdjuster.php:

**Tags:** craft3, plugin-craftcommerce2

---

## 1 answers

### Answer by username_0 on 2018-09-12. Score: 2 | Accepted answer

the adjuster had the wrong namespace, changing it to:

`namespace hendrikeng\friendsdiscount\adjusters`

fixed the issue


---

