Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Retail mode - catalog web price #78

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Plugin/ContextPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public function aroundDispatch(
RequestInterface $request
): mixed {

// show product offer price if shop has been selected, even in Retail mode
if ($this->settingsHelper->isDriveMode() || $this->currentStore->getRetailer()) {
if ($this->settingsHelper->isDriveMode()) {
// Set a default value to have common vary for all customers without any chosen retailer.
$retailerId = 'default';

if ($this->currentStore->getRetailer()
&& $this->currentStore->getRetailer()->getId()) {
if (
$this->currentStore->getRetailer()
&& $this->currentStore->getRetailer()->getId()
) {
$retailerId = $this->currentStore->getRetailer()->getId();
}

Expand Down
28 changes: 4 additions & 24 deletions Plugin/ProductPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Closure;
use Magento\Catalog\Model\Product;
use Smile\Retailer\Api\Data\RetailerInterface;
use Smile\RetailerOffer\Helper\Offer;
use Smile\RetailerOffer\Helper\Settings;
use Smile\StoreLocator\CustomerData\CurrentStore;
Expand All @@ -16,28 +15,13 @@
*/
class ProductPlugin
{

public function __construct(
private Offer $offerHelper,
private Settings $settingsHelper,
protected CurrentStore $currentStore
) {
}

/**
* Retrieve current retailer.
*/
private function getRetailer(): ?RetailerInterface
{
$retailer = null;
if ($this->currentStore->getRetailer() && $this->currentStore->getRetailer()->getId()) {
/** @var RetailerInterface $retailer */
$retailer = $this->currentStore->getRetailer();
}

return $retailer;
}

/**
* Return offer availability (if any) instead of the product one.
*
Expand All @@ -47,8 +31,7 @@ public function aroundIsAvailable(Product $product, Closure $proceed): bool
{
$isAvailable = $proceed();

// show product availability if shop has been selected, even in Retail mode
if ($this->settingsHelper->useStoreOffers() || $this->getRetailer()) {
if ($this->settingsHelper->useStoreOffers()) {
$isAvailable = false;
$offer = $this->offerHelper->getCurrentOffer($product);

Expand All @@ -67,8 +50,7 @@ public function aroundGetPrice(Product $product, Closure $proceed): mixed
{
$price = $proceed();

// show product offer price if shop has been selected, even in Retail mode
if ($this->settingsHelper->useStoreOffers() || $this->getRetailer()) {
if ($this->settingsHelper->useStoreOffers()) {
$offer = $this->offerHelper->getCurrentOffer($product);

if ($offer && $offer->getPrice()) {
Expand All @@ -88,8 +70,7 @@ public function aroundGetSpecialPrice(Product $product, Closure $proceed): mixed
{
$price = $proceed();

// show product offer price if shop has been selected, even in Retail mode
if ($this->settingsHelper->useStoreOffers() || $this->getRetailer()) {
if ($this->settingsHelper->useStoreOffers()) {
$offer = $this->offerHelper->getCurrentOffer($product);

if ($offer && $offer->getSpecialPrice()) {
Expand All @@ -107,8 +88,7 @@ public function aroundGetFinalPrice(Product $product, Closure $proceed, mixed $q
{
$price = $proceed($qty);

// show product offer price if shop has been selected, even in Retail mode
if ($this->settingsHelper->useStoreOffers() || $this->getRetailer()) {
if ($this->settingsHelper->useStoreOffers()) {
$offer = $this->offerHelper->getCurrentOffer($product);

if ($offer) {
Expand Down
Loading