Skip to content

Commit

Permalink
Merge pull request #743 from Nosto/release/5.3.0
Browse files Browse the repository at this point in the history
Release 5.3.0
  • Loading branch information
olsi-qose authored Sep 23, 2021
2 parents 5f3e6ad + 998845f commit caec7f0
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

### 5.3.0
* Index products to Nosto after bulk updates

### 5.2.10
* Improve message text for mixed nosto accounts
* Remove old changelog tables when upgrading to v5
Expand Down
129 changes: 129 additions & 0 deletions Observer/Product/MassProductAttributeUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
/**
* Copyright (c) 2020, Nosto Solutions Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Nosto Solutions Ltd <[email protected]>
* @copyright 2020 Nosto Solutions Ltd
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
*
*/

namespace Nosto\Tagging\Observer\Product;

use Exception;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Store\Model\Store;
use Nosto\Tagging\Helper\Account as NostoHelperAccount;
use Nosto\Tagging\Logger\Logger as NostoLogger;
use Nosto\Tagging\Model\ResourceModel\Magento\Product\Collection as ProductCollection;
use Nosto\Tagging\Model\ResourceModel\Magento\Product\CollectionBuilder;
use Nosto\Tagging\Model\Service\Update\QueueService;

class MassProductAttributeUpdate implements ObserverInterface
{

/** @var QueueService */
private $queueService;

/** @var CollectionBuilder */
private $productCollectionBuilder;

/** @var NostoLogger */
private $logger;

/** @var NostoHelperAccount */
private $nostoHelperAccount;

/**
* MassProductAttributeUpdate constructor.
* @param QueueService $queueService
* @param CollectionBuilder $productCollectionBuilder
* @param NostoHelperAccount $nostoHelperAccount
* @param NostoLogger $logger
*/
public function __construct(
QueueService $queueService,
CollectionBuilder $productCollectionBuilder,
NostoHelperAccount $nostoHelperAccount,
NostoLogger $logger
) {
$this->queueService = $queueService;
$this->productCollectionBuilder = $productCollectionBuilder;
$this->nostoHelperAccount = $nostoHelperAccount;
$this->logger = $logger;
}

/**
* @param Observer $observer
*/
public function execute(Observer $observer)
{
$ids = $observer->getData('product_ids');

if (!is_array($ids)) {
$this->logger->debug("Could not add mass updated products to nosto indexer");
return;
}

$stores = $this->nostoHelperAccount->getStoresWithNosto();
foreach ($stores as $store) {
$this->indexProductsPerStore($store, $ids);
}
}

/**
* @param Store $store
* @param array $ids
*/
private function indexProductsPerStore(Store $store, array $ids)
{
$collection = $this->getCollection($store, $ids);
try {
$this->queueService->addCollectionToUpsertQueue(
$collection,
$store
);
} catch (Exception $e) {
$this->logger->exception($e);
}
}

/**
* @param Store $store
* @param array $ids
* @return ProductCollection
*/
private function getCollection(Store $store, array $ids): ProductCollection
{
return $this->productCollectionBuilder->initDefault($store)
->withIds($ids)
->build();
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nosto/module-nostotagging",
"description": "Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.",
"type": "magento2-module",
"version": "5.2.10",
"version": "5.3.0",
"require-dev": {
"phpmd/phpmd": "^2.5",
"sebastian/phpcpd": "*",
Expand Down
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<event name="review_delete_after">
<observer name="nosto_review_delete_after" instance="Nosto\Tagging\Observer\Product\Review"/>
</event>
<event name="catalog_product_attribute_update_before">
<observer name="nosto_catalog_product_attribute_update_before" instance="Nosto\Tagging\Observer\Product\MassProductAttributeUpdate"/>
</event>
<event name="checkout_cart_product_add_after">
<observer name="nosto_checkout_cart_product_add_after" instance="Nosto\Tagging\Observer\Cart\Add"/>
</event>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
<!--suppress XmlUnboundNsPrefix -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Nosto_Tagging" setup_version="5.2.10"/>
<module name="Nosto_Tagging" setup_version="5.3.0"/>
</config>

0 comments on commit caec7f0

Please sign in to comment.