justbetter/laravel-akeneo

This package is abandoned and no longer maintained. No replacement package was suggested.

Akeneo wrapper for Laravel

0.0.3 2022-05-20 08:46 UTC

This package is auto-updated.

Last update: 2024-10-11 15:19:39 UTC


README

⚠️ Abandoned: This package is abandoned, we have developed a new client.

Akeneo wrapper for Laravel

Latest Version on Packagist GitHub Code Quality Action Status GitHub Code Style Action Status Total Downloads

This package allows you to work with Akeneo in a more Laravel like way.

Requirements

  • PHP 8 or above
  • Akeneo installation

Installation

You can install the package via composer:

composer require justbetter/laravel-akeneo

Configuration

Add the following values to your .env file:

AKENEO_URL=
AKENEO_CLIENT_ID=
AKENEO_SECRET=
AKENEO_USERNAME=
AKENEO_PASSWORD=

You can optionally publish the config file with:

php artisan vendor:publish --provider="JustBetter\Akeneo\AkeneoServiceProvider" --tag="akeneo-config"

This is the contents of the published config file:

return [
    'models' => [
        'product_model' => \JustBetter\Akeneo\Models\ProductModel::class,
        'product'       => \JustBetter\Akeneo\Models\Product::class,
        'attribute'     => \JustBetter\Akeneo\Models\Attribute::class,
        'channel'       => \JustBetter\Akeneo\Models\Channel::class,

        'attribute_types' => [
            'Simpleselect' => \JustBetter\Akeneo\Models\Attribute\Simpleselect::class,
            'Multiselect'  => \JustBetter\Akeneo\Models\Attribute\Multiselect::class,
            'Text'         => \JustBetter\Akeneo\Models\Attribute\Text::class,
            'Date'         => \JustBetter\Akeneo\Models\Attribute\Date::class,
        ],
    ],

    'connections' => [
        'default' => [
            'url'       => env('AKENEO_URL'),
            'client_id' => env('AKENEO_CLIENT_ID'),
            'secret'    => env('AKENEO_SECRET'),
            'username'  => env('AKENEO_USERNAME'),
            'password'  => env('AKENEO_PASSWORD'),
        ],
    ],

    'cache_ttl' => 30,
];

Usage

supported features:

  • Multiple Akeneo connections (WIP)
  • Custom model classes
  • Product Models
    • Get all
    • Get all lazily
    • Find by code
    • Save
  • Products
    • Get all
    • Get all lazily
    • Find by code
    • Save

How to use

All

Get all of the resources from Akeneo

$models = ProductModel::all();

This will return a Collection by default but can be modified by overwriting the newCollection method on your custom model.

The all() method can also be cached by setting the TTL in the config

Lazy

Getting all of the resources lazily from Akeneo returns a LazyCollection

$models = ProductModel::lazy();

See the laravel docs on lazy collections for a full list of methods

Find

Find a resource by its code

$product = Product::find('code-123');

Attributes

Calling an attribute code on a model will return a class of that attributes type. These are defined in the config and can be extended easily.

$product->product_name->setValue(
    data: 'test product 3',
    locale: null, # default
    scope: null # default
);
Options

Options can be constructed and passed to attributes compatible with them

$option = \JustBetter\Akeneo\DataObjects\Option::make(
    data: 'tag 1',
    locale: null,
    scope: null  
)

$product->tags->addOption($option);

$product->tags->removeOption($option);

$product->tags->syncOptions([$option1, $option2]);

Save

Save an altered model and persist it to akeneo

$product = Product::find('code-123');

$product->product_name->setValue(
    data: 'test product 3',
    locale: null, # default
    scope: null # default
);

$product->save();

Testing

The workflow requires 99% of the package to be tested.

make test
# -- OR --
make coverage

Make sure to also run static analysis checks

make analysis

Or combine the 2 requirements

make all

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.