Skip to content

Commit

Permalink
Merge pull request #831 from Nosto/release/7.3.0
Browse files Browse the repository at this point in the history
Release/7.3.0
  • Loading branch information
supercid authored Aug 29, 2023
2 parents 2633781 + 646f4f3 commit 9ccc3c0
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 49 deletions.
10 changes: 4 additions & 6 deletions Block/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Nosto\Model\Category as NostoCategory;
use Nosto\Model\Category\Category as NostoCategory;
use Nosto\Tagging\Helper\Account as NostoHelperAccount;
use Nosto\Tagging\Helper\Scope as NostoHelperScope;
use Nosto\Tagging\Model\Category\Builder as NostoCategoryBuilder;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function __construct(
/**
* Returns the current category as a slash delimited string
*
* @return string|null the current category as a slash delimited string
* @return NostoCategory|null the current category as a slash delimited string
*/
private function getNostoCategory()
{
Expand All @@ -120,12 +120,10 @@ private function getNostoCategory()
/**
* Returns the HTML to render categories
*
* @return NostoCategory
* @return NostoCategory|null
*/
public function getAbstractObject()
{
$category = new NostoCategory();
$category->setCategoryString($this->getNostoCategory());
return $category;
return $this->getNostoCategory();
}
}
13 changes: 0 additions & 13 deletions Block/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,6 @@ public function getAbstractObject()
);
}

/**
* Returns the Nosto category DTO.
*
* @return string|null the current category as a slash-delimited string
*/
public function getNostoCategory()
{
/** @phan-suppress-next-line PhanDeprecatedFunction */
$category = $this->_coreRegistry->registry('current_category');
$store = $this->nostoHelperScope->getStore();
return $category !== null ? $this->categoryBuilder->build($category, $store) : null;
}

/**
* Formats a price e.g. "1234.56".
*
Expand Down
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.

### 7.3.0
* Update tagging with category listing support
* Add category export
### 7.2.6
* Convert price in cart tagging item to avoid rounding errors

Expand Down
99 changes: 99 additions & 0 deletions Controller/Export/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Copyright (c) 2023, 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\Controller\Export;

use Magento\Framework\App\Action\Context;
use Magento\Store\Model\Store;
use Nosto\Model\AbstractCollection;
use Nosto\Model\Category\CategoryCollection;
use Nosto\NostoException;
use Nosto\Tagging\Helper\Account as NostoHelperAccount;
use Nosto\Tagging\Helper\Scope as NostoHelperScope;
use Nosto\Tagging\Model\Category\CollectionBuilder;

/**
* Category export controller used to export category tree to Nosto.
* This controller will be called by Nosto when a new account has been created
* from the Magento backend. The controller is public, but the information is
* encrypted with AES, and only Nosto can decrypt it.
*/
class Category extends Base
{
public const PARAM_PREVIEW = 'preview';

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

/**
* @param Context $context
* @param NostoHelperScope $nostoHelperScope
* @param NostoHelperAccount $nostoHelperAccount
* @param CollectionBuilder $collectionBuilder
*/
public function __construct(
Context $context,
NostoHelperScope $nostoHelperScope,
NostoHelperAccount $nostoHelperAccount,
CollectionBuilder $collectionBuilder
) {
parent::__construct($context, $nostoHelperScope, $nostoHelperAccount);
$this->nostoCollectionBuilder = $collectionBuilder;
}

/**
* @param Store $store
* @param int $limit
* @param int $offset
* @return AbstractCollection|CategoryCollection
* @throws NostoException
*/
public function buildExportCollection(Store $store, int $limit = 100, int $offset = 0)
{
return $this->nostoCollectionBuilder->buildMany($store, $limit, $offset);
}

/**
* @param Store $store
* @param $id
* @return AbstractCollection|CategoryCollection
* @throws NostoException
*/
public function buildSingleExportCollection(Store $store, $id)
{
return $this->nostoCollectionBuilder->buildSingle($store, $id);
}
}
50 changes: 31 additions & 19 deletions Model/Category/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,46 @@
namespace Nosto\Tagging\Model\Category;

use Exception;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\Store;
use Nosto\Model\Category as NostoCategory;
use Nosto\Model\Category\Category as NostoCategory;
use Nosto\Tagging\Logger\Logger as NostoLogger;
use Nosto\Tagging\Model\Service\Product\Category\CategoryServiceInterface as NostoCategoryService;

class Builder
{
private NostoLogger $logger;
/** @var CategoryRepositoryInterface */
private CategoryRepositoryInterface $categoryRepository;

/** @var ManagerInterface */
private ManagerInterface $eventManager;

/** @var NostoCategoryService */
private NostoCategoryService $nostoCategoryService;

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

/**
* Builder constructor.
* @param NostoLogger $logger
* @param CategoryRepositoryInterface $categoryRepository
* @param ManagerInterface $eventManager
* @param NostoCategoryService $nostoCategoryService
* @param NostoLogger $logger
*/
public function __construct(
NostoLogger $logger,
CategoryRepositoryInterface $categoryRepository,
ManagerInterface $eventManager,
NostoCategoryService $nostoCategoryService
NostoCategoryService $nostoCategoryService,
NostoLogger $logger
) {
$this->logger = $logger;
$this->categoryRepository = $categoryRepository;
$this->eventManager = $eventManager;
$this->nostoCategoryService = $nostoCategoryService;
$this->logger = $logger;
}

/**
Expand All @@ -77,18 +90,16 @@ public function build(Category $category, Store $store)
try {
$nostoCategory->setId($category->getId());
$nostoCategory->setParentId($category->getParentId());
$nostoCategory->setImageUrl($category->getImageUrl());
$nostoCategory->setLevel($category->getLevel());
$nostoCategory->setTitle($this->getCategoryNameById($category->getId(), $store->getId()));
$path = $this->nostoCategoryService->getCategory($category, $store);
$nostoCategory->setPath($path);
$nostoCategory->setCategoryString($path);
$nostoCategory->setUrl($category->getUrl());
$nostoCategory->setVisibleInMenu($this->getCategoryVisibleInMenu($category));
$nostoCategory->setCategoryString(
$this->nostoCategoryService->getCategory($category, $store)
);
$nostoCategory->setName($category->getName());
$nostoCategory->setAvailable($category->getIsActive() ?? false);
} catch (Exception $e) {
$this->logger->exception($e);
}
if (empty($nostoCategory)) {
if (empty($nostoCategory->getId())) {
$nostoCategory = null;
} else {
$this->eventManager->dispatch(
Expand All @@ -101,12 +112,13 @@ public function build(Category $category, Store $store)
}

/**
* @param Category $category
* @return bool
* @param int $id
* @param int $storeId
* @return string
* @throws NoSuchEntityException
*/
private function getCategoryVisibleInMenu(Category $category)
private function getCategoryNameById(int $id, int $storeId)
{
$visibleInMenu = $category->getIncludeInMenu();
return $visibleInMenu === "1";
return $this->categoryRepository->get($id, $storeId)->getName();
}
}
Loading

0 comments on commit 9ccc3c0

Please sign in to comment.