[11/06/2024] Les premières modifs + installation de quelques modules indispensables

This commit is contained in:
2024-06-11 14:57:59 +02:00
parent 5ac5653ae5
commit 77cf2c7cc6
1626 changed files with 171457 additions and 131 deletions

View File

@@ -0,0 +1,638 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint;
use Thelia\Model\Address as TheliaAddress;
use Thelia\Model\CountryQuery;
use Thelia\Model\StateQuery;
/**
* @OA\Schema(
* schema="Address",
* title="Address",
* description="Address model"
* )
*/
class Address extends BaseApiModel
{
public static $serviceAliases = ['PickupAddress'];
/**
* @var int
* @OA\Property(
* type="integer"
* )
* @Constraint\NotBlank(groups={"read", "update"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
* @Constraint\NotNull(groups={"create", "update"})
*/
protected $isDefault;
/**
* @var string
* @OA\Property(
* type="string",
* description="The name for this address",
* )
* @Constraint\NotBlank(groups={"create","update"})
*/
protected $label;
/**
* @var Customer
* @OA\Property(
* ref="#/components/schemas/Customer"
* ),
* @Constraint\NotNull(groups={"create","update"})
*/
protected $customer;
/**
* @var CivilityTitle
* @OA\Property(
* ref="#/components/schemas/CivilityTitle"
* ),
* @Constraint\NotNull(groups={"create","update"})
*/
protected $civilityTitle;
/**
* @var string
* @OA\Property(
* type="string",
* ),
* @Constraint\NotNull(groups={"create","update"})
*/
protected $firstName;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotNull(groups={"create","update"})
*/
protected $lastName;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $cellphone;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $phone;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $company;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create","update"})
*/
protected $address1;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $address2;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $address3;
/**
* @var string
* @OA\Property(
* type="string",
* ),
* @Constraint\NotBlank(groups={"create","update"})
* @Constraint\Zipcode(groups={"create","update"})
*/
protected $zipCode;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create","update"})
*/
protected $city;
/**
* @var string
* @OA\Property(
* type="string",
* description="Country ISO 3166-1 alpha-2 code"
* )
* @Constraint\NotBlank(groups={"create","update"})
* @Constraint\Length(
* min = 2,
* max = 2
* )
*/
protected $countryCode;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $stateCode;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $stateName;
/**
* @var object
* @OA\Property(
* type="object"
* )
*/
protected $additionalData;
/**
* @param TheliaAddress $address
* @param string $locale
*
* @return $this|Address
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function createFromTheliaModel($address, $locale = 'en_US')
{
parent::createFromTheliaModel($address, $locale);
$customerTitle = $address->getCustomerTitle()
->setLocale($locale);
/** @var CivilityTitle $civ */
$civ = $this->modelFactory->buildModel('Title', $customerTitle);
$this
->setCivilityTitle($civ)
->setCountryCode($address->getCountry()->getIsoalpha2())
;
if (null !== $state = $address->getState()) {
$this
->setStateCode($state->getIsocode())
->setStateName($state->setLocale($locale)->getTitle());
}
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Address
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* @param bool $isDefault
*
* @return Address
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
return $this;
}
/**
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* @param string $label
*
* @return Address
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
/**
* @param Customer $customer
*
* @return Address
*/
public function setCustomer($customer)
{
$this->customer = $customer;
return $this;
}
/**
* @return CivilityTitle
*/
public function getCivilityTitle()
{
return $this->civilityTitle;
}
/**
* @param CivilityTitle $civilityTitle
*
* @return Address
*/
public function setCivilityTitle($civilityTitle)
{
$this->civilityTitle = $civilityTitle;
return $this;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*
* @return Address
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
*
* @return Address
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* @param string $company
*
* @return Address
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* @return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* @param string $address1
*
* @return Address
*/
public function setAddress1($address1)
{
$this->address1 = $address1;
return $this;
}
/**
* @return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* @param string $address2
*
* @return Address
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
return $this;
}
/**
* @return string
*/
public function getAddress3()
{
return $this->address3;
}
/**
* @param string $address3
*
* @return Address
*/
public function setAddress3($address3)
{
$this->address3 = $address3;
return $this;
}
/**
* @return string
*/
public function getZipCode()
{
return $this->zipCode;
}
/**
* @param string $zipCode
*
* @return Address
*/
public function setZipCode($zipCode)
{
$this->zipCode = $zipCode;
return $this;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
*
* @return Address
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* @return string
*/
public function getCountryCode()
{
return $this->countryCode;
}
/**
* @param string $countryCode
*
* @return Address
*/
public function setCountryCode($countryCode)
{
$this->countryCode = $countryCode;
return $this;
}
/**
* @return object
*/
public function getAdditionalData()
{
return $this->additionalData;
}
/**
* @param object $additionalData
*
* @return Address
*/
public function setAdditionalData($additionalData)
{
$this->additionalData = $additionalData;
return $this;
}
/** Thelia model creation functions */
/**
* @return int
*/
public function getTitleId()
{
$civilityTitle = $this->getCivilityTitle();
return null !== $civilityTitle ? $civilityTitle->getId() : null;
}
/**
* @return int
*/
public function getCustomerId()
{
$customer = $this->getCustomer();
return null !== $customer ? $customer->getId() : null;
}
public function getCountryId()
{
$country = CountryQuery::create()->filterByIsoalpha2($this->getCountryCode())->findOne();
return null !== $country ? $country->getId() : null;
}
/*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/*
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/**
* @param string $phone
*
* @return Address
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* @param string $cellphone
*
* @return Address
*/
public function setCellphone($cellphone)
{
$this->cellphone = $cellphone;
return $this;
}
public function getStateCode(): ?string
{
return $this->stateCode;
}
public function setStateCode(string $stateCode = null)
{
$this->stateCode = $stateCode;
return $this;
}
public function getStateId()
{
$state = StateQuery::create()->filterByCountryId($this->getCountryId())->filterByIsocode($this->getStateCode())->findOne();
return null !== $state ? $state->getId() : null;
}
/**
* @return string
*/
public function getStateName(): ?string
{
return $this->stateName;
}
/**
* @param string $stateName
*/
public function setStateName(string $stateName = null)
{
$this->stateName = $stateName;
return $this;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Attribute.
*
* @OA\Schema(
* description="An attribute"
* )
*/
class Attribute extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var AttributeValue[]
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/AttributeValue"
* )
* )
*/
protected $values;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Attribute
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return array
*/
public function getValues()
{
return $this->values;
}
/**
* @param array $values
*
* @return Attribute
*/
public function setValues($values)
{
$this->values = $values;
return $this;
}
/**
* "setAttributeId" alias to fit Thelia model.
*
* @param int $id
*
* @return Attribute
*/
public function setAttributeId($id)
{
return $this->setId($id);
}
/**
* "setValues" alias to fit Thelia model.
*
* @param array $values
*
* @return Attribute
*/
public function setAttributeAvs($values)
{
return $this->setValues($values);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class AttributeValue.
*
* @OA\Schema(
* description="An attribute value"
* )
*/
class AttributeValue extends BaseApiModel
{
static $serviceAliases = ["AttributeAv"];
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return AttributeValue
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* "setAttributeAvId" alias to fit Thelia model.
*
* @param int $id
*
* @return AttributeValue
*/
public function setAttributeAvId($id)
{
return $this->setId($id);
}
}

View File

@@ -0,0 +1,352 @@
<?php
namespace OpenApi\Model\Api;
use Doctrine\Common\Annotations\AnnotationRegistry;
use OpenApi\Events\ModelExtendDataEvent;
use OpenApi\Events\ModelValidationEvent;
use OpenApi\Exception\OpenApiException;
use OpenApi\Normalizer\ModelApiNormalizer;
use OpenApi\OpenApi;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Propel\Runtime\Collection\Collection;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Country;
use Thelia\Model\State;
use Thelia\TaxEngine\TaxEngine;
abstract class BaseApiModel implements \JsonSerializable
{
/** @var ValidatorInterface */
protected $validator;
/** @var ModelFactory */
protected $modelFactory;
/** @var Request */
protected $request;
/** @var Country */
protected $country;
/** @var State|null */
protected $state;
/** @var EventDispatcherInterface */
protected $dispatcher;
protected $extendedData;
public function __construct(
ModelFactory $modelFactory,
RequestStack $requestStack,
TaxEngine $taxEngine,
EventDispatcherInterface $dispatcher
) {
if (class_exists(AnnotationRegistry::class)) {
AnnotationRegistry::registerLoader('class_exists');
}
$this->dispatcher = $dispatcher;
$this->validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$this->modelFactory = $modelFactory;
$this->request = $requestStack->getCurrentRequest();
$this->country = $taxEngine->getDeliveryCountry();
$this->state = $taxEngine->getDeliveryState();
if (method_exists($this, 'initI18n')) {
$this->initI18n($modelFactory);
}
}
public function getCurrentLocale()
{
return $this->request?->getSession()?->getLang(true)->getLocale();
}
/**
* @param $groups
*
* @return BaseApiModel
*
* @throws OpenApiException
*/
public function validate($groups, $recursively = true)
{
$violations = $this->getViolations($groups, $recursively);
if (empty($violations)) {
return $this;
}
/** @var Error $error */
$error = $this->modelFactory->buildModel(
'Error',
['title' => Translator::getInstance()->trans('Invalid data', [], OpenApi::DOMAIN_NAME)]
);
$error->setSchemaViolations($violations);
throw new OpenApiException($error);
}
public function getViolations($groups, $recursively = true, $propertyPatchPrefix = '')
{
$modelFactory = $this->modelFactory;
$violations = array_reduce(
iterator_to_array($this->validator->validate($this, null, $groups)),
function ($carry, $violation) use ($modelFactory, $propertyPatchPrefix) {
$carry[$propertyPatchPrefix.$violation->getPropertyPath()] = $modelFactory->buildModel('SchemaViolation', ['message' => $violation->getMessage()]);
return $carry;
},
[]
);
if ($recursively === true) {
foreach (get_object_vars($this) as $key => $value) {
if ($value instanceof self) {
$violations = array_merge($violations, $value->getViolations('read', true, $propertyPatchPrefix.$key.'.'));
}
}
}
$event = new ModelValidationEvent($this, $modelFactory, $groups, $propertyPatchPrefix);
$this->dispatcher->dispatch($event, ModelValidationEvent::MODEL_VALIDATION_EVENT_PREFIX.$this->snakeCaseName());
return array_merge($violations, $event->getViolations());
}
public function jsonSerialize()
{
$normalizer = new ModelApiNormalizer();
$serializer = new Serializer([$normalizer]);
return $serializer->normalize($this, null);
}
public function createOrUpdateFromData($data, $locale = null): void
{
if (null === $locale) {
$locale = $this->getCurrentLocale();
}
if (\is_object($data)) {
$this->createFromTheliaModel($data, $locale);
}
if (\is_string($data)) {
$data = json_decode($data, true);
}
if (\is_array($data) || $data instanceof \Traversable) {
foreach ($data as $key => $value) {
$setMethodName = 'set'.ucfirst($key);
$getMethodName = 'get'.ucfirst($key);
if (method_exists($this, $setMethodName)) {
if (\is_array($value)) {
if (method_exists($this, $getMethodName) && $this->$getMethodName() instanceof self) {
$this->$setMethodName($this->$getMethodName()->updateFromData($value));
continue;
}
$openApiModel = $this->modelFactory->buildModel(ucfirst($key), $value);
$value = null !== $openApiModel ? $openApiModel : $value;
}
$this->$setMethodName($value);
}
}
}
$modelExtendEvent = (new ModelExtendDataEvent())
->setData($data)
->setLocale($locale)
->setModel($this);
$this->dispatcher->dispatch(
$modelExtendEvent,
ModelExtendDataEvent::ADD_EXTEND_DATA_PREFIX.$this->snakeCaseName()
);
$this->setExtendData($modelExtendEvent->getExtendData());
}
/**
* Override to return the propel model associated with the OpenApi model instead of null.
*
* @return mixed
*/
protected function getTheliaModel($propelModelName = null)
{
if (null === $propelModelName) {
$propelModelName = "Thelia\Model\\".basename(str_replace('\\', '/', static::class));
}
if (!class_exists($propelModelName)) {
return null;
}
if (method_exists($this, 'getId') && null !== $id = $this->getId()) {
$theliaModelQueryName = $propelModelName.'Query';
return $theliaModelQueryName::create()->filterById($id)->findOne();
}
/** @var ActiveRecordInterface $newTheliaModel */
$newTheliaModel = new $propelModelName();
$newTheliaModel->setNew(true);
return $newTheliaModel;
}
public function toTheliaModel($locale = null)
{
if (null === $theliaModel = $this->getTheliaModel()) {
throw new \Exception(Translator::getInstance()->trans('Propel model not found automatically for class %className%. Please override the getTheliaModel method to use the toTheliaModel method.', ['%className%' => basename(static::class)], OpenApi::DOMAIN_NAME));
}
// If model need locale, set it
if (method_exists($theliaModel, 'setLocale')) {
$theliaModel->setLocale($locale !== null ? $locale : $this->getCurrentLocale());
}
// Look all method of Open API model
foreach (get_class_methods($this) as $methodName) {
$getter = $methodName;
$setter = null;
// If it's not a getter skip it
if (0 === strncasecmp('get', $methodName, 3)) {
// Build thelia setter name
$setter = 'set'.substr($getter, 3);
}
// For boolean method like "isVisible"
if ($setter === null && 0 === strncasecmp('is', $methodName, 2)) {
// Build thelia setter name
$setter = 'set'.substr($getter, 2);
}
// Check if setter exist in Thelia model
if (null === $setter || !method_exists($theliaModel, $setter)) {
continue;
}
$value = $this->$getter();
// If Values are the same skip this property
if (method_exists($theliaModel, $getter) && $theliaModel->$getter() === $value) {
continue;
}
// if the property is another Api model
if ($value instanceof self) {
// If it doesn't have a correspondant thelia model skip it
if (null === $value->getTheliaModel()) {
continue;
}
// Else try to set the model id
$setModelIdMethod = $setter.'Id';
if (!method_exists($theliaModel, $setModelIdMethod)) {
continue;
}
$setter = $setModelIdMethod;
$value = $value->getId();
}
// Todo transform array to collection
if (is_array($value)) {
continue;
}
$theliaModel->$setter($value);
}
return $theliaModel;
}
public function createFromTheliaModel($theliaModel, $locale = null)
{
if (method_exists($theliaModel, 'setLocale')) {
$theliaModel->setLocale($locale !== null ? $locale : $this->getCurrentLocale());
}
foreach (get_class_methods($this) as $modelMethod) {
if (0 === strncasecmp('set', $modelMethod, 3)) {
$property = ucfirst(substr($modelMethod, 3));
$lowercaseProperty = ucfirst(strtolower($property));
// List all possible getters for this property in propel
$propelPossibleMethods = [ // EXAMPLE :
'get'.$property, // getProductSaleElements
'get'.$property.'s', // getProductSaleElementss
'get'.$lowercaseProperty, // getProductsaleelements
'get'.$lowercaseProperty.'s', // getProductsaleelementss
'get'.$property.'Model', // getProductSaleElementsModel
'get'.$lowercaseProperty.'Model', // getProductsaleelementsModel
'get'.substr(\get_class($theliaModel), strrpos(\get_class($theliaModel), '\\') + 1).$property, // getCartProductSaleElements
'get'.substr(\get_class($theliaModel), strrpos(\get_class($theliaModel), '\\') + 1).$lowercaseProperty, // getCartProductsaleelements
];
$availableMethods = array_filter(array_intersect($propelPossibleMethods, get_class_methods($theliaModel)));
if (empty($availableMethods)) {
continue;
}
$theliaValue = null;
while (!empty($availableMethods) && ($theliaValue === null || empty($theliaValue))) {
$theliaMethod = array_pop($availableMethods);
$theliaValue = $theliaModel->$theliaMethod();
if ($theliaValue instanceof Collection) {
$theliaValue = array_filter(array_map(fn ($value) => $this->modelFactory->buildModel($property, $value), iterator_to_array($theliaValue)));
continue;
}
if (\is_object($theliaValue) && $this->modelFactory->modelExists($property)) {
$theliaValue = $this->modelFactory->buildModel($property, $theliaValue);
}
}
$this->$modelMethod($theliaValue);
}
}
return $this;
}
public function setExtendData($extendedData)
{
$this->extendedData = $extendedData;
return $this;
}
public function extendedDataValue()
{
return $this->extendedData;
}
protected function snakeCaseName()
{
$name = basename(str_replace('\\', '/', static::class));
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $name, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}
return implode('_', $ret);
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Brand.
*
* @OA\Schema(
* description="A Brand"
* )
*/
class Brand extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Brand
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return Brand
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}

View File

@@ -0,0 +1,467 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\Delivery\DeliveryPostageEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\AreaDeliveryModuleQuery;
use Thelia\Model\Country;
use Thelia\Model\CouponQuery;
use Thelia\Model\ModuleQuery;
use Thelia\Model\State;
use Thelia\Module\BaseModule;
use Thelia\Module\Exception\DeliveryException;
use Thelia\TaxEngine\TaxEngine;
/**
* Class Cart.
*
* @OA\Schema(
* description="A cart"
* )
*/
class Cart extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read", "update"})
*/
protected $id;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $taxes;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* description="The estimated delivery price for this cart",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $delivery;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* description="The estimated delivery tax price for this cart",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $deliveryTax;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Coupon"
* )
* )
*/
protected $coupons;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $discount;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $total;
/**
* @var string
* @OA\Property(
* description="Symbol of the currently used currency",
* type="string",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $currency;
/**
* @var boolean
* @OA\Property(
* type="boolean"
* )
*/
protected $virtual;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/CartItem"
* )
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $items;
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(
ModelFactory $modelFactory,
RequestStack $requestStack,
TaxEngine $taxEngine,
EventDispatcherInterface $dispatcher,
// Todo find a way to remove container here (only used to get module instance)
ContainerInterface $container
) {
parent::__construct($modelFactory, $requestStack, $taxEngine, $dispatcher);
$this->container = $container;
}
public function createFromTheliaModel($theliaModel, $locale = null): void
{
parent::createFromTheliaModel($theliaModel, $locale);
$postageInfo = $this->getEstimatedPostageForCountry($theliaModel, $this->country, $this->state);
$estimatedPostage = $postageInfo['postage'];
$postageTax = $postageInfo['tax'];
$consumedCoupons = $this->request->getSession()->getConsumedCoupons();
$coupons = $this->createOpenApiCouponsFromCouponsCodes($consumedCoupons);
$modelFactory = $this->modelFactory;
$deliveryCountry = $this->country;
$cartItems = array_map(
function ($theliaCartItem) use ($modelFactory, $deliveryCountry) {
/** @var CartItem $cartItem */
$cartItem = $modelFactory->buildModel('CartItem', $theliaCartItem);
$cartItem->fillFromTheliaCartItemAndCountry($theliaCartItem, $deliveryCountry);
return $cartItem;
},
iterator_to_array($theliaModel->getCartItems())
);
$this
->setDeliveryTax($postageTax)
->setTaxes($theliaModel->getTotalVAT($deliveryCountry, null, false))
->setDelivery($estimatedPostage)
->setCoupons($coupons)
->setTotal($theliaModel->getTaxedAmount($deliveryCountry, false, null))
->setCurrency($theliaModel->getCurrency()->getSymbol())
->setItems($cartItems)
->setVirtual($theliaModel->isVirtual());
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Cart
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return float
*/
public function getTaxes()
{
return $this->taxes;
}
/**
* @param float $taxes
*
* @return Cart
*/
public function setTaxes($taxes)
{
$this->taxes = $taxes;
return $this;
}
/**
* @return float
*/
public function getDelivery()
{
return $this->delivery;
}
/**
* @param float $delivery
*
* @return Cart
*/
public function setDelivery($delivery)
{
$this->delivery = $delivery;
return $this;
}
/**
* @return array
*/
public function getCoupons()
{
return $this->coupons;
}
/**
* @param array $coupons
*
* @return Cart
*/
public function setCoupons($coupons)
{
$this->coupons = $coupons;
return $this;
}
/**
* @return float
*/
public function getDeliveryTax()
{
return $this->deliveryTax;
}
/**
* @param float $deliveryTax
*/
public function setDeliveryTax($deliveryTax)
{
$this->deliveryTax = $deliveryTax;
return $this;
}
/**
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param float $discount
*
* @return Cart
*/
public function setDiscount($discount)
{
$this->discount = (float)$discount;
return $this;
}
/**
* @return boolean
*/
public function getVirtual()
{
return $this->virtual;
}
/**
* @param boolean $virtual
* @return Cart
*/
public function setVirtual($virtual)
{
$this->virtual = $virtual;
return $this;
}
/**
* @return float
*/
public function getTotal()
{
return $this->total;
}
/**
* @param float $total
*
* @return Cart
*/
public function setTotal($total)
{
$this->total = $total;
return $this;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*
* @return Cart
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* @return array
*/
public function getItems()
{
return $this->items;
}
/**
* @param array $items
*
* @return Cart
*/
public function setItems($items)
{
$this->items = $items;
return $this;
}
/**
* Creates an array of OpenApi coupons from an array of coupons codes, then returns it.
*
* @param $couponsCodes
*
* @return array
*/
protected function createOpenApiCouponsFromCouponsCodes($couponsCodes)
{
$coupons = CouponQuery::create()->filterByCode($couponsCodes)->find();
$factory = $this->modelFactory;
return array_map(
fn ($coupon) => $factory->buildModel('Coupon', $coupon),
iterator_to_array($coupons)
);
}
/**
* Return the minimum expected postage for a cart in a given country.
*
* @return array
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function getEstimatedPostageForCountry(\Thelia\Model\Cart $cart, Country $country, State $state = null)
{
$orderSession = $this->request->getSession()->getOrder();
$deliveryModules = [];
if ($deliveryModule = ModuleQuery::create()->findPk($orderSession->getDeliveryModuleId())) {
$deliveryModules[] = $deliveryModule;
}
if (empty($deliveryModules)) {
$deliveryModules = ModuleQuery::create()
->filterByActivate(1)
->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL)
->find();
}
$virtual = $cart->isVirtual();
$postage = null;
$postageTax = null;
/** @var \Thelia\Model\Module $deliveryModule */
foreach ($deliveryModules as $deliveryModule) {
$areaDeliveryModule = AreaDeliveryModuleQuery::create()
->findByCountryAndModule($country, $deliveryModule, $state);
if (null === $areaDeliveryModule && false === $virtual) {
continue;
}
$moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
if (true === $virtual && false === $moduleInstance->handleVirtualProductDelivery()) {
continue;
}
try {
$deliveryPostageEvent = new DeliveryPostageEvent($moduleInstance, $cart, null, $country, $state);
$this->dispatcher->dispatch(
$deliveryPostageEvent,
TheliaEvents::MODULE_DELIVERY_GET_POSTAGE
);
if ($deliveryPostageEvent->isValidModule()) {
$modulePostage = $deliveryPostageEvent->getPostage();
if (null === $postage || $postage > $modulePostage->getAmount()) {
$postage = $modulePostage->getAmount() - $modulePostage->getAmountTax();
$postageTax = $modulePostage->getAmountTax();
}
}
} catch (DeliveryException $ex) {
// Module is not available
}
}
return [
'postage' => $postage,
'tax' => $postageTax
];
}
}

View File

@@ -0,0 +1,309 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use OpenApi\Service\ImageService;
use Thelia\Model\CartItem as TheliaCartItem;
use Thelia\Model\Country;
/**
* Class CartItem.
*
* @OA\Schema(
* description="An item in a cart"
* )
*/
class CartItem extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* description="cartItemId, not to be confused with the productId or pseId",
* )
* @Constraint\NotBlank(groups={"read, update"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $isPromo;
/**
* @var Product
* @OA\Property(
* type="object",
* ref="#/components/schemas/Product",
* )
*/
protected $product;
/**
* @var ProductSaleElement
* @OA\Property(
* type="object",
* ref="#/components/schemas/ProductSaleElement",
* )
*/
protected $productSaleElement;
/**
* @var array
* @OA\Property(
* description="The pse images if they're present, the product images otherwise",
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $images;
/**
* @var Price
* @OA\Property(
* type="object",
* ref="#/components/schemas/Price",
* )
*/
protected $price;
/**
* @var Price
* @OA\Property(
* type="object",
* ref="#/components/schemas/Price"
* )
*/
protected $promoPrice;
/**
* @var int
* @OA\Property(
* type="integer",
* )
*/
protected $quantity;
/**
* Create a new OpenApi CartItem from a Thelia CartItem and a Country, then returns it.
*
* @param \Thelia\Model\CartItem $cartItem
* @param ImageService $imageService
*
* @return $this
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function fillFromTheliaCartItemAndCountry(TheliaCartItem $cartItem, Country $country)
{
$this->id = $cartItem->getId();
/** @var Product $product */
$product = $this->modelFactory->buildModel('Product', $cartItem->getProduct());
$this->product = $product;
/** @var ProductSaleElement $productSaleElements */
$productSaleElements = $this->modelFactory->buildModel('ProductSaleElement');
$productSaleElements->fillFromTheliaPseAndCountry($cartItem->getProductSaleElements(), $country);
$this->productSaleElement = $productSaleElements;
$this->isPromo = (bool) $cartItem->getPromo();
$this->price = $this->modelFactory->buildModel(
'Price',
[
'taxed' => $cartItem->getTaxedPrice($country),
'untaxed' => $cartItem->getPrice(),
]
);
$this->promoPrice = $this->modelFactory->buildModel(
'Price',
[
'taxed' => $cartItem->getTaxedPromoPrice($country),
'untaxed' => $cartItem->getPromoPrice(),
]
);
$this->quantity = $cartItem->getQuantity();
/** If there are PSE specific images, we use them. Otherwise, we just use the product images */
$modelFactory = $this->modelFactory;
try {
$images = array_map(
fn ($productSaleElementsImage) => $modelFactory->buildModel('Image', $productSaleElementsImage->getProductImage()),
iterator_to_array($cartItem->getProductSaleElements()->getProductSaleElementsProductImages())
);
} catch (\Exception $exception) {
$images = [];
}
$this->images = !empty($images) ? $images : $this->product->getImages();
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return CartItem
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isPromo()
{
return $this->isPromo;
}
/**
* @param bool $isPromo
*
* @return CartItem
*/
public function setIsPromo($isPromo)
{
$this->isPromo = $isPromo;
return $this;
}
/**
* @return Product
*/
public function getProduct()
{
return $this->product;
}
/**
* @param Product $product
*
* @return CartItem
*/
public function setProduct($product)
{
$this->product = $product;
return $this;
}
/**
* @return ProductSaleElement
*/
public function getProductSaleElement()
{
return $this->productSaleElement;
}
/**
* @param ProductSaleElement $productSaleElement
*
* @return CartItem
*/
public function setProductSaleElement($productSaleElement)
{
$this->productSaleElement = $productSaleElement;
return $this;
}
/**
* @return array
*/
public function getImages()
{
return $this->images;
}
/**
* @param array $images
*
* @return CartItem
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
/**
* @return Price
*/
public function getPrice()
{
return $this->price;
}
/**
* @param Price $price
*
* @return CartItem
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return Price
*/
public function getPromoPrice()
{
return $this->promoPrice;
}
/**
* @param Price $promoPrice
*
* @return CartItem
*/
public function setPromoPrice($promoPrice)
{
$this->promoPrice = $promoPrice;
return $this;
}
/**
* @return int
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param int $quantity
*
* @return CartItem
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
}

View File

@@ -0,0 +1,117 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Category.
*
* @OA\Schema(
* description="A Category"
* )
*/
class Category extends BaseApiModel
{
use translatable;
/**
* @var int
*
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
*
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @var string
*
* @OA\Property(
* type="string",
* )
*/
protected $url;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Category
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return Category
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*
* @return Category
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
}

View File

@@ -0,0 +1,309 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\OpenApi;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Order;
/**
* Class Checkout.
*
* @OA\Schema(
* schema="Checkout",
* title="Checkout",
* description="Checkout model",
* )
*/
class Checkout extends BaseApiModel
{
protected $isComplete = false;
/**
* @var int
* @OA\Property(
* type="integer",
* description="id of the delivery module used by this checkout"
* )
*/
protected $deliveryModuleId;
/**
* @var int
* @OA\Property(
* type="integer",
* description="id of the payment module used by this checkout"
* )
*/
protected $paymentModuleId;
/**
* @var int
* @OA\Property(
* type="integer"
* )
*/
protected $billingAddressId;
/**
* @var int
* @OA\Property(
* type="integer"
* )
*/
protected $deliveryAddressId;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $deliveryModuleOptionCode;
/**
* @var Address
* @OA\Property(
* ref="#/components/schemas/Address"
* )
*/
protected $pickupAddress;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
*/
protected $acceptedTermsAndConditions = false;
public function createFromOrder(Order $order)
{
$this->setDeliveryAddressId($order->getChoosenDeliveryAddress());
$this->setBillingAddressId($order->getChoosenInvoiceAddress());
$this->setDeliveryModuleId($order->getDeliveryModuleId())
->setPaymentModuleId($order->getPaymentModuleId());
return $this;
}
/**
* @OA\Property(
* property="isComplete",
* description="Tell if a checkout has defined a Module and an Address for both delivery and billing",
* type="boolean"
* )
*
* @return bool
*/
public function getIsComplete()
{
if (null === $this->getDeliveryModuleId()) {
return false;
}
if (null === $this->getDeliveryAddressId()) {
return false;
}
if (null === $this->getBillingAddressId()) {
return false;
}
if (null === $this->getPaymentModuleId()) {
return false;
}
return true;
}
/**
* @throws \Exception
*/
public function checkIsValid(): void
{
if (null === $this->getDeliveryModuleId()) {
throw new \Exception(
Translator::getInstance()->trans(
'You must choose a delivery module',
[],
OpenApi::DOMAIN_NAME
)
);
}
if (null === $this->getPaymentModuleId()) {
throw new \Exception(
Translator::getInstance()->trans(
'You must choose a payment module',
[],
OpenApi::DOMAIN_NAME
)
);
}
if (null === $this->getDeliveryAddressId()) {
throw new \Exception(
Translator::getInstance()->trans(
'You must choose a delivery address',
[],
OpenApi::DOMAIN_NAME
)
);
}
if (null === $this->getBillingAddressId()) {
throw new \Exception(
Translator::getInstance()->trans(
'You must choose a billing address',
[],
OpenApi::DOMAIN_NAME
)
);
}
if (false === $this->isAcceptedTermsAndConditions()) {
throw new \Exception(
Translator::getInstance()->trans(
'You must accept the terms and conditions',
[],
OpenApi::DOMAIN_NAME
)
);
}
}
/**
* @return int
*/
public function getDeliveryModuleId()
{
return $this->deliveryModuleId;
}
/**
* @param int $deliveryModuleId
*
* @return Checkout
*/
public function setDeliveryModuleId($deliveryModuleId)
{
$this->deliveryModuleId = $deliveryModuleId;
return $this;
}
/**
* @return int
*/
public function getPaymentModuleId()
{
return $this->paymentModuleId;
}
/**
* @param int $paymentModuleId
*
* @return Checkout
*/
public function setPaymentModuleId($paymentModuleId)
{
$this->paymentModuleId = $paymentModuleId;
return $this;
}
/**
* @return int
*/
public function getBillingAddressId()
{
return $this->billingAddressId;
}
/**
* @param int $billingAddressId
*
* @return Checkout
*/
public function setBillingAddressId($billingAddressId)
{
$this->billingAddressId = $billingAddressId;
return $this;
}
/**
* @return int
*/
public function getDeliveryAddressId()
{
return $this->deliveryAddressId;
}
/**
* @param int $deliveryAddressId
*
* @return Checkout
*/
public function setDeliveryAddressId($deliveryAddressId)
{
$this->deliveryAddressId = $deliveryAddressId;
return $this;
}
/**
* @return Address
*/
public function getPickupAddress()
{
return $this->pickupAddress;
}
/**
* @param Address $pickupAddress
*
* @return Checkout
*/
public function setPickupAddress($pickupAddress)
{
$this->pickupAddress = $pickupAddress;
return $this;
}
public function isAcceptedTermsAndConditions(): bool
{
return $this->acceptedTermsAndConditions;
}
public function setAcceptedTermsAndConditions(bool $acceptedTermsAndConditions): self
{
$this->acceptedTermsAndConditions = $acceptedTermsAndConditions;
return $this;
}
/**
* @return string
*/
public function getDeliveryModuleOptionCode()
{
return $this->deliveryModuleOptionCode;
}
/**
* @param $deliveryModuleOptionCode
* @return Checkout
*/
public function setDeliveryModuleOptionCode($deliveryModuleOptionCode)
{
$this->deliveryModuleOptionCode = $deliveryModuleOptionCode;
return $this;
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use Thelia\Model\CustomerTitle;
/**
* @OA\Schema(
* schema="CivilityTitle",
* title="CivilityTitle",
* description="Civility Title model"
* )
*/
class CivilityTitle extends BaseApiModel
{
static $serviceAliases = ["Title"];
/**
* @var int
* @OA\Property(
* type="integer"
* ),
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string"
* ),
*/
protected $short;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $long;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return CivilityTitle
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getShort()
{
return $this->short;
}
/**
* @param string $short
*
* @return CivilityTitle
*/
public function setShort($short)
{
$this->short = $short;
return $this;
}
/**
* @return string
*/
public function getLong()
{
return $this->long;
}
/**
* @param string $long
*
* @return CivilityTitle
*/
public function setLong($long)
{
$this->long = $long;
return $this;
}
/**
* @return CustomerTitle
*/
protected function getCustomerTitle()
{
return new CustomerTitle();
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Content.
*
* @OA\Schema(
* description="A Content"
* )
*/
class Content extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Content
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return Content
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}

View File

@@ -0,0 +1,104 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
/**
* Class Coupon.
*
* @OA\Schema(
* description="A coupon"
* )
*/
class Coupon extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read", "update"})
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $code;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $amount;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Coupon
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*
* @return Coupon
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param float $amount
*
* @return Coupon
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
}

View File

@@ -0,0 +1,381 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint;
/**
* @OA\Schema(
* schema="Customer",
* title="Customer",
* description="Customer model"
* )
*/
class Customer extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var CivilityTitle
* @OA\Property(
* type="object",
* ref="#/components/schemas/CivilityTitle",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $civilityTitle;
/**
* @var Lang
* @OA\Property(
* type="object",
* ref="#/components/schemas/Lang",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $lang;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"update"})
*/
protected $reference;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $firstName;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $lastName;
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $email;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $rememberMe;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
* @Constraint\NotBlank(groups={"create", "update"})
*/
protected $discount;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $reseller;
/**
* @var int
* @OA\Property(
* type="integer",
* )
*/
protected $defaultAddressId;
public function createFromTheliaModel($theliaModel, $locale = null): void
{
parent::createFromTheliaModel($theliaModel, $locale);
$this->setDefaultAddressId($theliaModel->getDefaultAddress()->getId());
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Customer
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return CivilityTitle
*/
public function getCivilityTitle()
{
return $this->civilityTitle;
}
/**
* @param CivilityTitle $civilityTitle
*
* @return Customer
*/
public function setCivilityTitle($civilityTitle)
{
$this->civilityTitle = $civilityTitle;
return $this;
}
/**
* @return Lang
*/
public function getLang()
{
return $this->lang;
}
/**
* @param Lang $lang
*
* @return Customer
*/
public function setLang($lang)
{
$this->lang = $lang;
return $this;
}
/**
* @return string
*/
public function getReference()
{
return $this->reference;
}
/**
* @param string $reference
*
* @return Customer
*/
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*
* @return Customer
*/
public function setFirstname($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
*
* @return Customer
*/
public function setLastname($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*
* @return Customer
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return bool
*/
public function isRememberMe()
{
return $this->rememberMe;
}
/**
* @param bool $rememberMe
*
* @return Customer
*/
public function setRememberMe($rememberMe)
{
$this->rememberMe = $rememberMe;
return $this;
}
/**
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param float $discount
*
* @return Customer
*/
public function setDiscount($discount)
{
$this->discount = $discount;
return $this;
}
/**
* @return bool
*/
public function isReseller()
{
return $this->reseller;
}
/**
* @param bool $reseller
*
* @return Customer
*/
public function setReseller($reseller)
{
$this->reseller = $reseller;
return $this;
}
/**
* @return int
*/
public function getTitleId()
{
return $this->getCivilityTitle()->getId();
}
/**
* @return int
*/
public function getLangId()
{
return $this->getLang()->getId();
}
public function setTitle(CivilityTitle $civilityTitle)
{
$this->civilityTitle = $civilityTitle;
return $this;
}
public function setRef($ref)
{
$this->reference = $ref;
return $this;
}
/**
* @return int
*/
public function getDefaultAddressId()
{
return $this->defaultAddressId;
}
/**
* @param int $id
*
* @return Customer
*/
public function setDefaultAddressId($id)
{
$this->defaultAddressId = $id;
return $this;
}
}

View File

@@ -0,0 +1,214 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use OpenApi\Exception\OpenApiException;
use OpenApi\Model\Api\ModelTrait\translatable;
use OpenApi\OpenApi;
use Thelia\Core\Translation\Translator;
/**
* Class DeliveryModule.
*
* @OA\Schema(
* description="A module of type delivery"
* )
*/
class DeliveryModule extends BaseApiModel
{
use translatable;
/**
* @var string
* @OA\Property(
* type="string",
* description="delivery -> At customer adress; pickup -> At carrier pickup point; localPickup -> At store pickup point",
* enum={"delivery", "pickup", "localPickup"}
* )
*/
protected $deliveryMode;
/**
* @var int
* @OA\Property(
* type="integer"
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
*/
protected $valid;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $code;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/DeliveryModuleOption"
* )
* )
*/
protected $options;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $images = [];
/**
* @return string
*/
public function getDeliveryMode()
{
return $this->deliveryMode;
}
/**
* @param string $deliveryMode
*
* @return DeliveryModule
*
* @throws \Exception
*/
public function setDeliveryMode($deliveryMode)
{
if (!\in_array($deliveryMode, ['delivery', 'pickup', 'localPickup'])) {
/** @var Error $error */
$error = $this->modelFactory->buildModel(
'Error',
[
'title' => Translator::getInstance()->trans('Invalid data', [], OpenApi::DOMAIN_NAME),
'description' => Translator::getInstance()->trans("Delivery mode can only be 'delivery', 'pickup' or 'localPickup'", [], OpenApi::DOMAIN_NAME),
]
);
throw new OpenApiException($error);
}
$this->deliveryMode = $deliveryMode;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return DeliveryModule
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isValid()
{
return $this->valid;
}
/**
* @param bool $valid
*
* @return DeliveryModule
*/
public function setValid($valid)
{
$this->valid = $valid;
return $this;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*
* @return DeliveryModule
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* @param array $options
*
* @return DeliveryModule
*/
public function setOptions($options)
{
$this->options = $options;
return $this;
}
/**
* @return array
*/
public function getImages()
{
return $this->images;
}
/**
* @param array $images
*
* @return DeliveryModule
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
}

View File

@@ -0,0 +1,275 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
/**
* Class DeliveryModuleOption.
*
* @OA\Schema(
* description="An option for delivery module"
* )
*/
class DeliveryModuleOption extends BaseApiModel
{
/**
* @var string
* @OA\Property(
* type="string",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $code;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $valid;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $title;
/**
* @var string
* @OA\Property(
* type="string",
* description="Delivery logo url",
* )
*/
protected $image;
/**
* @var string
* @OA\Property(
* type="string",
* format="date-time",
* )
*/
protected $minimumDeliveryDate;
/**
* @var string
* @OA\Property(
* type="string",
* format="date-time",
* )
*/
protected $maximumDeliveryDate;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $postage;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $postageTax;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $postageUntaxed;
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*
* @return DeliveryModuleOption
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return bool
*/
public function isValid()
{
return $this->valid;
}
/**
* @param bool $valid
*
* @return DeliveryModuleOption
*/
public function setValid($valid)
{
$this->valid = $valid;
return $this;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*
* @return DeliveryModuleOption
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @param string $image
*
* @return DeliveryModuleOption
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* @return string
*/
public function getMinimumDeliveryDate()
{
return $this->minimumDeliveryDate;
}
/**
* @param string $minimumDeliveryDate
*
* @return DeliveryModuleOption
*/
public function setMinimumDeliveryDate($minimumDeliveryDate)
{
$this->minimumDeliveryDate = $minimumDeliveryDate;
return $this;
}
/**
* @return string
*/
public function getMaximumDeliveryDate()
{
return $this->maximumDeliveryDate;
}
/**
* @param string $maximumDeliveryDate
*
* @return DeliveryModuleOption
*/
public function setMaximumDeliveryDate($maximumDeliveryDate)
{
$this->maximumDeliveryDate = $maximumDeliveryDate;
return $this;
}
/**
* @return float
*/
public function getPostage()
{
return $this->postage;
}
/**
* @param float $postage
*
* @return DeliveryModuleOption
*/
public function setPostage($postage)
{
$this->postage = $postage;
return $this;
}
/**
* @return float
*/
public function getPostageTax()
{
return $this->postageTax;
}
/**
* @param float $postageTax
*
* @return DeliveryModuleOption
*/
public function setPostageTax($postageTax)
{
$this->postageTax = $postageTax;
return $this;
}
/**
* @return float
*/
public function getPostageUntaxed()
{
return $this->postageUntaxed;
}
/**
* @param float $postageUntaxed
*
* @return DeliveryModuleOption
*/
public function setPostageUntaxed($postageUntaxed)
{
$this->postageUntaxed = $postageUntaxed;
return $this;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Service\DocumentService;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Thelia\TaxEngine\TaxEngine;
class Document extends File
{
static $serviceAliases = ["ProductDocuments"];
/** @var DocumentService */
protected $documentService;
public function __construct(ModelFactory $modelFactory, RequestStack $requestStack, TaxEngine $taxEngine, EventDispatcherInterface $dispatcher, DocumentService $documentService)
{
parent::__construct($modelFactory, $requestStack, $taxEngine, $dispatcher);
$this->documentService = $documentService;
}
/**
* @param $theliaModel
* @param null $locale
* @param null $type
*
* @return $this
*/
public function createFromTheliaModel($theliaModel, $locale = null, $type = null)
{
parent::createFromTheliaModel($theliaModel, $locale);
$this->url = $this->documentService->getDocumentUrl($theliaModel, $type);
return $this;
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
/**
* Class Error.
*
* @OA\Schema(
* description="An error"
* )
*/
class Error extends BaseApiModel
{
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $title;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $description;
/**
* @var array
* @OA\Property(
* type="object",
* @OA\AdditionalProperties(
* ref="#/components/schemas/SchemaViolation",
* ),
* example={"field_1": {"message":"Bad format"}, "field_2": {"message":"This value should not be blank"}, "...": {"message":"Other fields errors"}}
* )
*/
protected $schemaViolations;
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*
* @return Error
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*
* @return Error
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return array
*/
public function getSchemaViolations()
{
return $this->schemaViolations;
}
/**
* @param array $schemaViolations
*
* @return Error
*/
public function setSchemaViolations($schemaViolations)
{
$this->schemaViolations = $schemaViolations;
return $this;
}
/**
* @param $schemaViolation SchemaViolation
*
* @return $this
*/
public function appendViolation($schemaViolation)
{
$this->schemaViolations[] = $schemaViolation;
return $this;
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Feature.
*
* @OA\Schema(
* description="A feature"
* )
*/
class Feature extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var FeatureValue[]
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/FeatureValue"
* )
* )
*/
protected $values;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Feature
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return array
*/
public function getValues()
{
return $this->values;
}
/**
* @param array $values
*
* @return Feature
*/
public function setValues($values)
{
$this->values = $values;
return $this;
}
/**
* "setValues" alias to fit Thelia model.
*
* @param array $values
*
* @return Feature
*/
public function setFeatureAvs($values)
{
return $this->setValues($values);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class FeatureValue.
*
* @OA\Schema(
* description="A feature value"
* )
*/
class FeatureValue extends BaseApiModel
{
static $serviceAliases = ["FeatureAv"];
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return FeatureValue
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class File.
*
* @OA\Schema(
* description="A file for a product, brand, content, module, folder, category or PSE"
* )
*/
class File extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string",
* description="The file url",
* )
*/
protected $url;
/**
* @var int
* @OA\Property(
* type="integer",
* )
*/
protected $position;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return File
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*
* @return File
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* @param int $position
*
* @return File
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return File
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class Folder.
*
* @OA\Schema(
* description="A Folder"
* )
*/
class Folder extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Folder
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return Folder
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}

View File

@@ -0,0 +1,211 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
/**
* Class I18n.
*
* @OA\Schema(
* description="Translatable fields for multiple object"
* )
*/
class I18n extends BaseApiModel
{
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $title;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $description;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $chapo;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $postscriptum;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $metaTitle;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $metaDescription;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $metaKeywords;
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*
* @return I18n
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*
* @return I18n
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getChapo()
{
return $this->chapo;
}
/**
* @param string $chapo
*
* @return I18n
*/
public function setChapo($chapo)
{
$this->chapo = $chapo;
return $this;
}
/**
* @return string
*/
public function getPostscriptum()
{
return $this->postscriptum;
}
/**
* @param string $postscriptum
*
* @return I18n
*/
public function setPostscriptum($postscriptum)
{
$this->postscriptum = $postscriptum;
return $this;
}
/**
* @return string
*/
public function getMetaTitle()
{
return $this->metaTitle;
}
/**
* @param string $metaTitle
*
* @return I18n
*/
public function setMetaTitle($metaTitle)
{
$this->metaTitle = $metaTitle;
return $this;
}
/**
* @return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* @param string $metaDescription
*
* @return I18n
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
/**
* @return string
*/
public function getMetaKeywords()
{
return $this->metaKeywords;
}
/**
* @param string $metaKeywords
*
* @return I18n
*/
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Service\ImageService;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Thelia\TaxEngine\TaxEngine;
class Image extends File
{
/** @var ImageService */
protected $imageService;
public function __construct(ModelFactory $modelFactory, RequestStack $requestStack, TaxEngine $taxEngine, EventDispatcherInterface $dispatcher, ImageService $imageService)
{
parent::__construct($modelFactory, $requestStack, $taxEngine, $dispatcher);
$this->imageService = $imageService;
}
/**
* @param $theliaModel
* @param null $locale
* @param null $type
*
* @return $this
*/
public function createFromTheliaModel($theliaModel, $locale = null, $type = null)
{
parent::createFromTheliaModel($theliaModel, $locale);
$this->url = $this->imageService->getImageUrl($theliaModel, $type);
return $this;
}
}

View File

@@ -0,0 +1,411 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
/**
* @OA\Schema(
* schema="Lang",
* title="Lang",
* description="Lang model"
* )
*/
class Lang extends BaseApiModel
{
static $serviceAliases = ["Language"];
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $title;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $code;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $locale;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $url;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $dateFormat;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $timeFormat;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $datetimeFormat;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $decimalSeparator;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $thousandsSeparator;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $active;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $decimals;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $byDefault;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Lang
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*
* @return Lang
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*
* @return Lang
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return string
*/
public function getLocale()
{
return $this->locale;
}
/**
* @param string $locale
*
* @return Lang
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*
* @return Lang
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* @return string
*/
public function getDateFormat()
{
return $this->dateFormat;
}
/**
* @param string $dateFormat
*
* @return Lang
*/
public function setDateFormat($dateFormat)
{
$this->dateFormat = $dateFormat;
return $this;
}
/**
* @return string
*/
public function getTimeFormat()
{
return $this->timeFormat;
}
/**
* @param string $timeFormat
*
* @return Lang
*/
public function setTimeFormat($timeFormat)
{
$this->timeFormat = $timeFormat;
return $this;
}
/**
* @return string
*/
public function getDatetimeFormat()
{
return $this->datetimeFormat;
}
/**
* @param string $datetimeFormat
*
* @return Lang
*/
public function setDatetimeFormat($datetimeFormat)
{
$this->datetimeFormat = $datetimeFormat;
return $this;
}
/**
* @return string
*/
public function getDecimalSeparator()
{
return $this->decimalSeparator;
}
/**
* @param string $decimalSeparator
*
* @return Lang
*/
public function setDecimalSeparator($decimalSeparator)
{
$this->decimalSeparator = $decimalSeparator;
return $this;
}
/**
* @return string
*/
public function getThousandsSeparator()
{
return $this->thousandsSeparator;
}
/**
* @param string $thousandsSeparator
*
* @return Lang
*/
public function setThousandsSeparator($thousandsSeparator)
{
$this->thousandsSeparator = $thousandsSeparator;
return $this;
}
/**
* @return bool
*/
public function isActive()
{
return $this->active;
}
/**
* @param bool $active
*
* @return Lang
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* @param bool $visible
*
* @return Lang
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
/**
* @return string
*/
public function getDecimals()
{
return $this->decimals;
}
/**
* @param string $decimals
*
* @return Lang
*/
public function setDecimals($decimals)
{
$this->decimals = $decimals;
return $this;
}
/**
* @return bool
*/
public function isByDefault()
{
return $this->byDefault;
}
/**
* @param bool $byDefault
*
* @return Lang
*/
public function setByDefault($byDefault)
{
$this->byDefault = $byDefault;
return $this;
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\OpenApi;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Thelia\Log\Tlog;
class ModelFactory
{
/** @var Container */
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function buildModel($modelName, $data = null, $locale = null)
{
try {
$openApiModels = $this->container->getParameter(OpenApi::OPEN_API_MODELS_PARAMETER_KEY);
// If no correspondent OpenApi model was found
if (!\is_array($openApiModels) || !\array_key_exists($modelName, $openApiModels)) {
$modelName = rtrim($modelName, 's');
// Try to remove trailing "s" for plural
if (!\array_key_exists($modelName, $openApiModels)) {
return null;
}
}
$modelServiceId = $openApiModels[$modelName];
/** @var BaseApiModel $model */
$model = $this->container->get($modelServiceId);
if (null !== $data) {
$model->createOrUpdateFromData($data, $locale);
}
return $model;
} catch (\Exception $exception) {
Tlog::getInstance()->addError("Error for building api model \"$modelName\" : ".$exception->getMessage());
return null;
}
}
public function modelExists($modelName)
{
$openApiModels = $this->container->getParameter(OpenApi::OPEN_API_MODELS_PARAMETER_KEY);
if (!\is_array($openApiModels) || !\array_key_exists($modelName, $openApiModels)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace OpenApi\Model\Api\ModelTrait;
use OpenApi\Model\Api\I18n;
use OpenApi\Model\Api\ModelFactory;
/**
* @OA\Schema
* Trait translatable
*/
trait translatable
{
/**
* @var I18n
* @OA\Property(
* ref="#/components/schemas/I18n"
* )
*/
protected $i18n;
/**
* @param ModelFactory $modelFactory
*
* used to build an empty i18n model at model initialisation
*/
public function initI18n(ModelFactory $modelFactory): void
{
$this->i18n = $modelFactory->buildModel('I18n');
}
public function getI18n()
{
return $this->i18n;
}
/**
* @param string $title
*
* @return translatable
*/
public function setTitle($title)
{
$this->i18n->setTitle($title);
return $this;
}
/**
* @param string $description
*
* @return translatable
*/
public function setDescription($description)
{
$this->i18n->setDescription($description);
return $this;
}
/**
* @param string $chapo
*
* @return translatable
*/
public function setChapo($chapo)
{
$this->i18n->setChapo($chapo);
return $this;
}
/**
* @param string $postscriptum
*
* @return translatable
*/
public function setPostscriptum($postscriptum)
{
$this->i18n->setPostscriptum($postscriptum);
return $this;
}
/**
* @param string $metaTitle
*
* @return translatable
*/
public function setMetaTitle($metaTitle)
{
$this->i18n->setMetaTitle($metaTitle);
return $this;
}
/**
* @param string $metaDescription
*
* @return translatable
*/
public function setMetaDescription($metaDescription)
{
$this->i18n->setMetaDescription($metaDescription);
return $this;
}
/**
* @param string $metaKeywords
*
* @return translatable
*/
public function setMetaKeywords($metaKeywords)
{
$this->i18n->setMetaKeywords($metaKeywords);
return $this;
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Constraint as Constraint;
use OpenApi\Model\Api\ModelTrait\translatable;
/**
* Class PaymentModule.
*
* @OA\Schema(
* description="A module of type payment"
* )
*/
class PaymentModule extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer"
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
*/
protected $valid;
/**
* @var int
* @OA\Property(
* type="integer"
* )
*/
protected $code;
/**
* @var float
* @OA\Property(
* type="number",
* format="float"
* )
*/
protected $minimumAmount;
/**
* @var float
* @OA\Property(
* type="number",
* format="float"
* )
*/
protected $maximumAmount;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $images = [];
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return PaymentModule
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isValid()
{
return $this->valid;
}
/**
* @param bool $valid
*
* @return PaymentModule
*/
public function setValid($valid)
{
$this->valid = $valid;
return $this;
}
/**
* @return int
*/
public function getCode()
{
return $this->code;
}
/**
* @param int $code
*
* @return PaymentModule
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return float
*/
public function getMinimumAmount()
{
return $this->minimumAmount;
}
/**
* @param float $minimumAmount
*
* @return PaymentModule
*/
public function setMinimumAmount($minimumAmount)
{
$this->minimumAmount = $minimumAmount;
return $this;
}
/**
* @return float
*/
public function getMaximumAmount()
{
return $this->maximumAmount;
}
/**
* @param float $maximumAmount
*
* @return PaymentModule
*/
public function setMaximumAmount($maximumAmount)
{
$this->maximumAmount = $maximumAmount;
return $this;
}
/**
* @return array
*/
public function getImages()
{
return $this->images;
}
/**
* @param array $images
*
* @return PaymentModule
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
}

View File

@@ -0,0 +1,158 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
/**
* @OA\Schema(
* title="PickupLocation",
* description="PickupLocation model"
* )
*/
class PickupLocation extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $latitude;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $longitude;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $title;
/**
* @var Address
* @OA\Property(
* ref="#/components/schemas/Address"
* )
*/
protected $address;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return PickupLocation
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return float
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* @param float $latitude
*
* @return PickupLocation
*/
public function setLatitude($latitude)
{
$this->latitude = $latitude;
return $this;
}
/**
* @return float
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* @param float $longitude
*
* @return PickupLocation
*/
public function setLongitude($longitude)
{
$this->longitude = $longitude;
return $this;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*
* @return PickupLocation
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return Address
*/
public function getAddress()
{
return $this->address;
}
/**
* @param Address $address
*
* @return PickupLocation
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use Thelia\Model\Country;
use Thelia\Model\ProductPriceQuery;
use Thelia\Model\ProductSaleElements;
/**
* Class Price.
*
* @OA\Schema(
* description="A price"
* )
*/
class Price extends BaseApiModel
{
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $untaxed;
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* )
*/
protected $taxed;
/**
* Create a new OpenApi Price from a Thelia ProductSaleElements and a Country, then returns it.
*
* @param bool $isPromo
*
* @return $this
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function fillFromTheliaPseAndCountry(ProductSaleElements $pse, Country $country, $isPromo = false)
{
$price = ProductPriceQuery::create()->filterByProductSaleElements($pse)->findOne();
$pse->setVirtualColumn('price_PRICE', (float) $price->getPrice());
$pse->setVirtualColumn('price_PROMO_PRICE', (float) $price->getPromoPrice());
$this->untaxed = $isPromo ? $pse->getPromoPrice() : $pse->getPrice();
$this->taxed = $isPromo ? $pse->getTaxedPromoPrice($country) : $pse->getTaxedPrice($country);
return $this;
}
/**
* @return float
*/
public function getUntaxed()
{
return $this->untaxed;
}
/**
* @param float $untaxed
*
* @return Price
*/
public function setUntaxed($untaxed)
{
$this->untaxed = $untaxed;
return $this;
}
/**
* @return float
*/
public function getTaxed()
{
return $this->taxed;
}
/**
* @param float $taxed
*
* @return Price
*/
public function setTaxed($taxed)
{
$this->taxed = $taxed;
return $this;
}
}

View File

@@ -0,0 +1,428 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use OpenApi\Model\Api\ModelTrait\translatable;
use Thelia\Model\Base\ProductCategory;
use Thelia\Model\FeatureProduct;
/**
* Class Product.
*
* @OA\Schema(
* description="A product"
* )
*/
class Product extends BaseApiModel
{
use translatable;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $reference;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $url;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $virtual;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @var Brand
* @OA\Property(
* ref="#/components/schemas/Brand"
* )
*/
protected $brand;
/**
* @var Category
* @OA\Property(
* ref="#/components/schemas/Category"
* )
*/
protected $defaultCategory;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Category"
* )
* )
*/
protected $categories;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Content"
* )
* )
*/
protected $contents = [];
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $images = [];
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $documents = [];
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Feature"
* )
* )
*/
protected $features = [];
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/ProductSaleElement"
* )
* )
*/
protected $productSaleElements = [];
/**
* @param \Thelia\Model\Product $theliaModel
* @param null $locale
*
* @return Product|void
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function createFromTheliaModel($theliaModel, $locale = null)
{
parent::createFromTheliaModel($theliaModel, $locale);
$modelFactory = $this->modelFactory;
$this->features = array_filter(
array_map(
function (FeatureProduct $featureProduct) use ($modelFactory) {
$propelFeature = $featureProduct->getFeature();
if (null === $propelFeature){
return false;
}
if (null !== $featureProduct->getFeatureAv()) {
// Temporary set only product feature av to build good feature av list
$propelFeature->addFeatureAv($featureProduct->getFeatureAv());
}
$propelFeature->resetPartialFeatureAvs(false);
$feature = $modelFactory->buildModel('Feature', $propelFeature);
$propelFeature->clearFeatureAvs();
return $feature;
},
iterator_to_array($theliaModel->getFeatureProducts())),
function($value){
return $value;
}
);
$this->categories = array_map(
function (ProductCategory $productCategory) use ($modelFactory) {
$propelCategory = $productCategory->getCategory();
$category = $modelFactory->buildModel('Category', $propelCategory);
if ($productCategory->isDefaultCategory()) {
$this->defaultCategory = $category;
}
return $category;
},
iterator_to_array($theliaModel->getProductCategories())
);
usort($this->images, function ($item1, $item2) {
return $item1->getPosition() <=> $item2->getPosition();
});
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return Product
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getReference()
{
return $this->reference;
}
/**
* @param string $reference
*
* @return Product
*/
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
/**
* Method alias to match thelia getter name.
*
* @param string $reference
*
* @return Product
*/
public function setRef($reference)
{
$this->setReference($reference);
return $this;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*
* @return Product
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* @return array
*/
public function getImages()
{
return $this->images;
}
/**
* @param array $images
*
* @return Product
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
/**
* @return array
*/
public function getProductSaleElements()
{
return $this->productSaleElements;
}
/**
* @param array $productSaleElements
*
* @return Product
*/
public function setProductSaleElements($productSaleElements)
{
$this->productSaleElements = $productSaleElements;
return $this;
}
public function isVirtual(): bool
{
return $this->virtual;
}
public function setVirtual(bool $virtual): self
{
$this->virtual = $virtual;
return $this;
}
public function isVisible(): bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
/**
* @return Brand
*/
public function getBrand(): ?Brand
{
return $this->brand;
}
/**
* @param Brand $brand
*/
public function setBrand(Brand $brand = null): self
{
$this->brand = $brand;
return $this;
}
public function getDefaultCategory(): Category
{
return $this->defaultCategory;
}
public function setDefaultCategory(Category $defaultCategory): self
{
$this->defaultCategory = $defaultCategory;
return $this;
}
public function getCategories(): array
{
return $this->categories;
}
public function setCategories(array $categories): self
{
$this->categories = $categories;
return $this;
}
/**
* Method alias to match thelia getter name.
*/
public function setProductCategories(array $categories = []): self
{
return $this->setCategories($categories);
}
public function getContents(): array
{
return $this->contents;
}
public function setContents(array $contents = []): self
{
$this->contents = $contents;
return $this;
}
public function getDocuments(): array
{
return $this->documents;
}
public function setDocuments(array $documents = []): self
{
$this->documents = $documents;
return $this;
}
/**
* Method alias to match thelia getter name.
*/
public function setProductDocuments(array $documents = []): self
{
return $this->setDocuments($documents);
}
public function getFeatures(): array
{
return $this->features;
}
}

View File

@@ -0,0 +1,502 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint as Constraint;
use Propel\Runtime\Collection\Collection;
use Thelia\Model\AttributeCombination;
use Thelia\Model\Country;
use Thelia\Model\ProductPriceQuery;
use Thelia\Model\ProductSaleElements;
/**
* Class ProductSaleElement.
*
* @OA\Schema(
* description="A product sale element"
* )
*/
class ProductSaleElement extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $isPromo;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $reference;
/**
* @var array
* @OA\Property(
* description="List of the attributes and its value used by this pse",
* type="array",
* @OA\Items(
* ref="#/components/schemas/Attribute"
* )
* )
*/
protected $attributes;
/**
* @var float
* @OA\Property(
* type="number",
* format="float"
* )
*/
protected $quantity;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
*/
protected $newness;
/**
* @var float
* @OA\Property(
* type="number",
* format="float"
* )
*/
protected $weight;
/**
* @var bool
* @OA\Property(
* type="boolean"
* )
*/
protected $isDefault;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $ean;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $images;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/File"
* )
* )
*/
protected $documents;
/**
* @var Price
* @OA\Property(
* type="object",
* ref="#/components/schemas/Price"
* )
*/
protected $price;
/**
* @var Price
* @OA\Property(
* type="object",
* ref="#/components/schemas/Price"
* )
*/
protected $promoPrice;
/**
* @param ProductSaleElements $theliaModel
* @param null $locale
*
* @return ProductSaleElement|void
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function createFromTheliaModel($theliaModel, $locale = null)
{
$price = ProductPriceQuery::create()->filterByProductSaleElements($theliaModel)->findOne();
$theliaModel->setVirtualColumn('price_PRICE', (float) $price->getPrice());
$theliaModel->setVirtualColumn('price_PROMO_PRICE', (float) $price->getPromoPrice());
parent::createFromTheliaModel($theliaModel, $locale);
$modelFactory = $this->modelFactory;
$this->attributes = array_map(
function (AttributeCombination $attributeCombination) use ($modelFactory) {
$propelAttribute = $attributeCombination->getAttribute();
// Temporary set only pse attribute av to build good attribute av list
$propelAttribute->addAttributeAv($attributeCombination->getAttributeAv());
$attribute = $modelFactory->buildModel('Attribute', $propelAttribute);
// Reset attribute av to all for next use of attribute (because of propel "cache")
$propelAttribute->clearAttributeAvs();
return $attribute;
},
iterator_to_array($theliaModel->getAttributeCombinations())
);
$this->isPromo = (bool) $theliaModel->getPromo();
$this->price = $this->modelFactory->buildModel('Price', ['untaxed' => $theliaModel->getPrice(), 'taxed' => $theliaModel->getTaxedPrice($this->country)]);
$this->promoPrice = $this->modelFactory->buildModel('Price', ['untaxed' => $theliaModel->getPromoPrice(), 'taxed' => $theliaModel->getTaxedPromoPrice($this->country)]);
}
/**
* Create an OpenApi ProductSaleElement from a Thelia ProductSaleElements and a Country, then returns it.
*
* @return $this
*
* @throws \Propel\Runtime\Exception\PropelException
*/
public function fillFromTheliaPseAndCountry(ProductSaleElements $pse, Country $country)
{
$modelFactory = $this->modelFactory;
$attributes = array_map(
function (AttributeCombination $attributeCombination) use ($modelFactory) {
$attribute = $attributeCombination->getAttribute();
$attribute->setAttributeAvs((new Collection()));
$attribute->addAttributeAv($attributeCombination->getAttributeAv());
return $modelFactory->buildModel('Attribute', $attribute);
},
iterator_to_array($pse->getAttributeCombinations())
);
$this->id = $pse->getId();
$this->isPromo = (bool) $pse->getPromo();
/** @var Price $price */
$price = $this->modelFactory->buildModel('Price');
$price->fillFromTheliaPseAndCountry($pse, $country);
$this->price = $price;
/** @var Price $promoPrice */
$promoPrice = $this->modelFactory->buildModel('Price');
$promoPrice->fillFromTheliaPseAndCountry($pse, $country);
$this->promoPrice = $price;
$this->weight = $pse->getWeight();
$this->reference = $pse->getRef();
$this->attributes = $attributes;
$this->quantity = $pse->getQuantity();
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return ProductSaleElement
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isPromo()
{
return $this->isPromo;
}
/**
* @param bool $isPromo
*
* @return ProductSaleElement
*/
public function setIsPromo($isPromo)
{
$this->isPromo = $isPromo;
return $this;
}
/**
* @return string
*/
public function getReference()
{
return $this->reference;
}
/**
* @param string $reference
*
* @return ProductSaleElement
*/
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
/**
* @param $reference
*
* @return $this
*/
public function setRef($reference)
{
return $this->setReference($reference);
}
/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param array $attributes
*
* @return ProductSaleElement
*/
public function setAttributes($attributes)
{
$this->attributes = $attributes;
return $this;
}
/**
* @return float
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param float $quantity
*
* @return ProductSaleElement
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* @return bool
*/
public function isNewness()
{
return $this->newness;
}
/**
* @param bool $newness
*
* @return ProductSaleElement
*/
public function setNewness($newness)
{
$this->newness = $newness;
return $this;
}
/**
* @return float
*/
public function getWeight()
{
return $this->weight;
}
/**
* @param float $weight
*
* @return ProductSaleElement
*/
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
/**
* @return bool
*/
public function isDefault()
{
return $this->isDefault;
}
/**
* @param bool $isDefault
*
* @return ProductSaleElement
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
return $this;
}
/**
* @return string
*/
public function getEan()
{
return $this->ean;
}
/**
* @param string $ean
*
* @return ProductSaleElement
*/
public function setEan($ean)
{
$this->ean = $ean;
return $this;
}
/**
* @param string $ean
*
* @return ProductSaleElement
*/
public function setEanCode($ean)
{
return $this->setEan($ean);
}
/**
* @return array
*/
public function getImages()
{
return $this->images;
}
/**
* @param array $images
*
* @return ProductSaleElement
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}
/**
* @return array
*/
public function getDocuments()
{
return $this->documents;
}
/**
* @param array $documents
*
* @return ProductSaleElement
*/
public function setDocuments($documents)
{
$this->documents = $documents;
return $this;
}
/**
* @return Price
*/
public function getPrice()
{
return $this->price;
}
/**
* @param Price $price
*
* @return ProductSaleElement
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return Price
*/
public function getPromoPrice()
{
return $this->promoPrice;
}
/**
* @param Price $promoPrice
*
* @return ProductSaleElement
*/
public function setPromoPrice($promoPrice)
{
$this->promoPrice = $promoPrice;
return $this;
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace OpenApi\Model\Api;
/**
* Class Result.
*
* @OA\Schema(
* description="A result (to be in search object)"
* )
*/
class Result extends BaseApiModel
{
/**
* @var float
* @OA\Property(
* type="number",
* format="float",
* description="The weight of result in search"
* )
*/
protected $weight;
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $type;
/**
* @var BaseApiModel
* @OA\Property(
* type="object",
* description="Almost any of OpenApi object"
* )
*/
protected $object;
/**
* @return float
*/
public function getWeight()
{
return $this->weight;
}
/**
* @param float $weight
*
* @return Result
*/
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*
* @return Result
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* @return BaseApiModel
*/
public function getObject()
{
return $this->object;
}
/**
* @param BaseApiModel $object
*
* @return Result
*/
public function setObject($object)
{
$this->object = $object;
return $this;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace OpenApi\Model\Api;
use OpenApi\Annotations as OA;
/**
* Class SchemaViolation.
*
* @OA\Schema(
* description="A schema violation"
* )
*/
class SchemaViolation extends BaseApiModel
{
/**
* @var string
* @OA\Property(
* type="string"
* )
*/
protected $message;
/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* @param string $message
*
* @return SchemaViolation
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace OpenApi\Model\Api;
/**
* Class Search.
*
* @OA\Schema(
* description="A search response"
* )
*/
class Search extends BaseApiModel
{
/**
* @var Result
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Result"
* )
* )
*/
protected $results;
/**
* @var int
* @OA\Property(
* type="number",
* format="integer"
* )
*/
protected $page;
/**
* @var int
* @OA\Property(
* type="number",
* format="integer",
* description="The total of results for current page"
* )
*/
protected $pageTotal;
/**
* @var int
* @OA\Property(
* type="number",
* format="integer",
* description="The whole total of results (without paging)"
* )
*/
protected $total;
/**
* @return Result
*/
public function getResults()
{
return $this->results;
}
/**
* @param Result $results
*
* @return Search
*/
public function setResults($results)
{
$this->results = $results;
return $this;
}
/**
* @return int
*/
public function getPage()
{
return $this->page;
}
/**
* @param int $page
*
* @return Search
*/
public function setPage($page)
{
$this->page = $page;
return $this;
}
/**
* @return int
*/
public function getPageTotal()
{
return $this->pageTotal;
}
/**
* @param int $pageTotal
*
* @return Search
*/
public function setPageTotal($pageTotal)
{
$this->pageTotal = $pageTotal;
return $this;
}
/**
* @return int
*/
public function getTotal()
{
return $this->total;
}
/**
* @param int $total
*
* @return Search
*/
public function setTotal($total)
{
$this->total = $total;
return $this;
}
}