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

Release/1.17.0 #217

Merged
merged 22 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2d59c19
Use referenceBlock instead of referenceContainer
Bogardo Jan 29, 2024
98072e1
[inventory]:+ Prefetching MSI inventory, as a result it doesn't have …
julian-van-drielen Feb 7, 2024
f3411e1
Merge pull request #1 from LOAVIES/feat/item-feed-performance/inventory
julian-van-drielen Feb 7, 2024
411a28f
[master]:+ Changed package name
julian-van-drielen Feb 7, 2024
b72f158
[media]:+ Prefetching media data instead of per product fetching
julian-van-drielen Feb 8, 2024
6ff6818
[media]:+ Removed version from composer.json file
julian-van-drielen Feb 8, 2024
1af3eb1
Merge pull request #2 from LOAVIES/feat/item-feed-performance/media
julian-van-drielen Feb 8, 2024
170f400
[attribute-set]:+ Improved fetching of attribute set name
julian-van-drielen Feb 9, 2024
9621b91
Feature: save returns meta data and add to returns grid
Marvin-Magmodules Feb 26, 2024
1c65286
Feature: added option to set zero tax on business orders
Marvin-Magmodules Feb 26, 2024
c2aeddc
Added tier prices to output if selected in extra values
Marvin-Magmodules Feb 26, 2024
342e18b
Also convert shipping costs if needed
Marvin-Magmodules Feb 26, 2024
88e2b89
Add "Not Visible Individually" products to feed when forced
Marvin-Magmodules Feb 26, 2024
0e022e4
Move returns config menu option to bottom
Marvin-Magmodules Feb 26, 2024
9afe0b5
Revert "[master]:+ Changed package name"
Marvin-Magmodules Feb 26, 2024
788ddfe
Do not prefetch inventory data if option is disabled in config
Marvin-Magmodules Feb 26, 2024
b282f3c
Fix TypeError when parent relations are skipped
Marvin-Magmodules Feb 26, 2024
2b63cfe
Added category id to category output
Marvin-Magmodules Feb 26, 2024
3e8e689
Merge branch 'feature/prefetch-data' into release/1.17.0
Marvin-Magmodules Feb 26, 2024
114067b
Version bump
Marvin-Magmodules Feb 26, 2024
db211a2
Merge branch 'pr/213' into release/1.17.0
Marvin-Magmodules Feb 26, 2024
4c4ae93
Improved Return block on Credit-memo page
Marvin-Magmodules Feb 27, 2024
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
10 changes: 10 additions & 0 deletions Api/Config/System/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface OrderInterface extends ReturnsInterface
const XML_PATH_LVB_SKIP_STOCK = 'magmodules_channable_marketplace/order/lvb_stock';
const XML_PATH_LVB_AUTO_SHIP = 'magmodules_channable_marketplace/order/lvb_ship';
const XML_PATH_DEDUCT_FPT = 'magmodules_channable_marketplace/order/deduct_fpt';
const XML_PATH_BUSINESS_ORDER = 'magmodules_channable_marketplace/order/business_order';
const XML_PATH_TRANSACTION_FEE = 'magmodules_channable_marketplace/order/transaction_fee';
const XML_PATH_LOG = 'magmodules_channable_marketplace/order/log';
const XML_PATH_CARRIER_TITLE = 'carriers/channable/title';
Expand Down Expand Up @@ -285,6 +286,15 @@ public function autoShipLvbOrders(int $storeId = null): bool;
*/
public function deductFptTax(int $storeId = null): bool;

/**
* Check if business orders enabled.
*
* @param null|int $storeId
*
* @return bool
*/
public function isBusinessOrderEnabled(int $storeId = null): bool;

/**
* Check if need to add transaction fee
*
Expand Down
48 changes: 48 additions & 0 deletions Api/Returns/Data/DataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ interface DataInterface extends ExtensibleDataInterface
public const REASON = 'reason';
public const COMMENT = 'comment';
public const STATUS = 'status';
public const CHANNEL_RETURN_ID = 'channel_return_id';
public const CHANNEL_ORDER_ID = 'channel_order_id';
public const CHANNEL_ORDER_ID_INTERNAL = 'channel_order_id_internal';
public const PLATFORM_ORDER_ID = 'platform_order_id';
public const CREATED_AT = 'created_at';
public const UPDATED_AT = 'updated_at';

Expand Down Expand Up @@ -217,6 +221,50 @@ public function getStatus(): string;
*/
public function setStatus(string $status): self;

/**
* @return string|null
*/
public function getChannelReturnId(): ?string;

/**
* @param string|null $channelReturnId
* @return $this
*/
public function setChannelReturnId(?string $channelReturnId): self;

/**
* @return string|null
*/
public function getChannelOrderId(): ?string;

/**
* @param string|null $channelOrderId
* @return $this
*/
public function setChannelOrderId(?string $channelOrderId): self;

/**
* @return string|null
*/
public function getChannelOrderIdInternal(): ?string;

/**
* @param string|null $channelOrderIdInternal
* @return $this
*/
public function setChannelOrderIdInternal(?string $channelOrderIdInternal): self;

/**
* @return string|null
*/
public function getPlatformOrderId(): ?string;

/**
* @param string|null $platformOrderId
* @return $this
*/
public function setPlatformOrderId(?string $platformOrderId): self;

/**
* @return string
*/
Expand Down
47 changes: 44 additions & 3 deletions Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Magento\Bundle\Model\ResourceModel\Selection as BundleResource;
use Magmodules\Channable\Api\Log\RepositoryInterface as LogRepository;
use Magmodules\Channable\Service\Product\InventoryData;
use Magmodules\Channable\Service\Product\MediaData;

/**
* Class Product
Expand Down Expand Up @@ -84,6 +85,12 @@ class Product extends AbstractHelper
* @var CatalogPrice
*/
private $commonPriceModel;

/**
* @var MediaData
*/
private $mediaData;

/**
* @var LogRepository
*/
Expand Down Expand Up @@ -128,6 +135,7 @@ public function __construct(
ConfigurableResource $catalogProductTypeConfigurable,
CatalogPrice $commonPriceModel,
InventoryData $inventoryData,
MediaData $mediaData,
LogRepository $logger
) {
$this->galleryReadHandler = $galleryReadHandler;
Expand All @@ -143,6 +151,7 @@ public function __construct(
$this->catalogProductTypeBundle = $catalogProductTypeBundle;
$this->commonPriceModel = $commonPriceModel;
$this->inventoryData = $inventoryData;
$this->mediaData = $mediaData;
$this->logger = $logger;
parent::__construct($context);
}
Expand Down Expand Up @@ -254,6 +263,11 @@ public function validateProduct($product, $parent, $config)
}
}

$visibilityFilter = $config['filters']['visibility'] ?? [];
if (!empty($visibilityFilter) && in_array($product->getVisibility(), $visibilityFilter)) {
return true;
}

if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
if (empty($parent)) {
return false;
Expand Down Expand Up @@ -519,8 +533,13 @@ public function getImageData($attribute, $config, $product)
}
}
}
$this->galleryReadHandler->execute($product);

$galleryImages = $product->getMediaGallery('images');
if (!$galleryImages) {
$this->galleryReadHandler->execute($product);
$galleryImages = $product->getMediaGallery('images');
}

foreach ($galleryImages as $image) {
if (empty($image['disabled']) || !empty($config['inc_hidden_image'])) {
$images[] = $this->catalogProductMediaConfig->getMediaUrl($image['file']);
Expand Down Expand Up @@ -608,9 +627,15 @@ public function getResizedImage($product, $source, $size)
*/
public function getAttributeSetName($product)
{
static $attributeSets = [];

try {
$attributeSetRepository = $this->attributeSet->get($product->getAttributeSetId());
return $attributeSetRepository->getAttributeSetName();
if (!isset($attributeSets[$product->getAttributeSetId()])) {
$attributeSetName = $this->attributeSet->get($product->getAttributeSetId())->getAttributeSetName();
$attributeSets[$product->getAttributeSetId()] = $attributeSetName;
}

return $attributeSets[$product->getAttributeSetId()];
} catch (\Exception $e) {
$this->logger->addErrorLog('getAttributeSetName', $e->getMessage());
}
Expand Down Expand Up @@ -1313,4 +1338,20 @@ public function getParentId($product, $filters)

return array_unique($parentIds);
}

/**
* @return InventoryData
*/
public function getInventoryData()
{
return $this->inventoryData;
}

/**
* @return MediaData
*/
public function getMediaData()
{
return $this->mediaData;
}
}
6 changes: 5 additions & 1 deletion Helper/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,11 @@ public function getCategoryData($product, $parent, $categories)
if (!empty($categories[$catId])) {
$category = $categories[$catId];
if (!empty($category['path'])) {
$path[] = ['level' => $category['level'], 'path' => implode(' > ', $category['path'])];
$path[] = [
'level' => $category['level'],
'id' => $catId,
'path' => implode(' > ', $category['path'])
];
}
}
}
Expand Down
76 changes: 45 additions & 31 deletions Model/Collection/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magmodules\Channable\Model\Collection;

use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as ProductAttributeCollectionFactory;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Catalog\Model\Indexer\Product\Flat\StateFactory;
Expand All @@ -27,6 +28,10 @@ class Products
* @var ProductCollectionFactory
*/
private $productCollectionFactory;
/**
* @var ProductCollection
*/
private $productCollection;
/**
* @var ProductAttributeCollectionFactory
*/
Expand Down Expand Up @@ -70,6 +75,7 @@ class Products
*/
public function __construct(
ProductCollectionFactory $productCollectionFactory,
ProductCollection $productCollection,
ProductAttributeCollectionFactory $productAttributeCollectionFactory,
EavConfig $eavConfig,
StockHelper $stockHelper,
Expand All @@ -79,6 +85,7 @@ public function __construct(
ResourceConnection $resource
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->productCollection = $productCollection;
$this->productAttributeCollectionFactory = $productAttributeCollectionFactory;
$this->eavConfig = $eavConfig;
$this->productFlatState = $productFlatState;
Expand Down Expand Up @@ -116,6 +123,10 @@ public function getCollection($config, $page, $productIds)
->addUrlRewrite()
->setOrder('product_website.product_id', 'ASC');

if (in_array('tier_price', $attributes)) {
$collection->addTierPriceData();
}

if (!empty($filters['visibility'])) {
$collection->addAttributeToFilter('visibility', ['in' => $filters['visibility']]);
}
Expand Down Expand Up @@ -373,49 +384,52 @@ public function joinPriceIndexLeft($collection, $websiteId)
* @param $parentRelations
* @param $config
*
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
* @return ProductCollection
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getParents($parentRelations, $config)
public function getParents($parentRelations, $config): ProductCollection
{
if (!empty($parentRelations)) {
$filters = $config['filters'];
if (empty($parentRelations)) {
return $this->productCollection; //return empty product collection
}

if (!$config['flat']) {
$productFlatState = $this->productFlatState->create(['isAvailable' => false]);
} else {
$productFlatState = $this->productFlatState->create(['isAvailable' => true]);
}
$filters = $config['filters'];

$entityField = $this->generalHelper->getLinkField();
$attributes = $this->getAttributes($config['attributes']);
if (!$config['flat']) {
$productFlatState = $this->productFlatState->create(['isAvailable' => false]);
} else {
$productFlatState = $this->productFlatState->create(['isAvailable' => true]);
}

$collection = $this->productCollectionFactory
->create(['catalogProductFlatState' => $productFlatState])
->addStoreFilter($config['store_id'])
->addAttributeToFilter($entityField, ['in' => array_values($parentRelations)])
->addAttributeToSelect($attributes)
->addUrlRewrite()
->setRowIdFieldName($entityField);
$entityField = $this->generalHelper->getLinkField();
$attributes = $this->getAttributes($config['attributes']);

if (!empty($filters['category_ids'])) {
if (!empty($filters['category_type'])) {
$collection->addCategoriesFilter([$filters['category_type'] => $filters['category_ids']]);
}
}
$collection = $this->productCollectionFactory
->create(['catalogProductFlatState' => $productFlatState])
->addStoreFilter($config['store_id'])
->addAttributeToFilter($entityField, ['in' => array_values($parentRelations)])
->addAttributeToSelect($attributes)
->addUrlRewrite()
->setRowIdFieldName($entityField);

if (!empty($filters['visibility'])) {
$collection->addAttributeToFilter('visibility', ['in' => $filters['visibility']]);
if (!empty($filters['category_ids'])) {
if (!empty($filters['category_type'])) {
$collection->addCategoriesFilter([$filters['category_type'] => $filters['category_ids']]);
}
}

if (!empty($config['inventory']['attributes'])) {
$this->joinCatalogInventoryLeft($collection, $config);
}
if (!empty($filters['visibility'])) {
$collection->addAttributeToFilter('visibility', ['in' => $filters['visibility']]);
}

$this->addFilters($filters, $collection, 'parent');
$this->joinPriceIndexLeft($collection, $config['website_id']);
return $collection->load();
if (!empty($config['inventory']['attributes'])) {
$this->joinCatalogInventoryLeft($collection, $config);
}

$this->addFilters($filters, $collection, 'parent');
$this->joinPriceIndexLeft($collection, $config['website_id']);
return $collection->load();

}

/**
Expand Down
8 changes: 8 additions & 0 deletions Model/Config/System/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public function deductFptTax(int $storeId = null): bool
return $this->isSetFlag(self::XML_PATH_DEDUCT_FPT, $storeId);
}

/**
* @inheritDoc
*/
public function isBusinessOrderEnabled(int $storeId = null): bool
{
return $this->isSetFlag(self::XML_PATH_BUSINESS_ORDER, $storeId);
}

/**
* @inheritDoc
*/
Expand Down
23 changes: 23 additions & 0 deletions Model/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magmodules\Channable\Model;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Framework\Exception\LocalizedException;
use Magmodules\Channable\Model\Collection\Products as ProductsModel;
use Magmodules\Channable\Model\Item as ItemModel;
Expand Down Expand Up @@ -120,6 +121,8 @@ public function generateByStore(
$parentRelations = $this->productHelper->getParentsFromCollection($products, $config);
$parents = $this->productModel->getParents($parentRelations, $config);

$this->prefetchData($products, $parents, $parentRelations, $config);

foreach ($products as $product) {
/** @var Product $product */
$parent = null;
Expand Down Expand Up @@ -208,4 +211,24 @@ public function getDataRow($product, $parent, $config): ?array

return null;
}

/**
* Prefetches data to reduce amount of queries required.
* This increases performance by a lot for environments with >1ms latency to database.
*
* @param ProductCollection $products
* @param ProductCollection $parents
* @param array $parentRelations
* @param array $config
* @return void
*/
private function prefetchData(
ProductCollection $products,
ProductCollection $parents,
array $parentRelations,
array $config
) {
$this->productHelper->getInventoryData()->load($products->getColumnValues('sku'), $config);
$this->productHelper->getMediaData()->load($products, $parents);
}
}
Loading
Loading