Skip to content

Latest commit

 

History

History
73 lines (61 loc) · 1.63 KB

01.2-address.md

File metadata and controls

73 lines (61 loc) · 1.63 KB

Sylius B2B Kit

Installation

Add trait to Address entity class

<?php

declare(strict_types=1);

namespace App\Entity\Addressing;

use Doctrine\ORM\Mapping as ORM;
use Sylius\B2BKit\Entity\AddressAwareTrait;
use Sylius\B2BKit\Entity\AddressInterface;
use Sylius\B2BKit\Entity\OrganizationInterface;
use Sylius\Component\Core\Model\Address as BaseAddress;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_address")
 */
class Address extends BaseAddress implements AddressInterface
{
    /**
     *  * @ORM\AttributeOverrides({
     *      @ORM\AttributeOverrides(name="first_name",
     *           column=@Column(
     *               type="string",
     *               nullable="true"
     *           )
     *      ),
     *      @ORM\AttributeOverrides(name="last_name",
     *           column=@Column(
     *               type="string",
     *               nullable="true"
     *           )
     *      ),
     * })
     */
    use AddressAwareTrait;

    /**
     * @ORM\ManyToOne(
     *     targetEntity="Sylius\B2BKit\Entity\OrganizationInterface",
     *     inversedBy="addresses",
     * )
     * @ORM\JoinColumn(
     *     name="organization_id",
     *     referencedColumnName="id",
     *     nullable=true,
     *     onDelete="CASCADE",
     * )
     */
    protected ?OrganizationInterface $organization = null;
}

Override Address config

# config/packages/_sylius.yaml

sylius_addressing:
    resources:
        address:
            classes:
                model: App\Entity\Addressing\Address
                repository: Sylius\B2BKit\Repository\AddressRepository