Skip to content

Commit

Permalink
added initialization of Data multilanguage properties
Browse files Browse the repository at this point in the history
- for all locales
- initializes with null (as the current admin form does)
- changed phpdoc of multilanguage properties appropriately
  • Loading branch information
Svaťa Šimara committed Feb 12, 2019
1 parent 3056ac2 commit 7412b0e
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/framework/src/Model/Category/CategoryData.php
Expand Up @@ -8,7 +8,7 @@
class CategoryData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
4 changes: 4 additions & 0 deletions packages/framework/src/Model/Category/CategoryDataFactory.php
Expand Up @@ -81,6 +81,10 @@ protected function fillNew(CategoryData $categoryData)
$categoryData->descriptions[$domainId] = null;
$categoryData->enabled[$domainId] = true;
}

foreach ($this->domain->getAllLocales() as $locale) {
$categoryData->name[$locale] = null;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Model/Country/CountryData.php
Expand Up @@ -5,7 +5,7 @@
class CountryData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $names;

Expand Down
4 changes: 4 additions & 0 deletions packages/framework/src/Model/Country/CountryDataFactory.php
Expand Up @@ -73,5 +73,9 @@ protected function fillNew(CountryData $countryData): void
$countryData->enabled[$domainId] = true;
$countryData->priority[$domainId] = null;
}

foreach ($this->domain->getAllLocales() as $locale) {
$countryData->names[$locale] = null;
}
}
}
Expand Up @@ -5,7 +5,7 @@
class OrderStatusData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
Expand Up @@ -2,14 +2,41 @@

namespace Shopsys\FrameworkBundle\Model\Order\Status;

use Shopsys\FrameworkBundle\Component\Domain\Domain;

class OrderStatusDataFactory implements OrderStatusDataFactoryInterface
{
/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
*/
protected $domain;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(Domain $domain)
{
$this->domain = $domain;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusData
*/
public function create(): OrderStatusData
{
return new OrderStatusData();
$orderStatusData = new OrderStatusData();
$this->fillNew($orderStatusData);
return $orderStatusData;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusData $orderStatusData
*/
protected function fillNew(OrderStatusData $orderStatusData): void
{
foreach ($this->domain->getAllLocales() as $locale) {
$orderStatusData->name[$locale] = null;
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/src/Model/Payment/PaymentData.php
Expand Up @@ -7,7 +7,7 @@
class PaymentData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand All @@ -17,12 +17,12 @@ class PaymentData
public $vat;

/**
* @var string[]
* @var string[]|null[]
*/
public $description;

/**
* @var string[]
* @var string[]|null[]
*/
public $instructions;

Expand Down
6 changes: 6 additions & 0 deletions packages/framework/src/Model/Payment/PaymentDataFactory.php
Expand Up @@ -58,6 +58,12 @@ protected function fillNew(PaymentData $paymentData): void
foreach ($this->domain->getAllIds() as $domainId) {
$paymentData->enabled[$domainId] = true;
}

foreach ($this->domain->getAllLocales() as $locale) {
$paymentData->name[$locale] = null;
$paymentData->description[$locale] = null;
$paymentData->instructions[$locale] = null;
}
}

/**
Expand Down
Expand Up @@ -5,7 +5,7 @@
class AvailabilityData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
Expand Up @@ -2,14 +2,41 @@

namespace Shopsys\FrameworkBundle\Model\Product\Availability;

use Shopsys\FrameworkBundle\Component\Domain\Domain;

class AvailabilityDataFactory implements AvailabilityDataFactoryInterface
{
/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
*/
protected $domain;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(Domain $domain)
{
$this->domain = $domain;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityData
*/
public function create(): AvailabilityData
{
return new AvailabilityData();
$availabilityData = new AvailabilityData();
$this->fillNew($availabilityData);
return $availabilityData;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Product\Availability\AvailabilityData $availabilityData
*/
protected function fillNew(AvailabilityData $availabilityData): void
{
foreach ($this->domain->getAllLocales() as $locale) {
$availabilityData->name[$locale] = null;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Model/Product/Brand/BrandData.php
Expand Up @@ -18,7 +18,7 @@ class BrandData
public $image;

/**
* @var string[]
* @var string[]|null[]
*/
public $descriptions;

Expand Down
Expand Up @@ -58,6 +58,10 @@ protected function fillNew(BrandData $brandData)
$brandData->seoTitles[$domainId] = null;
$brandData->seoH1s[$domainId] = null;
}

foreach ($this->domain->getAllLocales() as $locale) {
$brandData->descriptions[$locale] = null;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Model/Product/Flag/FlagData.php
Expand Up @@ -5,7 +5,7 @@
class FlagData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
29 changes: 28 additions & 1 deletion packages/framework/src/Model/Product/Flag/FlagDataFactory.php
Expand Up @@ -2,14 +2,41 @@

namespace Shopsys\FrameworkBundle\Model\Product\Flag;

use Shopsys\FrameworkBundle\Component\Domain\Domain;

class FlagDataFactory implements FlagDataFactoryInterface
{
/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
*/
protected $domain;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(Domain $domain)
{
$this->domain = $domain;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Product\Flag\FlagData
*/
public function create(): FlagData
{
return new FlagData();
$flagData = new FlagData();
$this->fillNew($flagData);
return $flagData;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Product\Flag\FlagData $flagData
*/
protected function fillNew(FlagData $flagData): void
{
foreach ($this->domain->getAllLocales() as $locale) {
$flagData->name[$locale] = null;
}
}

/**
Expand Down
Expand Up @@ -5,7 +5,7 @@
class ParameterData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
Expand Up @@ -2,14 +2,41 @@

namespace Shopsys\FrameworkBundle\Model\Product\Parameter;

use Shopsys\FrameworkBundle\Component\Domain\Domain;

class ParameterDataFactory implements ParameterDataFactoryInterface
{
/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
*/
protected $domain;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(Domain $domain)
{
$this->domain = $domain;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterData
*/
public function create(): ParameterData
{
return new ParameterData();
$parameterData = new ParameterData();
$this->fillNew($parameterData);
return $parameterData;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterData $parameterData
*/
protected function fillNew(ParameterData $parameterData): void
{
foreach ($this->domain->getAllLocales() as $locale) {
$parameterData->name[$locale] = null;
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/Model/Product/ProductData.php
Expand Up @@ -8,7 +8,7 @@
class ProductData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down Expand Up @@ -98,7 +98,7 @@ class ProductData
public $brand;

/**
* @var string[]
* @var string[]|null[]
*/
public $variantAlias;

Expand Down
7 changes: 6 additions & 1 deletion packages/framework/src/Model/Product/ProductDataFactory.php
Expand Up @@ -133,7 +133,7 @@ public function create(): ProductData
* @param mixed $productData
* @param \Shopsys\FrameworkBundle\Model\Product\ProductData
*/
protected function fillNew($productData)
protected function fillNew(ProductData $productData)
{
$productData->vat = $this->vatFacade->getDefaultVat();
$productData->unit = $this->unitFacade->getDefaultUnit();
Expand All @@ -150,6 +150,11 @@ protected function fillNew($productData)
$productData->descriptions = $nullForAllDomains;
$productData->shortDescriptions = $nullForAllDomains;
$productData->accessories = [];

foreach ($this->domain->getAllLocales() as $locale) {
$productData->name[$locale] = null;
$productData->variantAlias[$locale] = null;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Model/Product/Unit/UnitData.php
Expand Up @@ -5,7 +5,7 @@
class UnitData
{
/**
* @var string[]
* @var string[]|null[]
*/
public $name;

Expand Down
29 changes: 28 additions & 1 deletion packages/framework/src/Model/Product/Unit/UnitDataFactory.php
Expand Up @@ -2,14 +2,41 @@

namespace Shopsys\FrameworkBundle\Model\Product\Unit;

use Shopsys\FrameworkBundle\Component\Domain\Domain;

class UnitDataFactory implements UnitDataFactoryInterface
{
/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
*/
protected $domain;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(Domain $domain)
{
$this->domain = $domain;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Product\Unit\UnitData
*/
public function create(): UnitData
{
return new UnitData();
$unitData = new UnitData();
$this->fillNew($unitData);
return $unitData;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Product\Unit\UnitData $unitData
*/
protected function fillNew(UnitData $unitData): void
{
foreach ($this->domain->getAllLocales() as $locale) {
$unitData->name[$locale] = null;
}
}

/**
Expand Down

0 comments on commit 7412b0e

Please sign in to comment.