Skip to content

Commit

Permalink
Do requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Oct 11, 2024
1 parent 763ae6d commit d35d10f
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 83 deletions.
4 changes: 2 additions & 2 deletions config/feed_routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
->controller(['webgriffe_sylius_clerk_plugin.controller.feed', '__invoke'])
->methods(['GET'])
->requirements([
'channelId' => '\d+',
'channelCode' => '\d+',
'localeCode' => '^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$',
'resource' => class_exists(EnumRequirement::class) ? new EnumRequirement(Resource::class) : 'products|categories|orders|customers|pages',
'resourceValue' => class_exists(EnumRequirement::class) ? new EnumRequirement(Resource::class) : 'products|categories|orders|customers|pages',
])
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function getResult(
$queryBuilder
->leftJoin('t.translations', 'tt', 'WITH', 'tt.locale = :localeCode')
->setParameter('localeCode', $localeCode)
->andWhere('t.enabled = true')
;

if ($modifiedAfter !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function getResult(
->andWhere('o.channel = :channel')
->setParameter('channel', $channel)
->andWhere('o.checkoutCompletedAt IS NOT NULL')
->andWhere('o.localeCode = :localeCode')
->setParameter('localeCode', $localeCode)
;

if ($modifiedAfter !== null) {
Expand Down
5 changes: 2 additions & 3 deletions src/DataSyncInfrastructure/Normalizer/CategoryNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function __construct(
* name: string,
* url: string,
* subcategories: array<int|string>,
* image?: string,
* description?: string,
* }
* }&array<string, mixed>
*/
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
Expand Down Expand Up @@ -104,6 +102,7 @@ private function getUrlOfTaxon(TaxonTranslationInterface $taxonTranslation, Chan
],
UrlGeneratorInterface::ABSOLUTE_URL,
);
Assert::stringNotEmpty($url);

$channelRequestContext->setHost($previousHost);

Expand Down
27 changes: 1 addition & 26 deletions src/DataSyncInfrastructure/Normalizer/CustomerNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Normalizer;

use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -27,11 +26,7 @@ public function __construct(
* name: string,
* email: string,
* subscribed: bool,
* zip?: string,
* gender?: string,
* age?: int,
* is_b2b?: bool,
* }
* }&array<string, mixed>
*/
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
Expand All @@ -55,33 +50,13 @@ public function normalize(mixed $object, ?string $format = null, array $context
if ($customerEmail === null) {
throw new \InvalidArgumentException('Customer email must not be null for customer with ID "' . $customerId . '".');
}
$customerZip = null;
$customerIsB2B = false;
$customerDefaultAddress = $customer->getDefaultAddress();
if ($customerDefaultAddress instanceof AddressInterface) {
$customerZip = $customerDefaultAddress->getPostcode();
$customerIsB2B = $customerDefaultAddress->getCompany() !== null;
}
$customerGender = $customer->isMale() ? 'male' : ($customer->isFemale() ? 'female' : null);
$customerBirthday = $customer->getBirthday();
$customerAge = $customerBirthday !== null ? (new \DateTime())->diff($customerBirthday)->y : null;

$customerData = [
'id' => $customerId,
'name' => $customerName,
'email' => $customerEmail,
'subscribed' => $customer->isSubscribedToNewsletter(),
'is_b2b' => $customerIsB2B,
];
if ($customerGender !== null) {
$customerData['gender'] = $customerGender;
}
if ($customerZip !== null) {
$customerData['zip'] = $customerZip;
}
if ($customerAge !== null) {
$customerData['age'] = $customerAge;
}

$customerNormalizerEvent = new CustomerNormalizerEvent(
$customerData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ final class CategoryNormalizerEvent
* name: string,
* url: string,
* subcategories: array<int|string>,
* image?: string,
* description?: string,
* } $categoryData
* }&array<string, mixed> $categoryData
*/
public function __construct(
private array $categoryData,
Expand All @@ -34,9 +32,7 @@ public function __construct(
* name: string,
* url: string,
* subcategories: array<int|string>,
* image?: string,
* description?: string,
* }
* }&array<string, mixed>
*/
public function getCategoryData(): array
{
Expand All @@ -49,9 +45,7 @@ public function getCategoryData(): array
* name: string,
* url: string,
* subcategories: array<int|string>,
* image?: string,
* description?: string,
* } $categoryData
* }&array<string, mixed> $categoryData
*/
public function setCategoryData(array $categoryData): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ final class CustomerNormalizerEvent
* name: string,
* email: string,
* subscribed: bool,
* zip?: string,
* gender?: string,
* age?: int,
* is_b2b?: bool,
* } $customerData
* }&array<string, mixed> $customerData
*/
public function __construct(
private array $customerData,
Expand All @@ -36,11 +32,7 @@ public function __construct(
* name: string,
* email: string,
* subscribed: bool,
* zip?: string,
* gender?: string,
* age?: int,
* is_b2b?: bool,
* }
* }&array<string, mixed>
*/
public function getCustomerData(): array
{
Expand All @@ -53,11 +45,7 @@ public function getCustomerData(): array
* name: string,
* email: string,
* subscribed: bool,
* zip?: string,
* gender?: string,
* age?: int,
* is_b2b?: bool,
* } $customerData
* }&array<string, mixed> $customerData
*/
public function setCustomerData(array $customerData): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class OrderNormalizerEvent
* email?: string,
* products: array<array-key, array{id: string|int, quantity: int, price: float}>,
* time: int,
* } $orderData
* }&array<string, mixed> $orderData
*/
public function __construct(
private array $orderData,
Expand All @@ -34,7 +34,7 @@ public function __construct(
* email?: string,
* products: array<array-key, array{id: string|int, quantity: int, price: float}>,
* time: int,
* }
* }&array<string, mixed>
*/
public function getOrderData(): array
{
Expand All @@ -48,7 +48,7 @@ public function getOrderData(): array
* email?: string,
* products: array<array-key, array{id: string|int, quantity: int, price: float}>,
* time: int,
* } $orderData
* }&array<string, mixed> $orderData
*/
public function setOrderData(array $orderData): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ final class ProductNormalizerEvent
* url: string,
* categories: array<int|string>,
* created_at: string,
* brand?: string,
* color_names?: array<string>,
* color_codes?: array<string>,
* reviews_amount?: int,
* reviews_avg?: float,
* } $productData
* }&array<string, mixed> $productData
*/
public function __construct(
private array $productData,
Expand All @@ -47,12 +42,7 @@ public function __construct(
* url: string,
* categories: array<int|string>,
* created_at: string,
* brand?: string,
* color_names?: array<string>,
* color_codes?: array<string>,
* reviews_amount?: int,
* reviews_avg?: float,
* }
* }&array<string, mixed>
*/
public function getProductData(): array
{
Expand All @@ -70,12 +60,7 @@ public function getProductData(): array
* url: string,
* categories: array<int|string>,
* created_at: string,
* brand?: string,
* color_names?: array<string>,
* color_codes?: array<string>,
* reviews_amount?: int,
* reviews_avg?: float,
* } $productData
* }&array<string, mixed> $productData
*/
public function setProductData(array $productData): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataSyncInfrastructure/Normalizer/OrderNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
* email?: string,
* products: array<array-key, array{id: string|int, quantity: int, price: float}>,
* time: int,
* }
* }&array<string, mixed>
*/
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
Expand Down
7 changes: 1 addition & 6 deletions src/DataSyncInfrastructure/Normalizer/ProductNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ public function __construct(
* url: string,
* categories: array<int|string>,
* created_at: string,
* brand?: string,
* color_names?: array<string>,
* color_codes?: array<string>,
* reviews_amount?: int,
* reviews_avg?: float,
* }
* }&array<string, mixed>
*/
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
Expand Down

0 comments on commit d35d10f

Please sign in to comment.