Skip to content

Commit

Permalink
[project-base] fix company complaints if you change domains setting (…
Browse files Browse the repository at this point in the history
…#3563)
  • Loading branch information
henzigo authored Nov 4, 2024
1 parent e0ebe71 commit 2e1a0b4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
64 changes: 40 additions & 24 deletions app/src/DataFixtures/Demo/CompanyComplaintDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Shopsys\FrameworkBundle\Component\DataFixture\AbstractReferenceFixture;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Complaint\Complaint;
use Shopsys\FrameworkBundle\Model\Complaint\Status\ComplaintStatus;

class CompanyComplaintDataFixture extends AbstractReferenceFixture implements DependentFixtureInterface
{
public const string COMPLAINT_PREFIX = 'complaint_';

/**
* @param \App\DataFixtures\Demo\Helper\ComplaintHelper $complaintHelper
*/
Expand All @@ -30,33 +28,51 @@ public function __construct(
*/
public function load(ObjectManager $manager): void
{
$customerUserNovotny = $this->getReferenceForDomain(CompanyDataFixture::B2B_COMPANY_OWNER_EMAIL, Domain::SECOND_DOMAIN_ID, CustomerUser::class);
$customerUserKovac = $this->getReferenceForDomain(CompanyDataFixture::B2B_COMPANY_LIMITED_USER_EMAIL, Domain::SECOND_DOMAIN_ID, CustomerUser::class);
foreach ($this->domainsForDataFixtureProvider->getAllowedDemoDataDomains() as $domainConfig) {
if (!$domainConfig->isB2b()) {
continue;
}

$uploadedFile1 = $this->complaintHelper->createUploadedFile(__DIR__ . '/../resources/images/complaint/404.jpg');
$uploadedFile2 = $this->complaintHelper->createUploadedFile(__DIR__ . '/../resources/images/complaint/405.jpg');
$domainId = $domainConfig->getId();
$this->importCompanyComplaints($domainId);
}
}

$order27 = $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 27, Order::class);
$orderItems1 = $order27->getProductItems();
$complaintItem1 = $this->complaintHelper->createComplaintItemData(array_shift($orderItems1), 'Broken!', 1, [$uploadedFile2]);
$complaint1 = $this->complaintHelper->createComplaint(
$customerUserNovotny,
$order27,
$this->getReference(ComplaintStatusDataFixture::COMPLAINT_STATUS_NEW, ComplaintStatus::class),
[$complaintItem1],
/**
* @param int $domainId
*/
private function importCompanyComplaints(int $domainId): void
{
$this->createComplaint(
$this->getReference(CompanyOrderDataFixture::COMPANY_ORDER_1, Order::class),
$this->getReferenceForDomain(CompanyDataFixture::B2B_COMPANY_OWNER_EMAIL, $domainId, CustomerUser::class),
[$this->complaintHelper->createUploadedFile(__DIR__ . '/../resources/images/complaint/404.jpg')],
);
$this->addReference(self::COMPLAINT_PREFIX . 3, $complaint1);

$order28 = $this->getReference(CompanyOrderDataFixture::ORDER_PREFIX . 28, Order::class);
$orderItems1 = $order28->getProductItems();
$complaintItem1 = $this->complaintHelper->createComplaintItemData(array_shift($orderItems1), 'Broken!', 1, [$uploadedFile1]);
$complaint2 = $this->complaintHelper->createComplaint(
$customerUserKovac,
$order28,
$this->createComplaint(
$this->getReference(CompanyOrderDataFixture::COMPANY_ORDER_2, Order::class),
$this->getReferenceForDomain(CompanyDataFixture::B2B_COMPANY_LIMITED_USER_EMAIL, $domainId, CustomerUser::class),
[$this->complaintHelper->createUploadedFile(__DIR__ . '/../resources/images/complaint/405.jpg')],
);
}

/**
* @param \App\Model\Order\Order $order
* @param \App\Model\Customer\User\CustomerUser $customer
* @param \Symfony\Component\HttpFoundation\File\UploadedFile[] $uploadedFiles
* @return \Shopsys\FrameworkBundle\Model\Complaint\Complaint
*/
private function createComplaint(Order $order, CustomerUser $customer, array $uploadedFiles): Complaint
{
$orderItems = $order->getProductItems();
$complaintItem = $this->complaintHelper->createComplaintItemData(array_shift($orderItems), 'Broken!', 1, $uploadedFiles);

return $this->complaintHelper->createComplaint(
$customer,
$order,
$this->getReference(ComplaintStatusDataFixture::COMPLAINT_STATUS_NEW, ComplaintStatus::class),
[$complaintItem1],
[$complaintItem],
);
$this->addReference(self::COMPLAINT_PREFIX . 4, $complaint2);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions app/src/DataFixtures/Demo/CompanyOrderDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CompanyOrderDataFixture extends AbstractReferenceFixture implements Depend
{
private const string UUID_NAMESPACE = '0338e624-c961-4475-a29d-c90080d02d1f';
public const string ORDER_PREFIX = 'order_';
public const string COMPANY_ORDER_1 = 'company_order_1';
public const string COMPANY_ORDER_2 = 'company_order_2';

/**
* @param \App\Model\Order\PlaceOrderFacade $placeOrderFacade
Expand Down Expand Up @@ -120,7 +122,7 @@ private function loadOrders(int $domainId): void
$orderData->domainId = $domainId;
$orderData->currency = $domainDefaultCurrency;
$orderData->createdAt = (new DateTime('now -3 day'))->setTime(18, 27, 36);
$this->createOrder(
$order = $this->createOrder(
$orderData,
[
ProductDataFixture::PRODUCT_PREFIX . '4' => 6,
Expand All @@ -131,6 +133,8 @@ private function loadOrders(int $domainId): void
$customerUser,
);

$this->addReference(self::COMPANY_ORDER_1, $order);

$orderData = $this->orderDataFactory->create();
$orderData->status = $this->getReference(OrderStatusDataFixture::ORDER_STATUS_NEW, OrderStatus::class);
$this->mapCustomerUserDataToOrderData($orderData, $customerUser);
Expand All @@ -139,7 +143,7 @@ private function loadOrders(int $domainId): void
$orderData->domainId = $domainId;
$orderData->currency = $domainDefaultCurrency;
$orderData->createdAt = (new DateTime('now -1 day'))->setTime(18, 30, 01);
$this->createOrder(
$order = $this->createOrder(
$orderData,
[
ProductDataFixture::PRODUCT_PREFIX . '1' => 1,
Expand All @@ -149,6 +153,8 @@ private function loadOrders(int $domainId): void
$customerUser,
);

$this->addReference(self::COMPANY_ORDER_2, $order);

$orderData = $this->orderDataFactory->create();
$orderData->status = $this->getReference(OrderStatusDataFixture::ORDER_STATUS_NEW, OrderStatus::class);
$this->mapCustomerUserDataToOrderData($orderData, $customerUser);
Expand Down

0 comments on commit 2e1a0b4

Please sign in to comment.