Skip to content

Commit

Permalink
Merge branch 'extcode:main' into feature/167/enable-detail-view-link-…
Browse files Browse the repository at this point in the history
…from-cart
  • Loading branch information
rintisch authored Jun 24, 2024
2 parents 2609a62 + ed2231f commit 5b701e6
Show file tree
Hide file tree
Showing 50 changed files with 497 additions and 1,641 deletions.
43 changes: 12 additions & 31 deletions Classes/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -32,40 +33,22 @@

class ProductController extends ActionController
{
protected ExtensionService $extensionService;

protected SessionHandler $sessionHandler;

protected Cart $cart;

protected CartUtility $cartUtility;

protected ProductRepository $productRepository;

protected CategoryRepository $categoryRepository;

protected array $searchArguments = [];

protected array $cartConfiguration = [];

public function __construct(
ExtensionService $extensionService,
SessionHandler $sessionHandler,
CartUtility $cartUtility,
ProductRepository $productRepository,
CategoryRepository $categoryRepository
) {
$this->extensionService = $extensionService;
$this->sessionHandler = $sessionHandler;
$this->cartUtility = $cartUtility;
$this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
}
protected readonly ExtensionService $extensionService,
protected readonly SessionHandler $sessionHandler,
protected readonly CartUtility $cartUtility,
protected readonly ProductRepository $productRepository,
protected readonly CategoryRepository $categoryRepository
) {}

protected function initializeAction()
{
$this->cartConfiguration = $this->configurationManager->getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK,
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
'Cart'
);

Expand Down Expand Up @@ -143,7 +126,7 @@ protected function addCategoriesToDemandObjectFromSettings(ProductDemand $demand
public function listAction(int $currentPage = 1): ResponseInterface
{
$demand = $this->createDemandObjectFromSettings($this->settings);
$demand->setActionAndClass(__METHOD__, __CLASS__);
$demand->setActionAndClass(__METHOD__, self::class);

$itemsPerPage = $this->settings['itemsPerPage'] ?? 20;

Expand Down Expand Up @@ -172,9 +155,7 @@ public function listAction(int $currentPage = 1): ResponseInterface
return $this->htmlResponse();
}

/**
* @IgnoreValidation("product")
*/
#[IgnoreValidation(['value' => 'product'])]
public function showAction(Product $product = null): ResponseInterface
{
if (!$product) {
Expand Down Expand Up @@ -226,7 +207,7 @@ public function teaserAction(): ResponseInterface

public function flexformAction(): ResponseInterface
{
$contentObj = $this->configurationManager->getContentObject();
$contentObj = $this->request->getAttribute('currentContentObject');
$contentId = $contentObj->data['uid'];

$this->view->assign('contentId', $contentId);
Expand Down Expand Up @@ -271,7 +252,7 @@ public function getProductUid(): mixed
TypoScriptService::class
);
$configuration = $typoscriptService->convertPlainArrayToTypoScriptArray($configuration);
$productUid = (int)$configurationManager->getContentObject()->cObjGetSingle($configuration['product'], $configuration['product.']);
$productUid = (int)$this->request->getAttribute('currentContentObject')->cObjGetSingle($configuration['product'], $configuration['product.']);

if ($productUid === 0) {
$configurationManager->setConfiguration([
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Dto/Product/ProductDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getTitle(): ?string
return $this->title;
}

public function setTitle(string $title)
public function setTitle(string $title): void
{
$this->title = $title;
}
Expand Down
32 changes: 11 additions & 21 deletions Classes/Domain/Model/Product/BeVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class BeVariant extends AbstractEntity
protected float $price = 0.0;

/**
* @Cascade("remove")
* @var ObjectStorage<SpecialPrice>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $specialPrices;

protected int $priceCalcMethod = 0;
Expand Down Expand Up @@ -91,16 +91,11 @@ public function getPriceCalculated(): float

$parentPrice = $this->getProduct()->getPrice();

switch ($this->priceCalcMethod) {
case 3:
$calc_price = -1 * (($price / 100) * ($parentPrice));
break;
case 5:
$calc_price = ($price / 100) * ($parentPrice);
break;
default:
$calc_price = 0;
}
$calc_price = match ($this->priceCalcMethod) {
3 => -1 * (($price / 100) * ($parentPrice)),
5 => ($price / 100) * ($parentPrice),
default => 0,
};

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cart']['changeVariantDiscount']) &&
Expand Down Expand Up @@ -142,16 +137,11 @@ public function getBestPriceCalculated($frontendUserGroupIds = []): float

$parentPrice = $this->getProduct()->getBestSpecialPrice($frontendUserGroupIds);

switch ($this->priceCalcMethod) {
case 3:
$calc_price = -1 * (($price / 100) * ($parentPrice));
break;
case 5:
$calc_price = ($price / 100) * ($parentPrice);
break;
default:
$calc_price = 0;
}
$calc_price = match ($this->priceCalcMethod) {
3 => -1 * (($price / 100) * ($parentPrice)),
5 => ($price / 100) * ($parentPrice),
default => 0,
};

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cart']['changeVariantDiscount']) &&
Expand Down
8 changes: 2 additions & 6 deletions Classes/Domain/Model/Product/FeVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

class FeVariant extends AbstractEntity
{
/**
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected string $sku = '';

/**
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected string $title = '';

protected string $description = '';
Expand Down
14 changes: 7 additions & 7 deletions Classes/Domain/Model/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Product extends AbstractProduct
protected string $productType = 'simple';

/**
* @Lazy
* @var ObjectStorage<TtContent>
*/
#[Lazy]
protected ?ObjectStorage $productContent = null;

protected int $minNumberInOrder = 0;
Expand All @@ -46,35 +46,35 @@ class Product extends AbstractProduct
protected float $price = 0.0;

/**
* @Cascade("remove")
* @var ObjectStorage<SpecialPrice>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $specialPrices;

/**
* @Cascade("remove")
* @var ObjectStorage<QuantityDiscount>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $quantityDiscounts;

protected int $taxClassId = 1;

/**
* @Cascade("remove")
* @var ObjectStorage<FeVariant>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $feVariants;

/**
* @Lazy
* @var ObjectStorage<Product>
*/
#[Lazy]
protected ?ObjectStorage $relatedProducts = null;

/**
* @Lazy
* @var ObjectStorage<Product>
*/
#[Lazy]
protected ?ObjectStorage $relatedProductsFrom = null;

protected int $stock = 0;
Expand Down Expand Up @@ -132,7 +132,7 @@ public function getMaxNumberInOrder(): int
return $this->maxNumberInOrder;
}

public function setMaxNumberInOrder(int $maxNumberInOrder)
public function setMaxNumberInOrder(int $maxNumberInOrder): void
{
if ($maxNumberInOrder < 0 || (($maxNumberInOrder !== 0) && ($maxNumberInOrder < $this->minNumberInOrder))) {
throw new \InvalidArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ trait ProductBackendVariantTrait
protected ?BeVariantAttribute $beVariantAttribute3 = null;

/**
* @Cascade("remove")
* @var ObjectStorage<BeVariant>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $beVariants;

public function getBeVariantAttribute1(): ?BeVariantAttribute
Expand Down
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Product/QuantityDiscount.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@

class QuantityDiscount extends AbstractEntity
{
/**
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected float $price = 0.0;

/**
* Quantity (lower bound)
*
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected int $quantity = 0;

protected ?FrontendUserGroup $frontendUserGroup = null;
Expand Down
8 changes: 2 additions & 6 deletions Classes/Domain/Model/Product/SpecialPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@

class SpecialPrice extends AbstractEntity
{
/**
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected string $title = '';

/**
* @Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected float $price = 0.0;

protected ?FrontendUserGroup $frontendUserGroup = null;
Expand Down
Loading

0 comments on commit 5b701e6

Please sign in to comment.