Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.23 KB

01.3-customer.md

File metadata and controls

57 lines (46 loc) · 1.23 KB

Sylius B2B Kit

Installation

Add trait to Customer entity class

<?php

declare(strict_types=1);

namespace App\Entity\Customer;

use Doctrine\ORM\Mapping as ORM;
use Sylius\B2BKit\Entity\CustomerAwareTrait;
use Sylius\B2BKit\Entity\CustomerInterface;
use Sylius\B2BKit\Entity\OrganizationInterface;
use Sylius\Component\Core\Model\Customer as BaseCustomer;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_customer")
 */
class Customer extends BaseCustomer implements CustomerInterface
{
    use CustomerAwareTrait;

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

Override Customer config

# config/packages/_sylius.yaml

sylius_customer:
    resources:
        customer:
            classes:
                model: App\Entity\Customer\Customer
                repository: Sylius\B2BKit\Repository\CustomerRepository