Add custom product types
By default the Attlaz Magento2 adapter supports all standard Magento product types (simple, grouped, configuragble, virtual, bundle, downloadable). It is possible to create custom product types and some modules for example Amasty GiftCard comes with other product types. To let the adapter know there are new types you have to override the product type enum we use. Create a new class for the enum
<?php
declare(strict_types=1);
namespace App\Model;
enum ProductType: string
{
case AmGiftCard = 'amgiftcard';
case Simple = 'simple';
case Grouped = 'grouped';
case Configurable = 'configurable';
case Virtual = 'virtual';
case Bundle = 'bundle';
case Downloadable = 'downloadable';
case Custom = 'custom';
public static function fromValue($value): self
{
return self::from($value);
}
}
Then set that enum as the custom type enum for the product repository, this can be done in the di.php file of your project:
Magento2ProductRepository::class => DI\decorate(function (Magento2ProductRepository $magentoProductRepository, \DI\Container $container) {
$magentoProductRepository->setCustomTypeEnumClass(\App\Model\ProductType::class);
return $magentoProductRepository;
}),