Skip to content

Commit

Permalink
[shopsys] added product inquiries (#3465)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Nov 6, 2024
2 parents 48beb86 + e20c0e2 commit f6bebbc
Show file tree
Hide file tree
Showing 51 changed files with 1,991 additions and 45 deletions.
9 changes: 9 additions & 0 deletions src/Component/Image/ImageFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ function () use ($image, $domainConfig) {
. $this->imageLocator->getRelativeImageFilepathWithSlug($image, $friendlyUrlSeoEntityName);
}

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig $domainConfig
* @return string
*/
public function getEmptyImageUrl(DomainConfig $domainConfig): string
{
return $this->cdnFacade->resolveDomainUrlForAssets($domainConfig) . '/public/frontend/images/noimage.png';
}

/**
* @param object $imageOrEntity
* @param string|null $type
Expand Down
158 changes: 158 additions & 0 deletions src/Component/Money/HiddenMoney.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Component\Money;

class HiddenMoney extends Money
{
public const string HIDDEN_FORMAT = '***';

public function __construct()
{
}

/**
* {@inheritdoc}
*/
public static function create($value): Money
{
return new self();
}

/**
* {@inheritdoc}
*/
public static function createFromFloat(float $float, int $scale): Money
{
return new self();
}

/**
* {@inheritdoc}
*/
public static function zero(): Money
{
return new self();
}

/**
* {@inheritdoc}
*/
public function getAmount(): string
{
return self::HIDDEN_FORMAT;
}

/**
* {@inheritdoc}
*/
public function add(Money $money): Money
{
return $this;
}

/**
* {@inheritdoc}
*/
public function subtract(Money $money): Money
{
return $this;
}

/**
* {@inheritdoc}
*/
public function multiply($multiplier): Money
{
return $this;
}

/**
* {@inheritdoc}
*/
public function divide($divisor, int $scale): Money
{
return $this;
}

/**
* {@inheritdoc}
*/
public function round(int $scale): Money
{
return $this;
}

/**
* {@inheritdoc}
*/
public function equals(Money $money): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function compare(Money $money): int
{
return -1;
}

/**
* {@inheritdoc}
*/
public function isGreaterThan(Money $money): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isGreaterThanOrEqualTo(Money $money): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isLessThan(Money $money): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isLessThanOrEqualTo(Money $money): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isNegative(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isPositive(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isZero(): bool
{
return false;
}
}
78 changes: 78 additions & 0 deletions src/Controller/Admin/InquiryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Controller\Admin;

use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade;
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormData;
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormType;
use Shopsys\FrameworkBundle\Model\Inquiry\InquiryFacade;
use Shopsys\FrameworkBundle\Model\Inquiry\InquiryGridFactory;
use Shopsys\FrameworkBundle\Model\Localization\Localization;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class InquiryController extends AdminBaseController
{
/**
* @param \Shopsys\FrameworkBundle\Model\Inquiry\InquiryGridFactory $inquiryGridFactory
* @param \Shopsys\FrameworkBundle\Model\Inquiry\InquiryFacade $inquiryFacade
* @param \Shopsys\FrameworkBundle\Model\Localization\Localization $localization
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade
*/
public function __construct(
protected readonly InquiryGridFactory $inquiryGridFactory,
protected readonly InquiryFacade $inquiryFacade,
protected readonly Localization $localization,
protected readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade,
) {
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
#[Route(path: '/inquiry/list/')]
public function listAction(Request $request): Response
{
$domainFilterNamespace = 'inquiries';

$quickSearchForm = $this->createForm(QuickSearchFormType::class, new QuickSearchFormData());
$quickSearchForm->handleRequest($request);

$queryBuilder = $this->inquiryFacade->getInquiryListQueryBuilderByQuickSearchData(
$quickSearchForm->getData(),
$this->localization->getAdminLocale(),
);

$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace);

if ($selectedDomainId !== null) {
$queryBuilder
->andWhere('i.domainId = :selectedDomainId')
->setParameter('selectedDomainId', $selectedDomainId);
}

return $this->render('@ShopsysFramework/Admin/Content/Inquiry/list.html.twig', [
'gridView' => $this->inquiryGridFactory->createView($queryBuilder, $this->getCurrentAdministrator()),
'domainFilterNamespace' => $domainFilterNamespace,
'quickSearchForm' => $quickSearchForm->createView(),
]);
}

/**
* @param int $id
* @return \Symfony\Component\HttpFoundation\Response
*/
#[Route(path: '/inquiry/detail/{id}', requirements: ['id' => '\d+'])]
public function detailAction(int $id): Response
{
$inquiry = $this->inquiryFacade->getById($id);

return $this->render('@ShopsysFramework/Admin/Content/Inquiry/detail.html.twig', [
'inquiry' => $inquiry,
]);
}
}
13 changes: 12 additions & 1 deletion src/Form/Admin/Product/ProductFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Shopsys\FrameworkBundle\Model\Product\Product;
use Shopsys\FrameworkBundle\Model\Product\ProductData;
use Shopsys\FrameworkBundle\Model\Product\ProductFacade;
use Shopsys\FrameworkBundle\Model\Product\ProductTypeEnum;
use Shopsys\FrameworkBundle\Model\Product\Unit\UnitFacade;
use Shopsys\FrameworkBundle\Model\Seo\SeoSettingFacade;
use Shopsys\FrameworkBundle\Model\Transport\TransportFacade;
Expand Down Expand Up @@ -69,6 +70,7 @@ class ProductFormType extends AbstractType
* @param \Shopsys\FrameworkBundle\Model\Product\ProductFacade $productFacade
* @param \Shopsys\FrameworkBundle\Model\Transport\TransportFacade $transportFacade
* @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator
* @param \Shopsys\FrameworkBundle\Model\Product\ProductTypeEnum $productTypeEnum
*/
public function __construct(
private readonly BrandFacade $brandFacade,
Expand All @@ -83,6 +85,7 @@ public function __construct(
private readonly ProductFacade $productFacade,
private readonly TransportFacade $transportFacade,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly ProductTypeEnum $productTypeEnum,
) {
}

Expand Down Expand Up @@ -167,6 +170,14 @@ private function createBasicInformationGroup(
'label' => t('Basic information'),
]);

if (!$this->isProductMainVariant($product)) {
$builderBasicInformationGroup->add('productType', ChoiceType::class, [
'required' => true,
'choices' => $this->productTypeEnum->getAllIndexedByTranslations(),
'label' => t('Product type'),
]);
}

$builderBasicInformationGroup->add('catnum', TextType::class, [
'required' => true,
'constraints' => [
Expand Down Expand Up @@ -747,7 +758,7 @@ private function createParametersGroup(FormBuilderInterface $builder): FormBuild
'error_bubbling' => false,
'render_form_row' => false,
])
->addModelTransformer($this->productParameterValueToProductParameterValuesLocalizedTransformer));
->addModelTransformer($this->productParameterValueToProductParameterValuesLocalizedTransformer));

return $builderParametersGroup;
}
Expand Down
28 changes: 28 additions & 0 deletions src/Migrations/Version20240924082209.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20240924082209 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$this->sql('ALTER TABLE products ADD product_type VARCHAR(32) DEFAULT NULL');
$this->sql('UPDATE products SET product_type = \'basic\'');
$this->sql('ALTER TABLE products ALTER product_type SET NOT NULL');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
62 changes: 62 additions & 0 deletions src/Migrations/Version20240926162253.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20240926162253 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$this->sql('
CREATE TABLE inquiries (
id SERIAL NOT NULL,
domain_id INT NOT NULL,
product_id INT DEFAULT NULL,
product_catnum VARCHAR(100) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
telephone VARCHAR(30) NOT NULL,
company_name VARCHAR(100) DEFAULT NULL,
company_number VARCHAR(50) DEFAULT NULL,
company_tax_number VARCHAR(50) DEFAULT NULL,
note TEXT DEFAULT NULL,
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
customer_user_id INT DEFAULT NULL,
PRIMARY KEY(id)
)');
$this->sql('CREATE INDEX IDX_1CCE4D54584665A ON inquiries (product_id)');
$this->sql('
ALTER TABLE
inquiries
ADD
CONSTRAINT FK_1CCE4D54584665A FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE
SET
NULL NOT DEFERRABLE INITIALLY IMMEDIATE');

$this->sql('COMMENT ON COLUMN inquiries.created_at IS \'(DC2Type:datetime_immutable)\'');

$this->sql('
ALTER TABLE
inquiries
ADD
CONSTRAINT FK_1CCE4D5BBB3772B FOREIGN KEY (customer_user_id) REFERENCES customer_users (id) ON DELETE
SET
NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->sql('CREATE INDEX IDX_1CCE4D5BBB3772B ON inquiries (customer_user_id)');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
Loading

0 comments on commit f6bebbc

Please sign in to comment.