Skip to content

Commit

Permalink
MM-38: Implement sync processors (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-parkhomenko authored and 24198 committed Aug 12, 2020
1 parent 1d6be06 commit 49b6550
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 89 deletions.
41 changes: 38 additions & 3 deletions src/Marello/Bundle/OrderBundle/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ class Order extends ExtendOrder implements
*/
protected $currency;

/**
* Represent locale in ICU format
*
* @var string
*
* @ORM\Column(name="locale_id", type="string", length=255, nullable=true)
*/
protected $localeId;

/**
* @var string
* @ORM\Column(name="payment_method", type="string", length=255, nullable=true)
Expand Down Expand Up @@ -359,6 +368,9 @@ class Order extends ExtendOrder implements
* @ORM\OrderBy({"id" = "ASC"})
* @Oro\ConfigField(
* defaultValues={
* "importexport"={
* "full"=true
* },
* "email"={
* "available_in_template"=true
* },
Expand Down Expand Up @@ -392,6 +404,9 @@ class Order extends ExtendOrder implements
* @ORM\JoinColumn(name="billing_address_id", referencedColumnName="id")
* @Oro\ConfigField(
* defaultValues={
* "importexport"={
* "full"=true
* },
* "dataaudit"={
* "auditable"=true
* }
Expand All @@ -407,6 +422,9 @@ class Order extends ExtendOrder implements
* @ORM\JoinColumn(name="shipping_address_id", referencedColumnName="id")
* @Oro\ConfigField(
* defaultValues={
* "importexport"={
* "full"=true
* },
* "dataaudit"={
* "auditable"=true
* }
Expand Down Expand Up @@ -436,9 +454,6 @@ class Order extends ExtendOrder implements
* @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
* @Oro\ConfigField(
* defaultValues={
* "importexport"={
* "full"=true
* },
* "dataaudit"={
* "auditable"=true
* }
Expand Down Expand Up @@ -837,6 +852,26 @@ public function setCurrency($currency)
return $this;
}

/**
* @param string $localeId
*
* @return $this
*/
public function setLocaleId($localeId)
{
$this->localeId = $localeId;

return $this;
}

/**
* @return string
*/
public function getLocaleId()
{
return $this->localeId;
}

/**
* @return string
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Marello/Bundle/OrderBundle/Entity/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ public function __construct()
*/
public function prePersist()
{
if (null === $this->product) {
return;
}

// prevent overriding product name if already being set
if (is_null($this->productName)) {
$this->setProductName((string)$this->product->getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MarelloOrderBundleInstaller implements
*/
public function getMigrationVersion()
{
return 'v1_13';
return 'v1_13_1';
}

/**
Expand Down Expand Up @@ -82,6 +82,7 @@ protected function createMarelloOrderOrderTable(Schema $schema)
$table->addColumn('subtotal', 'money', ['precision' => 19, 'scale' => 4, 'comment' => '(DC2Type:money)']);
$table->addColumn('total_tax', 'money', ['precision' => 19, 'scale' => 4, 'comment' => '(DC2Type:money)']);
$table->addColumn('grand_total', 'money', ['precision' => 19, 'scale' => 4, 'comment' => '(DC2Type:money)']);
$table->addColumn('locale_id', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('currency', 'string', ['notnull' => false, 'length' => 10]);
$table->addColumn('payment_method', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Marello\Bundle\OrderBundle\Migrations\Schema\v1_13_1;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\MigrationBundle\Migration\QueryBag;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\EntityConfigBundle\Migration\UpdateEntityConfigFieldValueQuery;

use Marello\Bundle\OrderBundle\Entity\Order;

class MarelloOrderBundle implements Migration
{
/**
* {@inheritDoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$table = $schema->getTable('marello_order_order');
$table->addColumn('locale_id', 'string', ['notnull' => false, 'length' => 255]);

$queries->addQuery(
new UpdateEntityConfigFieldValueQuery(
Order::class,
'salesChannel',
'importexport',
'full',
false
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ Marello\Bundle\OrderBundle\Entity\Order:
- NotBlank: { groups: [Default, commerce], message: 'marello.order.address.validation.billing_not_blank' }
shippingAddress:
- NotBlank: { groups: [Default, commerce], message: 'marello.order.address.validation.shipping_not_blank' }

items:
- Count:
min: 1
minMessage: 'marello.order.item.count'
- Valid: ~
constraints:
- Marello\Bundle\CoreBundle\Validator\Constraints\GreaterThanDate:
field: 'deliveryDate'
greaterThan: 'today'
nullable: true
errorPath: deliveryDate
message: 'marello.order.delivery_date.messages.error.greater_than_date'
message: 'marello.order.delivery_date.messages.error.greater_than_date'
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
marello:
order:
shipping_method.label: Shipping Method
locale_id.label: Locale ID
previous_shipping_method.label: Previously selected Shipping Method
possible_shipping_methods.no_method: No shipping methods are available
possible_shipping_methods.confirmation.title: Review Shipping Cost
Expand All @@ -12,4 +13,4 @@ marello:
possible_payment_methods.confirmation.title: Review Payment Methods
possible_payment_methods.confirmation.content: As order content has been modified, payment methods may have changed. Please, review the payment method selection before saving the order to make sure that the payment method is acceptable.

continue_editing: Continue Editing
continue_editing: Continue Editing
Original file line number Diff line number Diff line change
Expand Up @@ -135,34 +135,6 @@ public function testValidateWithInvalidEntityMapping()
$this->getValidator()->validate(new \StdClass(), $this->getConstraint());
}

/**
* {@inheritdoc}
*/
public function testValidateNoValueForProperty()
{
$entity = new \StdClass();
$entity->test = null;

$this->doctrineHelper->expects($this->once())
->method('getEntityManagerForClass')
->willReturn($this->objectManager);

$this->objectManager->expects($this->once())
->method('getClassMetadata')
->willReturn($this->classMetaData);

$this->classMetaData->expects($this->atLeastOnce())
->method('hasField')
->willReturn(true);

$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage(
'Cannot get inventory when not all required values are set'
);

$this->getValidator()->validate($entity, $this->getConstraint(['fields' => ['test']]));
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -220,50 +192,6 @@ public function testValidateViolationIsBuild()
$this->getValidator()->validate($entity, $constraint);
}

/**
* {@inheritdoc}
*/
public function testQuantityFieldIsNotSet()
{
$orderMock = $this->createMock(Order::class);
$salesChannelMock = $this->createMock(SalesChannel::class);
$entity = new \StdClass();
$entity->product = $this->createMock(Product::class);
$entity->order = $orderMock;
$constraint = $this->getConstraint([
'fields' => ['product', 'order'],
'errorPath' => 'quantity'
]);

$this->doctrineHelper->expects($this->once())
->method('getEntityManagerForClass')
->willReturn($this->objectManager);

$this->objectManager->expects($this->once())
->method('getClassMetadata')
->willReturn($this->classMetaData);

$this->classMetaData->expects($this->atLeastOnce())
->method('hasField')
->willReturn(true);

$orderMock->expects($this->atLeastOnce())
->method('getSalesChannel')
->willReturn($salesChannelMock);

$this->inventoryProvider->expects($this->exactly(1))
->method('getAvailableInventory')
->with($entity->product, $salesChannelMock)
->willReturn(100);

$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage(
'Cannot compare values if because there nothing to compare'
);

$this->getValidator()->validate($entity, $constraint);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ public function validate($entity, Constraint $constraint)
}

$values = $this->entityGetFieldValues($entity, $fields);
if ((!isset($values[self::PRODUCT_FIELD]) || $values[self::PRODUCT_FIELD] === null) ||
(!isset($values[self::SALES_CHANNEL_FIELD]) || $values[self::SALES_CHANNEL_FIELD] === null)) {
throw new ConstraintDefinitionException('Cannot get inventory when not all required values are set');

/**
* In case when some required data is not available we skip validation because specific validators
* for these fields must catch them
*/
if (!$this->isAllRequiredFieldsHasValue($values)) {
return;
}

$result = $this->availableInventoryProvider
Expand All @@ -103,10 +107,6 @@ public function validate($entity, Constraint $constraint)
$values[self::QUANTITY_FIELD] += $this->collection[$productSku];
}

if (!isset($values[self::QUANTITY_FIELD])) {
throw new ConstraintDefinitionException('Cannot compare values if because there nothing to compare');
}

if (!$this->compareValues($result, $values[self::QUANTITY_FIELD])) {
if (isset($values[self::PRODUCT_FIELD])) {
$violation = true;
Expand Down Expand Up @@ -331,6 +331,22 @@ private function entityGetFieldValues($entity, $fields)
return $results;
}

/**
* @param array $values
* @return bool
*/
protected function isAllRequiredFieldsHasValue(array $values): bool
{
$requiredFields = [self::PRODUCT_FIELD, self::SALES_CHANNEL_FIELD, self::PRODUCT_FIELD];
foreach ($requiredFields as $requiredField) {
if (!\array_key_exists($requiredField, $values)) {
return false;
}
}

return true;
}

/**
* Get field to display Error from config or use the first field in the array
* @param Constraint $constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Oro\Bundle\SecurityBundle\Acl\Voter\AbstractEntityVoter;

/**
* Disables deleting the sales channel group in case when it has attached integration
* Disable deletion of the sales channel group in the case when it has been attached integration
*/
class SalesChannelGroupVoter extends AbstractEntityVoter
{
Expand Down
2 changes: 0 additions & 2 deletions src/Marello/Bundle/SalesBundle/Entity/SalesChannelGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ class SalesChannelGroup extends ExtendSalesChannelGroup
protected $system = false;

/**
* @todo Add restriction on removing sales channel from the group in case when it attached to the integration
*
* @var SalesChannel[]
*
* @ORM\OneToMany(targetEntity="SalesChannel", mappedBy="group", cascade={"persist"}, fetch="EAGER")
Expand Down

0 comments on commit 49b6550

Please sign in to comment.