Skip to content

Commit

Permalink
Merge pull request #17 from FriendsOfShopware/v1.1.0
Browse files Browse the repository at this point in the history
Release V1.1.0
  • Loading branch information
vienthuong authored May 23, 2021
2 parents 7b1a4cd + b7774d1 commit 2c1679f
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 137 deletions.
35 changes: 20 additions & 15 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.1.0 - 6.4 kompatibel
- Shopware 6.4 Kompatibilität
- [Issue-14] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/14) Behebt, dass der Cross-Sellings-Vergleich nicht mit Produktvarianten funktioniert
- Anzeige des Wertes der Eigenschaftsoption der Variante in der Vergleichsliste
- [Issue-15] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/15) Neue Plugin-Konfiguration hinzugefügt, um zwischen "show all/selected properties" umzuschalten
- Kleinere Probleme beheben

# 1.0.6
- [Issue-11] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/11) Korrigieren Sie die Import-SCSS-Syntax.
- Kleiner Refactor auf der `base.html.twig` des Plugins
Expand All @@ -13,20 +20,18 @@
- Fix Cross-Selling funktioniert nach der Installation des Plugins nicht.

# 1.0.2

- Shopware 6.3 Kompatibilität

# 1.0.1 - Release on Shopware store as Frosh's plugin

- Remove some redundant LoC.
- Add robot noindex meta on Compare page
- Update the plugin's name and add some store's requirements.

# 1.0.0 - First release
- Add `Add to Compare` button in Product Card and Product detail.
- Add `Float button` on bottom left of the page with `added products counter`.
- Add `Products added to compare list offcanvas` when click `Float button`.
- Add `Compare page` to display Compare products table. Up to 4 products can be added into the list.
- Add `Print` button in Compare page to print the compare table.
- Add `Clear all` button to clear all products in the list.
- Add `Comparable switch` in `Administration > Product Detail > Cross-selling tab` that allow to display cross-selling products as a compare table.
# 1.0.1 - Freigabe im Shopware-Store als Plugin von Frosh
- Entfernen einiger überflüssiger LoC.
- Hinzufügen von robot noindex meta auf der Vergleichsseite
- Aktualisieren Sie den Namen des Plugins und fügen Sie einige Anforderungen des Shops hinzu.

# 1.0.0 - Erste Freigabe
- Hinzufügen der Schaltfläche "Zum Vergleich hinzufügen" in der Produktkarte und im Produktdetail.
- Schaltfläche "Float" unten links auf der Seite mit Zähler für "hinzugefügte Produkte" hinzufügen.
- Hinzufügen von "Zur Vergleichsliste hinzugefügte Produkte außerhalb des Bildschirms", wenn Sie auf die Schaltfläche "Float" klicken.
- Fügen Sie "Vergleichsseite" hinzu, um die Tabelle "Produkte vergleichen" anzuzeigen. Es können bis zu 4 Produkte in die Liste aufgenommen werden.
- Schaltfläche "Drucken" auf der Vergleichsseite hinzufügen, um die Vergleichstabelle zu drucken.
- Schaltfläche "Alle löschen" hinzufügen, um alle Produkte in der Liste zu löschen.
- Schalter "Vergleichbar" in "Verwaltung > Produktdetails > Registerkarte "Cross-Selling"" hinzufügen, um Cross-Selling-Produkte als Vergleichstabelle anzuzeigen.
7 changes: 7 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.1.0 - 6.4 compatible
- Shopware 6.4 compatibility
- [Issue-14] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/14) Fixes cross-sellings compare does not work with product variants
- Show variant's property option value in compare list
- [Issue-15] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/15) Added a new plugin's config to toggle between show all/selected properties
- Fix minor issues

# 1.0.6
- [Issue-11] (https://github.com/FriendsOfShopware/FroshProductCompare/issues/11) Fix import scss syntax.
- Small refactor on plugin's base.html.twig
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ http://shopware.thuong.lv/

- Add up to 4 products into compare list.
- Show compare list separated in products compare page or in product detail's cross-selling tab.
- Compare all properties or selected properties, configurable in plugin's config
- Read CHANGELOG for detail.

## Requirements

| Version | Requirements |
|--------- |---------------------------- |
| 1.0.6 | Shopware 6.2 >= |
| 1.0.6 | Shopware 6.4 >= |

## License

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frosh/product-compare",
"description": "A Simple Product Compare plugin for Shopware 6",
"version": "1.0.6",
"version": "1.1.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
Expand All @@ -15,8 +15,8 @@
}
],
"require": {
"shopware/core": "^6.3",
"shopware/storefront": "^6.3"
"shopware/core": "^6.4",
"shopware/storefront": "^6.4"
},
"extra": {
"shopware-plugin-class": "Frosh\\FroshProductCompare\\FroshProductCompare",
Expand Down
12 changes: 3 additions & 9 deletions src/Controller/CompareProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
*/
class CompareProductController extends StorefrontController
{
/**
* @var CompareProductPageLoader
*/
private $compareProductPageLoader;
/**
* @var GenericPageLoader
*/
private $genericPageLoader;
private CompareProductPageLoader $compareProductPageLoader;

private GenericPageLoader $genericPageLoader;

public function __construct(
CompareProductPageLoader $compareProductPageLoader,
Expand Down Expand Up @@ -56,7 +51,6 @@ public function comparePageContent(Request $request, SalesChannelContext $contex

/**
* @Route("/compare/offcanvas", name="frontend.compare.offcanvas", options={"seo"="false"}, methods={"POST"}, defaults={"XmlHttpRequest"=true})
*
*/
public function offcanvas(Request $request, SalesChannelContext $context): Response
{
Expand Down
12 changes: 9 additions & 3 deletions src/DependencyInjection/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
</service>

<service id="Frosh\FroshProductCompare\Page\CompareProductPageLoader">
<argument type="service" id="Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader"/>
<argument type="service" id="Shopware\Core\Content\Product\Cart\ProductGateway"/>
<argument type="service" id="Shopware\Storefront\Page\GenericPageLoader"/>
<argument type="service" id="Symfony\Component\EventDispatcher\EventDispatcherInterface" />
<argument type="service" id="product_review.repository" />
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
</service>

<service id="Frosh\FroshProductCompare\Controller\CompareProductController" public="true">
Expand All @@ -31,10 +32,15 @@
</service>

<!-- Subscriber -->
<service id="Frosh\FroshProductCompare\Subscriber\CrossSellingProductListingSubscriber">
<service id="Frosh\FroshProductCompare\Subscriber\FroshCrossSellingProductListingSubscriber">
<argument type="service" id="Frosh\FroshProductCompare\Page\CompareProductPageLoader"/>
<argument type="service" id="Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader"/>
<argument type="service" id="Shopware\Core\Content\Product\Cart\ProductGateway"/>
<tag name="kernel.event_subscriber"/>
</service>

<service id="Frosh\FroshProductCompare\Subscriber\FroshProductGatewayCriteriaSubscriber">
<tag name="kernel.event_subscriber"/>
</service>

</services>
</container>
2 changes: 1 addition & 1 deletion src/FroshProductCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function cleanRelatedData(): void
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);

$connection->exec('
$connection->executeStatement('
DROP TABLE IF EXISTS frosh_cross_selling_comparable;
');
}
Expand Down
5 changes: 1 addition & 4 deletions src/Page/CompareProductPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

class CompareProductPage extends Page
{
/**
* @var ProductListingResult
*/
protected $products;
protected ProductListingResult $products;

public function getProducts(): ProductListingResult
{
Expand Down
99 changes: 40 additions & 59 deletions src/Page/CompareProductPageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Shopware\Core\Content\Product\Aggregate\ProductReview\ProductReviewCollection;
use Shopware\Core\Content\Product\Aggregate\ProductReview\ProductReviewEntity;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Shopware\Core\Content\Product\Events\ProductListingResultEvent;
use Shopware\Core\Content\Product\Cart\ProductGateway;
use Shopware\Core\Content\Product\ProductCollection;
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader;
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingResult;
use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionCollection;
Expand All @@ -24,6 +22,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\GenericPageLoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand All @@ -32,39 +31,33 @@ class CompareProductPageLoader
{
const MAX_COMPARE_PRODUCT_ITEMS = 4;

/**
* @var GenericPageLoaderInterface
*/
private $genericLoader;
/**
* @var ProductListingLoader
*/
private $productListingLoader;
private GenericPageLoaderInterface $genericLoader;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var EntityRepositoryInterface
*/
private $productReviewRepository;
private ProductGateway $productGateway;

private EventDispatcherInterface $eventDispatcher;

private EntityRepositoryInterface $productReviewRepository;

private SystemConfigService $systemConfigService;

public function __construct(
ProductListingLoader $productListingLoader,
ProductGateway $productGateway,
GenericPageLoaderInterface $genericLoader,
EventDispatcherInterface $eventDispatcher,
EntityRepositoryInterface $productReviewRepository
EntityRepositoryInterface $productReviewRepository,
SystemConfigService $systemConfigService
) {
$this->productListingLoader = $productListingLoader;
$this->productGateway = $productGateway;
$this->genericLoader = $genericLoader;
$this->eventDispatcher = $eventDispatcher;
$this->productReviewRepository = $productReviewRepository;
$this->systemConfigService = $systemConfigService;
}

public function loadPreview(array $productIds, Request $request, SalesChannelContext $salesChannelContext): CompareProductPage
{
$productIds = array_filter($productIds, function ($id) {
$productIds = array_filter(array_slice($productIds, 0, self::MAX_COMPARE_PRODUCT_ITEMS), function ($id) {
return Uuid::isValid($id);
});

Expand All @@ -80,7 +73,7 @@ public function loadPreview(array $productIds, Request $request, SalesChannelCon
$criteria = new Criteria();
$criteria->setIds($productIds)->setLimit(self::MAX_COMPARE_PRODUCT_ITEMS);

$products = $this->productListingLoader->load($criteria, $salesChannelContext);
$products = $this->productGateway->get($productIds, $salesChannelContext);

$result = ProductListingResult::createFrom($products);

Expand Down Expand Up @@ -110,31 +103,27 @@ public function load(array $productIds, Request $request, SalesChannelContext $s
return $page;
}

$criteria = $this->getCompareProductListCriteria($productIds);

$this->eventDispatcher->dispatch(
new ProductListingCriteriaEvent($request, $criteria, $salesChannelContext)
);

$products = $this->productListingLoader->load($criteria, $salesChannelContext);
$products = $this->productGateway->get($productIds, $salesChannelContext);

$result = ProductListingResult::createFrom($products);

$result = $this->loadProductCompareData($result, $salesChannelContext->getContext());

$this->eventDispatcher->dispatch(
new ProductListingResultEvent($request, $result, $salesChannelContext)
);
$result = $this->loadProductCompareData($result, $salesChannelContext);

$page->setProducts($result);

return $page;
}

private function sortProperties(SalesChannelProductEntity $product): PropertyGroupCollection
private function sortProperties(SalesChannelProductEntity $product, array $selectedProperties): PropertyGroupCollection
{
$properties = $product->getProperties();

if (!empty($selectedProperties)) {
$properties = $properties->filter(function (PropertyGroupOptionEntity $property) use ($selectedProperties) {
return in_array($property->getGroupId(), $selectedProperties);
});
}

if ($properties === null) {
return new PropertyGroupCollection();
}
Expand Down Expand Up @@ -169,29 +158,11 @@ private function sortProperties(SalesChannelProductEntity $product): PropertyGro
return $propertyGroupCollection;
}

public function getCompareProductListCriteria(array $productIds): Criteria
{
$criteria = new Criteria();
$criteria->setIds($productIds)
->addAssociation('media')
->addAssociation('prices')
->addAssociation('manufacturer')
->addAssociation('manufacturer.media')
->addAssociation('cover')
->addAssociation('options.group')
->addAssociation('properties.group')
->addAssociation('properties.media')
->addAssociation('mainCategories.category')
->setLimit(self::MAX_COMPARE_PRODUCT_ITEMS);

return $criteria;
}

private function loadProductReviews(array $productIds, Context $context): EntityCollection
{
$criteria = new Criteria();
$criteria->addAggregation(new CountAggregation('count', 'id'));
$criteria->addFilter(new EqualsFilter('status', true));
$criteria->addFilter(new EqualsFilter('status', true));
$criteria->addFilter(
new MultiFilter(MultiFilter::CONNECTION_OR, [
new EqualsAnyFilter('product.id', $productIds),
Expand All @@ -202,9 +173,19 @@ private function loadProductReviews(array $productIds, Context $context): Entity
return $this->productReviewRepository->search($criteria, $context)->getEntities();
}

public function loadProductCompareData(ProductListingResult $products, Context $context): ProductListingResult
public function loadProductCompareData(ProductListingResult $products, SalesChannelContext $context): ProductListingResult
{
$productReviews = $this->loadProductReviews($products->getIds(), $context);
$productReviews = $this->loadProductReviews($products->getIds(), $context->getContext());

$selectedProperties = [];
$showSelectedProperties = $this->systemConfigService->getBool('FroshProductCompare.config.showSelectedProperties', $context->getSalesChannelId());

if ($showSelectedProperties) {
$selectedProperties = $this->systemConfigService->get('FroshProductCompare.config.selectedProperties', $context->getSalesChannelId());
$selectedProperties = array_map(function ($property) {
return $property['id'];
}, $selectedProperties);
}

/** @var SalesChannelProductEntity $product */
foreach ($products as $product) {
Expand All @@ -220,7 +201,7 @@ public function loadProductCompareData(ProductListingResult $products, Context $
}
});

$sortedProperties = $this->sortProperties($product);
$sortedProperties = $this->sortProperties($product, $selectedProperties);

$product->setSortedProperties($sortedProperties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { Component } = Shopware;
const { Criteria, EntityCollection } = Shopware.Data;

Component.extend('sw-property-multi-select', 'sw-entity-multi-select', {
props: {
entityCollection: {
type: Array,
required: true,
default() {
return new EntityCollection(
'/property_group',
'property_group',
Shopware.Context.api,
new Criteria(1, this.resultLimit)
);
}
},

entityName: {
type: String,
required: false,
default: 'property_group'
},
},
});
5 changes: 3 additions & 2 deletions src/Resources/app/administration/src/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import './extension/sw-product/component/sw-product-cross-selling-form';
import './extension/sw-product/view/sw-product-detail-cross-selling';
import './extension/sw-product/page/sw-product-detail';
import './extension/sw-settings/sw-property-multi-select';

Shopware.Module.register('frosh-product-compare', {
type: 'plugin',
name: 'FroshProductCompare',
title: 'frosh-product-compare.generalInformation.mainMenuItemGeneral',
description: 'frosh-product-compare.generalInformation.descriptionTextModule',
version: '1.0.1',
targetVersion: '1.0.1',
version: '1.1.0',
targetVersion: '1.1.0',
color: '#9AA8B5',
icon: 'default-shopping-paper-bag'
});
Loading

0 comments on commit 2c1679f

Please sign in to comment.