Passed
Push — master ( fea822...a43bd7 )
by Christian
14:56 queued 04:20
created

ShippingMethodDefinition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 58
ccs 40
cts 40
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityClass() 0 3 1
A getCollectionClass() 0 3 1
A defineFields() 0 32 2
A getDefaults() 0 4 1
A getEntityName() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Shipping;
4
5
use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryDefinition;
6
use Shopware\Core\Checkout\Shipping\Aggregate\ShippingMethodPrice\ShippingMethodPriceDefinition;
7
use Shopware\Core\Checkout\Shipping\Aggregate\ShippingMethodTag\ShippingMethodTagDefinition;
8
use Shopware\Core\Checkout\Shipping\Aggregate\ShippingMethodTranslation\ShippingMethodTranslationDefinition;
9
use Shopware\Core\Content\Media\MediaDefinition;
10
use Shopware\Core\Content\Rule\RuleDefinition;
11
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
12
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
13
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField;
14
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
15
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
16
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
17
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected;
18
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
19
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\RestrictDelete;
20
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SearchRanking;
21
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
22
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
23
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
24
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
25
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
26
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
27
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
28
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
29
use Shopware\Core\Framework\Feature;
30
use Shopware\Core\System\DeliveryTime\DeliveryTimeDefinition;
31 104
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelShippingMethod\SalesChannelShippingMethodDefinition;
32
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
33 104
use Shopware\Core\System\Tag\TagDefinition;
34
use Shopware\Core\System\Tax\TaxDefinition;
35
36 102
class ShippingMethodDefinition extends EntityDefinition
37
{
38 102
    public const ENTITY_NAME = 'shipping_method';
39
40
    public function getEntityName(): string
41 81
    {
42
        return self::ENTITY_NAME;
43 81
    }
44
45
    public function getCollectionClass(): string
46 1
    {
47
        return ShippingMethodCollection::class;
48 1
    }
49 1
50 1
    public function getEntityClass(): string
51 1
    {
52 1
        return ShippingMethodEntity::class;
53 1
    }
54 1
55 1
    public function getDefaults(): array
56 1
    {
57 1
        return [
58 1
            'taxType' => ShippingMethodEntity::TAX_TYPE_AUTO,
59 1
        ];
60 1
    }
61 1
62 1
    protected function defineFields(): FieldCollection
63 1
    {
64 1
        $collection = new FieldCollection([
65 1
            (new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
66 1
            (new TranslatedField('name'))->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
67 1
            new BoolField('active', 'active'),
68 1
            new TranslatedField('customFields'),
69 1
            (new FkField('availability_rule_id', 'availabilityRuleId', RuleDefinition::class))->addFlags(new Required()),
70 1
            new FkField('media_id', 'mediaId', MediaDefinition::class),
71 1
            (new FkField('delivery_time_id', 'deliveryTimeId', DeliveryTimeDefinition::class))->addFlags(new Required()),
72 1
            new ManyToOneAssociationField('deliveryTime', 'delivery_time_id', DeliveryTimeDefinition::class, 'id', true),
73 1
            (new TranslatedField('description'))->addFlags(new SearchRanking(SearchRanking::LOW_SEARCH_RAKING)),
74 1
            new TranslatedField('trackingUrl'),
75 1
            (new TranslationsAssociationField(ShippingMethodTranslationDefinition::class, 'shipping_method_id'))->addFlags(new Required()),
76 1
            new ManyToOneAssociationField('availabilityRule', 'availability_rule_id', RuleDefinition::class),
77 1
            (new OneToManyAssociationField('prices', ShippingMethodPriceDefinition::class, 'shipping_method_id', 'id'))->addFlags(new CascadeDelete()),
78 1
            new ManyToOneAssociationField('media', 'media_id', MediaDefinition::class),
79 1
            new ManyToManyAssociationField('tags', TagDefinition::class, ShippingMethodTagDefinition::class, 'shipping_method_id', 'tag_id'),
80 1
81 1
            // Reverse Association, not available in sales-channel-api
82 1
            (new OneToManyAssociationField('orderDeliveries', OrderDeliveryDefinition::class, 'shipping_method_id', 'id'))->addFlags(new RestrictDelete(), new ReadProtected(SalesChannelApiSource::class)),
83
            (new ManyToManyAssociationField('salesChannels', SalesChannelDefinition::class, SalesChannelShippingMethodDefinition::class, 'shipping_method_id', 'sales_channel_id'))->addFlags(new ReadProtected(SalesChannelApiSource::class)),
84
            (new OneToManyAssociationField('salesChannelDefaultAssignments', SalesChannelDefinition::class, 'shipping_method_id', 'id'))->addFlags(new RestrictDelete(), new ReadProtected(SalesChannelApiSource::class)),
85
        ]);
86
87
        if (Feature::isActive('FEATURE_NEXT_6995')) {
88
            $collection->add(new StringField('tax_type', 'taxType', 50));
89
            $collection->add(new FkField('tax_id', 'taxId', TaxDefinition::class));
90
            $collection->add(new ManyToOneAssociationField('tax', 'tax_id', TaxDefinition::class));
91
        }
92
93
        return $collection;
94
    }
95
}
96