diff --git a/1 b/1 deleted file mode 100644 index 63a2414..0000000 --- a/1 +++ /dev/null @@ -1,6 +0,0 @@ - -version 7c -# -# Write a message for tag: -# 0.0.7b -# Lines starting with '#' will be ignored. diff --git a/Block/Product/CustomRatingSnippet.php b/Block/Product/CustomRatingSnippet.php index 7a20d27..d229834 100644 --- a/Block/Product/CustomRatingSnippet.php +++ b/Block/Product/CustomRatingSnippet.php @@ -4,17 +4,15 @@ use Magento\Framework\View\Element\Template; -class CustomRatingSnippet extends \Reviewscouk\Reviews\Block\Product\RatingSnippet +class CustomRatingSnippet extends RatingSnippet { /** - * Get the template for the block based on the admin setting - * * @return string */ public function getTemplate() { $isEnabled = $this->_scopeConfig->isSetFlag('reviewscouk_reviews_onpage/widget/category_rating_snippet_widget_enabled'); - + if ($isEnabled) { return 'Reviewscouk_Reviews::category/list.phtml'; } diff --git a/Block/Product/RatingSnippet.php b/Block/Product/RatingSnippet.php index c6227aa..eea1433 100644 --- a/Block/Product/RatingSnippet.php +++ b/Block/Product/RatingSnippet.php @@ -2,51 +2,41 @@ namespace Reviewscouk\Reviews\Block\Product; +use Magento\Catalog\Api\CategoryRepositoryInterface; +use Magento\Catalog\Block\Product\Context; use Magento\Catalog\Block\Product\ListProduct; -use Framework\Registry as Registry; -use Magento\Framework\Escaper as Escaper; -// use Reviewscouk\Reviews\Helper\Config as ReviewsConfig; -use Magento\Framework as Framework; +use Magento\Catalog\Model\CategoryFactory; +use Magento\Catalog\Model\Layer\Resolver; +use Magento\Customer\Model\Session; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Helper\PostHelper; +use Magento\Framework\Escaper; +use Magento\Framework\Url\Helper\Data; use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\App\Helper\Context as ContextHelper; -use \Reviewscouk\Reviews\Helper\Config as ReviewsConfig; - +use Reviewscouk\Reviews\Helper\Config as ReviewsConfig; class RatingSnippet extends ListProduct { protected $_customerSession; protected $categoryFactory; - //protected $reviewsConfig = Reviews\Helper\Config; - // protected $_storeManager = StoreManagerInterface::class; protected $store; protected $reviewsConfig; - /** - * ListProduct constructor. - * @param \Magento\Catalog\Block\Product\Context $context - * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper - * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver - * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository - * @param \Magento\Framework\Url\Helper\Data $urlHelper - * @param Helper $helper - * @param array $data - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory - */ + public function __construct( - \Magento\Catalog\Block\Product\Context $context, - \Magento\Framework\Data\Helper\PostHelper $postDataHelper, - \Magento\Catalog\Model\Layer\Resolver $layerResolver, - \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, - \Magento\Framework\Url\Helper\Data $urlHelper, + Context $context, + PostHelper $postDataHelper, + Resolver $layerResolver, + CategoryRepositoryInterface $categoryRepository, + Data $urlHelper, array $data = [], - \Magento\Customer\Model\Session $customerSession = null, - \Magento\Catalog\Model\CategoryFactory $categoryFactory = null, + Session $customerSession = null, + CategoryFactory $categoryFactory = null, ReviewsConfig $reviewsConfigHelper = null, StoreManagerInterface $storeManager = null ) { $this->_customerSession = $customerSession; $this->categoryFactory = $categoryFactory; - $this->reviewsConfig = $reviewsConfigHelper ?: \Magento\Framework\App\ObjectManager::getInstance()->get(ReviewsConfig::class); + $this->reviewsConfig = $reviewsConfigHelper ?: ObjectManager::getInstance()->get(ReviewsConfig::class); $this->store = $storeManager; parent::__construct( @@ -63,22 +53,24 @@ public function __construct( private function getProductSkus($product) { $sku = $product->getSku(); - $type = $product->getTypeID(); + $type = (string) $product->getTypeID(); $productSkus = [$sku]; - if ($type == 'configurable') { + + if ($type === 'configurable') { $usedProducts = $product->getTypeInstance()->getUsedProducts($product); foreach ($usedProducts as $usedProduct) { $productSkus[] = $usedProduct->getSku(); } } - if ($type == 'grouped') { + if ($type === 'grouped') { $usedProducts = $product->getTypeInstance()->getAssociatedProducts($product); foreach ($usedProducts as $usedProduct) { $productSkus[] = $usedProduct->getSku(); } } + return $productSkus; } @@ -88,9 +80,11 @@ public function getRatingSnippet($product) $ratingSnippetEnabled = $this->reviewsConfig->isCategoryRatingSnippetWidgetEnabled($this->store); $skus = $this->getProductSkus($product); $html = ''; - if($ratingSnippetEnabled) { + + if ($ratingSnippetEnabled) { $html = '
'; } + return $html; } diff --git a/Block/Product/Reviewwidget.php b/Block/Product/Reviewwidget.php index f7984b6..e2a022c 100755 --- a/Block/Product/Reviewwidget.php +++ b/Block/Product/Reviewwidget.php @@ -2,12 +2,11 @@ namespace Reviewscouk\Reviews\Block\Product; -use Reviewscouk\Reviews as Reviews; -use Magento\Framework as Framework; +use Reviewscouk\Reviews; +use Magento\Framework; class Reviewwidget extends Framework\View\Element\Template { - private $configHelper; private $dataHelper; private $registry; @@ -126,7 +125,7 @@ protected function getWidgetColor() { $colour = $this->configHelper->getProductWidgetColour($this->store->getId()); // people will sometimes put hash and sometimes they will forgot so we need to check for this error - if (isset($colour) && strpos($colour, '#') === false) { + if (isset($colour) && !str_contains($colour, '#')) { $colour = '#' . $colour; } // checking to see if we hare a valid colour. If not then we change it to reviews default hex colour @@ -140,9 +139,11 @@ protected function getWidgetURL() { $region = $this->configHelper->getRegion($this->store->getId()); $api_url = 'widget.reviews.co.uk'; + if ($region == 'US') { $api_url = 'widget.reviews.io'; } + return $api_url; } } diff --git a/Block/Richsnippet.php b/Block/Richsnippet.php index 2097f2f..22ba158 100755 --- a/Block/Richsnippet.php +++ b/Block/Richsnippet.php @@ -2,10 +2,10 @@ namespace Reviewscouk\Reviews\Block; -use Magento\Backend as Backend; -use Magento\Directory as Directory; -use Magento\Framework as Framework; -use Reviewscouk\Reviews as Reviews; +use Magento\Backend; +use Magento\Directory; +use Magento\Framework; +use Reviewscouk\Reviews; class Richsnippet extends Framework\View\Element\Template { @@ -21,8 +21,6 @@ public function __construct( Reviews\Helper\Data $dataHelper, Framework\View\Element\Template\Context $context, Framework\Registry $registry, - Backend\Block\Template\Context $backend, - Directory\Model\Currency $currency, array $data = [] @@ -30,9 +28,9 @@ public function __construct( parent::__construct($context, $data); $this->configHelper = $config; - $this->dataHelper = $dataHelper; - $this->registry = $registry; - $this->currency = $currency; + $this->dataHelper = $dataHelper; + $this->registry = $registry; + $this->currency = $currency; $this->store = $this->_storeManager->getStore(); } @@ -40,7 +38,7 @@ public function __construct( public function autoRichSnippet() { $merchant_enabled = $this->configHelper->isMerchantRichSnippetsEnabled($this->store->getId()); - $product_enabled = $this->configHelper->isProductRichSnippetsEnabled($this->store->getId()); + $product_enabled = $this->configHelper->isProductRichSnippetsEnabled($this->store->getId()); $current_product = $this->registry->registry('current_product'); @@ -56,19 +54,20 @@ public function autoRichSnippet() } $product = [ - 'availability' => $productAvailability, - 'price' => $current_product->getFinalPrice(), - 'url' => $current_product->getProductUrl(), - 'description' => $current_product->getMetaDescription(), + 'availability' => $productAvailability, + 'price' => $current_product->getFinalPrice(), + 'url' => $current_product->getProductUrl(), + 'description' => $current_product->getMetaDescription(), 'mpn' => ($current_product->hasData('mpn') ? $current_product->getData('mpn') : $current_product->getSku()), 'priceCurrency' => $this->store->getDefaultCurrencyCode(), 'brand' => ($current_product->hasData('manufacturer') ? $current_product->getAttributeText('manufacturer') : ($current_product->hasData('brand') ? $current_product->getAttributeText('brand') : 'Not Available')), ]; return $this->getRichSnippet($sku, $product); - } else if ($merchant_enabled) { + } elseif ($merchant_enabled) { return $this->getRichSnippet(); } + return ''; } @@ -78,9 +77,9 @@ public function getRichSnippet($sku = null, $product = null) $sku = implode(';', $sku); } - $region = $this->configHelper->getRegion($this->store->getId()); + $region = $this->configHelper->getRegion($this->store->getId()); $storeName = $this->configHelper->getStoreId($this->store->getId()); - $url = $region == 'us' ? 'https://widget.reviews.io/rich-snippet/dist.js' : 'https://widget.reviews.co.uk/rich-snippet/dist.js'; + $url = $region == 'us' ? 'https://widget.reviews.io/rich-snippet/dist.js' : 'https://widget.reviews.co.uk/rich-snippet/dist.js'; $output = ''; $output .= ' + +use Magento\Framework\Escaper; +use Reviewscouk\Reviews\Block\Product\Reviewwidget; + +/** + * @var $block Reviewwidget + * @var $escaper Escaper + */ + +if (!isset($escaper)) { + $escaper = $block; +} + +if (!($block->isProductWidgetEnabled() && $block->isTabMode())): + print $block->getStaticWidget(); +else: + $_data = $block->getSettings(); + $_skus = $block->getProductSkus(); + + if ($block->isIframeWidget()): + ?> + +
+ - isPolarisWidget()) { - - $_data = $block->getSettings(); - $_skus = $block->getProductSkus(); - ?> + isPolarisWidget()): ?>
- + + - - -getStaticWidget(); - } -} -?> \ No newline at end of file + +