flooris / prestashop-models
Collection of Eloquent model files for using Laravel with Prestashop data
Installs: 2 093
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 4
Forks: 7
Open Issues: 0
Requires
- php: ^7.4|^8.0|^8.1
- laravel/framework: ^10.0|^11.0
- dev-master
- v2.3.2
- v2.3.1
- v2.3
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- V2.1.1
- v2.1
- v2.0.1
- v2.0.0
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-feature/BR-5742-Brekz-Exact-API-Pest-en-PHPstan-instellen
- dev-feature/productShop
- dev-laravel-8/master
This package is auto-updated.
Last update: 2024-12-24 15:14:33 UTC
README
PrestaShop Models for Laravel Tests and Factories
This package provides PrestaShop model support for Laravel applications, with a focus on enhancing testing workflows and facilitating the generation of Laravel factories for PrestaShop data.
You can find the package at GitHub - flooris-prestashop-models.
Overview
The flooris-prestashop-models
package helps integrate PrestaShop models with Laravel applications, making it easier to write tests and generate database records using Laravel factories. This is particularly useful when you're working with PrestaShop's complex data structures and want to take advantage of Laravel’s powerful testing and factory generation tools.
Installation
To get started, you can install the package via Composer:
composer require flooris/flooris-prestashop-models
Once installed, the package will be ready to use in your Laravel application, and you can start using PrestaShop models within your Laravel tests and factories.
Usage
The package allows you to interact with PrestaShop models as Laravel Eloquent models, simplifying the process of creating and manipulating PrestaShop data. You can use it with Laravel's built-in Factories and Testing capabilities.
Example Usage
Here’s an example of how to use a PrestaShop model in a Laravel factory:
use App\Models\PrestaShop\Product; Product::factory()->create([ 'name' => 'Sample Product', 'price' => 19.99, ]);
This will create a new product in your PrestaShop database using the data defined in the factory.
Factory Configuration
You can define custom factories for PrestaShop models. For example, to create a factory for a PrestaShop product, you might set up a factory like this:
use Faker\Generator as Faker; $factory->define(App\Models\PrestaShop\Product::class, function (Faker $faker) { return [ 'name' => $faker->word, 'price' => $faker->randomFloat(2, 1, 100), // Add other product fields here ]; });
Extending the Package
While the flooris-prestashop-models
package provides integration with common PrestaShop models, you may find the need to extend it further for your own project-specific requirements. Here are some ways you can extend or modify the package:
In some cases, you might want to add relationships or custom logic to an existing PrestaShop model. For example, if you want to extend the ProductAttribute model, you can create a new class like this:
namespace App\Models; use Illuminate\Database\Eloquent\Relations\HasMany; use Flooris\Prestashop\Models\Product\ProductAttribute as BaseProductAttribute; use Flooris\Prestashop\Models\Product\ProductAttributeShop; class ProductAttribute extends BaseProductAttribute { public function productAttributeShops(): HasMany { return $this->hasMany(ProductAttributeShop::class, 'id_product_attribute', 'id_product_attribute'); } public function isInStock(int $idShop): bool { /** @var ?ProductAttributeShop $productAttributeShop */ $productAttributeShop = $this->productAttributeShops()->where('id_shop', $idShop)->first(); if ($productAttributeShop?->available_date !== '0000-00-00') { return false; } return $this->productAttributeShops()->where('id_shop', $idShop)->first()?->active; } }
Features
- PrestaShop Model Integration: Easily integrate PrestaShop models into Laravel applications.
- Factories for PrestaShop Data: Create Laravel factories for PrestaShop entities, simplifying data seeding and testing.
- Laravel Testing Compatibility: Use PrestaShop models seamlessly in your Laravel tests.
- Support for Common PrestaShop Models: Includes support for common PrestaShop models like products, categories, and customers.
Testing
With this package, you can easily set up tests that involve PrestaShop data. Here’s an example of a simple test that creates a PrestaShop product:
use App\Models\PrestaShop\Product; use Tests\TestCase; class ProductTest extends TestCase { public function test_product_creation() { $product = Product::factory()->create([ 'name' => 'Test Product', 'price' => 10.99, ]); $this->assertDatabaseHas('products', [ 'name' => 'Test Product', 'price' => 10.99, ]); } }
This test will create a product in the database and check that the product exists with the expected values.
Contributing
We welcome contributions to improve and extend the functionality of this package. If you'd like to contribute, please follow these steps:
- Fork the repository on GitHub.
- Create a new branch for your changes.
- Make your changes and ensure tests pass.
- Submit a pull request with a detailed description of your changes.
License
This package is licensed under the MIT License. See LICENSE for more details.
Author
- Flooris - GitHub Profile