diff --git a/Block/Adminhtml/SeoChecker/CheckForm.php b/Block/Adminhtml/SeoChecker/CheckForm.php
index c47d6be..8c75d06 100644
--- a/Block/Adminhtml/SeoChecker/CheckForm.php
+++ b/Block/Adminhtml/SeoChecker/CheckForm.php
@@ -24,7 +24,7 @@
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ProductFactory;
-use Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder;
+use Magento\Cms\Helper\Page;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
@@ -45,7 +45,7 @@ class CheckForm extends Template
protected $_template = 'seocheck.phtml';
/**
- * @var UrlBuilder
+ * @var Page
*/
protected $cmsUrl;
@@ -88,7 +88,7 @@ class CheckForm extends Template
*/
public function __construct(
Context $context,
- UrlBuilder $cmsUrl,
+ Page $cmsUrl,
PageFactory $cmsPageFactory,
ProductFactory $productFactory,
ProductRepositoryInterface $productRepository,
@@ -115,13 +115,11 @@ public function __construct(
public function getLink()
{
$id = $this->_request->getParam('id');
- $storeCode = $this->_storeManager->getStore()->getCode();
$storeId = $this->_request->getParam('store');
$actionName = $this->_request->getFullActionName();
if ($storeId === 0 || $storeId === null) {
$defaultStore = $this->_storeManager->getDefaultStoreView();
$storeId = $defaultStore->getId();
- $storeCode = $defaultStore->getCode();
}
switch ($actionName) {
case 'catalog_product_edit':
@@ -135,11 +133,7 @@ public function getLink()
break;
case 'cms_page_edit':
$pageId = $this->_request->getParam('page_id');
- $url = $this->cmsUrl->getUrl(
- $this->cmsPageFactory->create()->load($pageId)->getIdentifier(),
- $storeId,
- $storeCode
- );
+ $url = $this->cmsUrl->getPageUrl($pageId);
break;
default:
$url = '';
diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php
index 4bb7341..d482a3a 100755
--- a/Plugin/SeoRender.php
+++ b/Plugin/SeoRender.php
@@ -28,6 +28,7 @@
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
+use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\Request\Http;
use Magento\Framework\DataObject;
use Magento\Framework\Event\Manager;
@@ -51,6 +52,9 @@
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Seo\Helper\Data as HelperData;
use Mageplaza\Seo\Model\Config\Source\PriceValidUntil;
+use Magento\InventoryApi\Api\GetSourceItemsBySkuInterface as SourceItems;
+use Magento\InventorySales\Model\ResourceModel\GetAssignedStockIdForWebsite as AssignedStock;
+use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku as SalableQuantity;
/**
* Class SeoRender
@@ -169,30 +173,48 @@ class SeoRender
*/
protected $collectionFactory;
+ /**
+ * @var SourceItems
+ */
+ protected $sourceItemsBySku;
+
+ /**
+ * @var AssignedStock
+ */
+ protected $assignedStock;
+
+ /**
+ * @var SalableQuantity
+ */
+ protected $salableQuantity;
+
/**
* SeoRender constructor.
*
- * @param PageConfig $pageConfig
- * @param Http $request
- * @param HelperData $helpData
- * @param StockItemRepository $stockItemRepository
- * @param Registry $registry
- * @param ReviewFactory $reviewFactory
- * @param StoreManagerInterface $storeManager
- * @param UrlInterface $urlBuilder
- * @param ProductFactory $productFactory
- * @param ManagerInterface $messageManager
+ * @param PageConfig $pageConfig
+ * @param Http $request
+ * @param HelperData $helpData
+ * @param StockItemRepository $stockItemRepository
+ * @param Registry $registry
+ * @param ReviewFactory $reviewFactory
+ * @param StoreManagerInterface $storeManager
+ * @param UrlInterface $urlBuilder
+ * @param ProductFactory $productFactory
+ * @param ManagerInterface $messageManager
* @param StockRegistryInterface $stockState
- * @param SearchHelper $searchHelper
- * @param PriceHelper $priceHelper
- * @param Manager $eventManager
- * @param DateTime $dateTime
- * @param TimezoneInterface $timeZoneInterface
- * @param ReviewCollection $reviewCollection
- * @param ModuleManager $moduleManager
- * @param RatingFactory $ratingFactory
- * @param ReviewResourceModel $reviewResourceModel
- * @param CollectionFactory $collectionFactory
+ * @param SearchHelper $searchHelper
+ * @param PriceHelper $priceHelper
+ * @param Manager $eventManager
+ * @param DateTime $dateTime
+ * @param TimezoneInterface $timeZoneInterface
+ * @param ReviewCollection $reviewCollection
+ * @param ModuleManager $moduleManager
+ * @param RatingFactory $ratingFactory
+ * @param ReviewResourceModel $reviewResourceModel
+ * @param CollectionFactory $collectionFactory
+ * @param SourceItems $sourceItemsBySku
+ * @param AssignedStock $assignedStock
+ * @param SalableQuantity $salableQuantity
*/
public function __construct(
PageConfig $pageConfig,
@@ -215,7 +237,10 @@ public function __construct(
ModuleManager $moduleManager,
RatingFactory $ratingFactory,
ReviewResourceModel $reviewResourceModel,
- CollectionFactory $collectionFactory
+ CollectionFactory $collectionFactory,
+ SourceItems $sourceItemsBySku,
+ AssignedStock $assignedStock,
+ SalableQuantity $salableQuantity
) {
$this->pageConfig = $pageConfig;
$this->request = $request;
@@ -238,6 +263,9 @@ public function __construct(
$this->ratingFactory = $ratingFactory;
$this->reviewResourceModel = $reviewResourceModel;
$this->collectionFactory = $collectionFactory;
+ $this->sourceItemsBySku = $sourceItemsBySku;
+ $this->assignedStock = $assignedStock;
+ $this->salableQuantity = $salableQuantity;
}
/**
@@ -346,6 +374,36 @@ public function showProductStructuredData()
$product->getId(),
$product->getStore()->getWebsiteId()
);
+
+ if ($sourceItemList = $this->sourceItemsBySku->execute($product->getSku())) {
+ $stockQty = 0;
+ $websiteCode = $this->_storeManager->getWebsite()->getCode();
+ $assignedStockId = $this->assignedStock->execute($websiteCode);
+
+ if ($product->getTypeId() === Configurable::TYPE_CODE) {
+ $typeInstance = $product->getTypeInstance();
+ $childProductCollection = $typeInstance->getUsedProducts($product);
+ foreach ($childProductCollection as $childProduct) {
+ $qty = $this->salableQuantity->execute($childProduct->getSku());
+ foreach ($qty as $value) {
+ if ($value['stock_id'] == $assignedStockId) {
+ $stockQty += isset($value['qty']) ? $value['qty'] : 0;
+ }
+ }
+ }
+ } else {
+ $qty = $this->salableQuantity->execute($product->getSku());
+ foreach ($qty as $value) {
+ if ($value['stock_id'] == $assignedStockId) {
+ $stockQty += isset($value['qty']) ? $value['qty'] : 0;
+ }
+ }
+
+ }
+
+ $stockItem = (int)$stockQty;
+ }
+
$priceValidUntil = $currentProduct->getSpecialToDate();
$modelAttribute = $this->helperData->getRichsnippetsConfig('model_value');
$modelValue = $product->getResource()
@@ -370,12 +428,12 @@ public function showProductStructuredData()
'description' => $currentProduct->getDescription() ? trim(strip_tags($currentProduct->getDescription())) : '',
'sku' => $currentProduct->getSku(),
'url' => $currentProduct->getProductUrl(),
- 'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImage(),
+ 'image' => $this->getUrl('/media/catalog') . 'product' . $currentProduct->getImage(),
'offers' => [
'@type' => 'Offer',
'priceCurrency' => $this->_storeManager->getStore()->getCurrentCurrencyCode(),
'price' => $currentProduct->getPriceInfo()->getPrice('final_price')->getValue(),
- 'itemOffered' => $stockItem->getQty(),
+ 'itemOffered' => is_integer($stockItem) ? $stockItem : $stockItem->getQty(),
'availability' => 'http://schema.org/' . $availability,
'url' => $currentProduct->getProductUrl()
],
diff --git a/Setup/Patch/Data/RemoveAttribute.php b/Setup/Patch/Data/RemoveAttribute.php
new file mode 100644
index 0000000..6db6227
--- /dev/null
+++ b/Setup/Patch/Data/RemoveAttribute.php
@@ -0,0 +1,112 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->eavSetupFactory = $eavSetupFactory;
+ }
+
+ /**
+ * Do Upgrade
+ *
+ * @return void
+ */
+ public function apply()
+ {
+ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_meta_robots');
+ $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_seo_og_description');
+ $this->removeAttribute($eavSetup, Category::ENTITY, 'mp_meta_robots');
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * @return string
+ */
+ public static function getVersion()
+ {
+ return '2.0.1';
+ }
+
+
+ /**
+ * Remove attribute
+ *
+ * @param $eavSetup
+ * @param $model
+ * @param $id
+ */
+ private function removeAttribute($eavSetup, $model, $id)
+ {
+ if ($eavSetup->getAttributeId($model, $id)) {
+ $eavSetup->removeAttribute($model, $id);
+ }
+ }
+}
diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php
deleted file mode 100644
index 56d844c..0000000
--- a/Setup/UpgradeData.php
+++ /dev/null
@@ -1,79 +0,0 @@
-eavSetupFactory = $eavSetupFactory;
- }
-
- /**
- * @param ModuleDataSetupInterface $setup
- * @param ModuleContextInterface $context
- */
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- if (version_compare($context->getVersion(), '2.0.1', '<')) {
- $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_meta_robots');
- $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_seo_og_description');
- $this->removeAttribute($eavSetup, Category::ENTITY, 'mp_meta_robots');
- }
- }
-
- /**
- * Remove attribute
- *
- * @param $eavSetup
- * @param $model
- * @param $id
- */
- public function removeAttribute($eavSetup, $model, $id)
- {
- if ($eavSetup->getAttributeId($model, $id)) {
- $eavSetup->removeAttribute($model, $id);
- }
- }
-}
diff --git a/composer.json b/composer.json
index 4cafd2c..e621759 100644
--- a/composer.json
+++ b/composer.json
@@ -2,10 +2,10 @@
"name": "mageplaza/magento-2-seo-extension",
"description": "Magento 2 SEO extension",
"require": {
- "mageplaza/module-core": "^1.4.12"
+ "mageplaza/module-core": "^1.5.0"
},
"type": "magento2-module",
- "version": "4.2.0",
+ "version": "4.2.1",
"license": "proprietary",
"keywords": [
"magento 2",