laravel / cashier-mollie

MIT License
375 stars 63 forks source link

Overriding Order Number Generator #139

Closed mirkin-pixel closed 4 years ago

mirkin-pixel commented 4 years ago

I made my own OrderNumberGenrator like this:

<?php

namespace App\Payments;

use Laravel\Cashier\Order\Order;
use Laravel\Cashier\Order\OrderNumberGenerator;

class OwnOrderNumberGenerator extends OrderNumberGenerator
{

    protected $offset;
    /**
     * OrderNumberGenerator constructor.
     */
    public function __construct()
    {
        $this->offset = config('cashier.order_number_generator.offset');
    }
    /**
     * Generate an order reference.
     *
     * @return string
     */

    public function generate()
    {
        $number = str_pad(
            $this->offset + Order::count() + 1,
            4,
            '0',
            STR_PAD_LEFT
        );
        $numbers = str_split($number, 4);
        return now()->month .'-'. now()->year . ' '. implode('-',[
            now()->year,
            $numbers[0],
            $numbers[1],
        ]);
    }
}

In config/cashier.php I changed this line: 'model' => \Laravel\Cashier\Order\OrderNumberGenerator::class, to: 'model' => \App\Payments\OwnOrderNumberGenerator::class,

But it wont work, the order numbers are the same as the OrderNumberGenerator from the package..

sandervanhooft commented 4 years ago

Hi @mirkin1993,

Have you tried clearing the config cache?

php artisan config:clear
mirkin-pixel commented 4 years ago

Hi @mirkin1993,

Have you tried clearing the config cache?

php artisan config:clear

Yes I did, but it didn’t work..

sandervanhooft commented 4 years ago

Thanks @mirkin1993 . I've just confirmed the issue. Working on a fix now.