-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from EmicoEcommerce/beta
Merge beta into master
- Loading branch information
Showing
23 changed files
with
984 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tweakwise\Magento2Tweakwise\Block\Product\ProductList; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Block\Product\AbstractProduct; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Registry; | ||
use Tweakwise\Magento2Tweakwise\Helper\Cache; | ||
|
||
class Linked | ||
{ | ||
/** | ||
* @param Cache $cacheHelper | ||
* @param RequestInterface $request | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param Registry $registry | ||
*/ | ||
public function __construct( | ||
private readonly Cache $cacheHelper, | ||
private readonly RequestInterface $request, | ||
private readonly ProductRepositoryInterface $productRepository, | ||
private readonly Registry $registry, | ||
) { | ||
} | ||
|
||
/** | ||
* @param AbstractProduct $productBlock | ||
* @return int|null | ||
*/ | ||
public function getCacheLifetime(AbstractProduct $productBlock): ?int | ||
{ | ||
if (!$this->cacheHelper->personalMerchandisingCanBeApplied()) { | ||
return null; | ||
} | ||
|
||
$productBlock->setData('ttl', Cache::PRODUCT_LIST_TTL); | ||
$productBlock->setData('cache_lifetime', Cache::PRODUCT_LIST_TTL); | ||
return $productBlock->getData('cache_lifetime'); | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getTemplate(): ?string | ||
{ | ||
if (!$this->cacheHelper->personalMerchandisingCanBeApplied()) { | ||
return null; | ||
} | ||
|
||
return 'Tweakwise_Magento2Tweakwise::product/list/items.phtml'; | ||
} | ||
|
||
/** | ||
* @param AbstractProduct $productBlock | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function prepareData(AbstractProduct $productBlock): void | ||
{ | ||
if ($this->cacheHelper->isEsiRequest($this->request) && !$productBlock->getProduct()) { | ||
$productId = $this->request->getParam('product_id'); | ||
$product = $this->productRepository->getById($productId); | ||
$this->registry->register('product', $product); | ||
$productBlock->setData('product', $product); | ||
} | ||
} | ||
|
||
/** | ||
* @param AbstractProduct $productBlock | ||
* @param string $route | ||
* @param array $params | ||
* @return array|null | ||
*/ | ||
public function getUrl(AbstractProduct $productBlock, string $route = '', array $params = []): ?array | ||
{ | ||
if ( | ||
!$this->cacheHelper->personalMerchandisingCanBeApplied() || | ||
$route !== 'page_cache/block/esi' | ||
) { | ||
return null; | ||
} | ||
|
||
$params['_query'] = [ | ||
'product_id' => $productBlock->getProduct()->getId() | ||
]; | ||
|
||
return $params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tweakwise\Magento2Tweakwise\Block\Product\ProductList; | ||
|
||
use Magento\Catalog\Block\Product\Context; | ||
use Magento\Catalog\Block\Product\ProductList\Related as MagentoRelated; | ||
use Magento\Catalog\Model\Product\Visibility as ProductVisibility; | ||
use Magento\Checkout\Model\ResourceModel\Cart as CartResourceModel; | ||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Module\Manager; | ||
|
||
class Related extends MagentoRelated | ||
{ | ||
/** | ||
* @param Context $context | ||
* @param CartResourceModel $checkoutCart | ||
* @param ProductVisibility $catalogProductVisibility | ||
* @param CheckoutSession $checkoutSession | ||
* @param Manager $moduleManager | ||
* @param Linked $linked | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
CartResourceModel $checkoutCart, | ||
ProductVisibility $catalogProductVisibility, | ||
CheckoutSession $checkoutSession, | ||
Manager $moduleManager, | ||
private readonly Linked $linked, | ||
array $data = [] | ||
) { | ||
parent::__construct( | ||
$context, | ||
$checkoutCart, | ||
$catalogProductVisibility, | ||
$checkoutSession, | ||
$moduleManager, | ||
$data | ||
); | ||
} | ||
|
||
/** | ||
* @return int|bool|null | ||
*/ | ||
protected function getCacheLifetime() | ||
{ | ||
$linkedResult = $this->linked->getCacheLifetime($this); | ||
if ($linkedResult) { | ||
return $linkedResult; | ||
} | ||
|
||
return parent::getCacheLifetime(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTemplate() | ||
{ | ||
$linkedResult = $this->linked->getTemplate(); | ||
if ($linkedResult) { | ||
return $linkedResult; | ||
} | ||
|
||
return parent::getTemplate(); | ||
} | ||
|
||
/** | ||
* @return Related | ||
* @throws NoSuchEntityException | ||
*/ | ||
protected function _prepareData() | ||
{ | ||
$this->linked->prepareData($this); | ||
|
||
return parent::_prepareData(); | ||
} | ||
|
||
/** | ||
* @param string $route | ||
* @param array $params | ||
* @return string | ||
*/ | ||
public function getUrl($route = '', $params = []) | ||
{ | ||
$linkedResult = $this->linked->getUrl($this, $route, $params); | ||
if ($linkedResult) { | ||
$params = $linkedResult; | ||
} | ||
|
||
return parent::getUrl($route, $params); | ||
} | ||
} |
Oops, something went wrong.