Skip to content

Commit 4d8c8f8

Browse files
authored
Merge pull request #55 from integer-net/2.2-compatibility
Magento 2.2.5 compatibility
2 parents b29dec2 + 764d80e commit 4d8c8f8

File tree

15 files changed

+224
-53
lines changed

15 files changed

+224
-53
lines changed

build/install-magento.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -x
44
echo memory_limit=-1 >> /usr/local/etc/php/php.ini
55
git checkout -b tmp
66
git add -A
7+
git config --global user.email "wercker@localhost"
8+
git config --global user.name "Wercker"
79
git commit --allow-empty -m "tmp"
810
export MODULE_DIR=`pwd`
911
export M2SETUP_DB_HOST=$MYSQL_CI_PORT_3306_TCP_ADDR
@@ -20,10 +22,15 @@ export M2SETUP_VERSION=$1
2022
export M2SETUP_USE_SAMPLE_DATA=false
2123
export M2SETUP_USE_ARCHIVE=true
2224
export COMPOSER_HOME=$WERCKER_CACHE_DIR/composer
25+
BIN_MAGENTO=magento-command
26+
27+
# Reconfigure composer after COMPOSER_HOME has been changed
28+
[ ! -z "${COMPOSER_MAGENTO_USERNAME}" ] && \
29+
composer config -a -g http-basic.repo.magento.com $COMPOSER_MAGENTO_USERNAME $COMPOSER_MAGENTO_PASSWORD
30+
2331
mysqladmin -u$M2SETUP_DB_USER -p"$M2SETUP_DB_PASSWORD" -h$M2SETUP_DB_HOST create $M2SETUP_DB_NAME
24-
/usr/local/bin/mage-setup
25-
cd /srv/www
26-
composer config http-basic.repo.magento.com $MAGENTO_REPO_PUBLIC_KEY $MAGENTO_REPO_PRIVATE_KEY
32+
DEBUG=true magento-installer
33+
cd /var/www/magento
2734
composer config repositories.solr-module vcs $MODULE_DIR
2835
composer config repositories.solr-autosuggest vcs [email protected]:integer-net/solr-magento2-autosuggest.git
2936
composer config repositories.solr-base vcs [email protected]:integer-net/solr-base.git
@@ -42,6 +49,5 @@ composer update
4249
sed -i -e "s/8983/$SOLR_CI_PORT_8983_TCP_PORT/g" vendor/integer-net/solr-magento2/main/test/integration/_files/solr_config.dist.php
4350
sed -i -e "s/localhost/$SOLR_CI_PORT_8983_TCP_ADDR/g" vendor/integer-net/solr-magento2/main/test/integration/_files/solr_config.dist.php
4451
sed -i -e "s/solr-magento2-tests/core0/g" vendor/integer-net/solr-magento2/main/test/integration/_files/solr_config.dist.php
45-
bin/magento module:enable IntegerNet_Solr
46-
bin/magento setup:di:compile
47-
bin/magento setup:upgrade
52+
$BIN_MAGENTO module:enable IntegerNet_Solr
53+
$BIN_MAGENTO setup:di:compile

build/integration-tests.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export M2SETUP_DB_USER=root
77
export M2SETUP_DB_PASSWORD=$MYSQL_CI_ENV_MYSQL_ROOT_PASSWORD
88
export TEST_DB_NAME=magento_integration_tests
99
mysqladmin -u$M2SETUP_DB_USER -p"$M2SETUP_DB_PASSWORD" -h$M2SETUP_DB_HOST create $TEST_DB_NAME
10-
cp $MODULE_DIR/main/test/integration/phpunit.xml.dist /srv/www/dev/tests/integration/phpunit.xml
11-
cp $MODULE_DIR/main/test/integration/install-config-mysql.php /srv/www/dev/tests/integration/etc/
12-
sed -i -e "s/DB_HOST/$M2SETUP_DB_HOST/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
13-
sed -i -e "s/DB_USER/$M2SETUP_DB_USER/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
14-
sed -i -e "s/DB_PASSWORD/$M2SETUP_DB_PASSWORD/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
15-
sed -i -e "s/DB_NAME/$TEST_DB_NAME/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
16-
cd /srv/www/dev/tests/integration
10+
cp $MODULE_DIR/main/test/integration/phpunit.xml.dist /var/www/magento/dev/tests/integration/phpunit.xml
11+
cp $MODULE_DIR/main/test/integration/install-config-mysql.php /var/www/magento/dev/tests/integration/etc/
12+
sed -i -e "s/DB_HOST/$M2SETUP_DB_HOST/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
13+
sed -i -e "s/DB_USER/$M2SETUP_DB_USER/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
14+
sed -i -e "s/DB_PASSWORD/$M2SETUP_DB_PASSWORD/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
15+
sed -i -e "s/DB_NAME/$TEST_DB_NAME/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
16+
cd /var/www/magento/dev/tests/integration
1717
php ../../../vendor/phpunit/phpunit/phpunit
1818

19-
cp $MODULE_DIR/categories/test/integration/phpunit.xml.dist /srv/www/dev/tests/integration/phpunit.xml
20-
cd /srv/www/dev/tests/integration
19+
cp $MODULE_DIR/categories/test/integration/phpunit.xml.dist /var/www/magento/dev/tests/integration/phpunit.xml
20+
cd /var/www/magento/dev/tests/integration
2121
php ../../../vendor/phpunit/phpunit/phpunit

main/src/Model/Bridge/ProductRenderer.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use IntegerNet\Solr\Implementor\Product as ProductInterface;
1515
use IntegerNet\Solr\Implementor\ProductRenderer as ProductRendererInterface;
1616
use IntegerNet\Solr\Indexer\IndexDocument;
17+
use IntegerNet\Solr\Model\Config\FrontendStoresConfig;
1718
use Magento\Framework\App\State as AppState;
1819
use Magento\Framework\View\LayoutInterface;
1920

@@ -27,10 +28,18 @@ class ProductRenderer implements ProductRendererInterface
2728
* @var AppState
2829
*/
2930
private $appState;
31+
/**
32+
* @var FrontendStoresConfig
33+
*/
34+
private $storesConfig;
35+
/**
36+
* @var bool
37+
*/
3038
private $isLayoutLoaded = false;
3139

32-
public function __construct(LayoutInterface\Proxy $layout, AppState $appState)
40+
public function __construct(LayoutInterface\Proxy $layout, AppState $appState, FrontendStoresConfig $storesConfig)
3341
{
42+
$this->storesConfig = $storesConfig;
3443
$this->layout = $layout;
3544
$this->appState = $appState;
3645
}
@@ -65,7 +74,9 @@ public function addResultHtmlToProductData(ProductInterface $product, IndexDocum
6574
// We need direct access to the Magento product
6675
throw new \InvalidArgumentException('Magento 2 product bridge expected, '. get_class($product) .' received.');
6776
}
68-
$this->addAutosuggestItemHtml($product, $productData);
77+
if ($this->storesConfig->byStoreId($product->getStoreId())->getAutosuggestConfig()->isActive()) {
78+
$this->addAutosuggestItemHtml($product, $productData);
79+
}
6980
//TODO if $useHtmlInResult, render product list and grid HTML
7081
}
7182

main/src/Model/Config/FrontendStoresConfig.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public function __construct(StoreManagerInterface $storeManager, ConfigFactory $
2727
parent::__construct($configByStore);
2828
}
2929

30+
public function byStoreId($storeId)
31+
{
32+
return $this[$storeId];
33+
}
3034
}

main/src/Model/Indexer/Fulltext.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@
1414
use IntegerNet\Solr\Plugin\UrlFactoryPlugin;
1515
use Magento\Framework\Indexer\ActionInterface;
1616
use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
17+
use Magento\Framework\App\State;
1718

1819
class Fulltext implements ActionInterface, MviewActionInterface
1920
{
2021
/**
2122
* @var ProductIndexer
2223
*/
2324
private $solrIndexer;
24-
2525
/**
26-
* @param ProductIndexerFactory $solrIndexerFactory
26+
* @var State
2727
*/
28-
public function __construct(ProductIndexerFactory $solrIndexerFactory)
29-
{
28+
private $state;
29+
30+
public function __construct(
31+
ProductIndexerFactory $solrIndexerFactory,
32+
State $state
33+
) {
3034
$this->solrIndexer = $solrIndexerFactory->create();
35+
$this->state = $state;
3136
}
3237

3338
/**
@@ -91,12 +96,16 @@ private function reindex(
9196
$sliceId = null,
9297
$totalNumberSlices = null
9398
) {
94-
$this->solrIndexer->reindex(
95-
$productIds,
96-
$emptyIndex,
97-
$restrictToStoreIds,
98-
$sliceId,
99-
$totalNumberSlices
99+
$this->state->emulateAreaCode(
100+
'frontend',
101+
[$this->solrIndexer, 'reindex'],
102+
[
103+
$productIds,
104+
$emptyIndex,
105+
$restrictToStoreIds,
106+
$sliceId,
107+
$totalNumberSlices
108+
]
100109
);
101110
}
102111
}

main/src/Model/ResourceModel/CategoryPosition.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@
99
*/
1010
namespace IntegerNet\Solr\Model\ResourceModel;
1111

12+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
15+
use Magento\Framework\App\ProductMetadataInterface;
16+
use Magento\Framework\Model\ResourceModel\Db\Context;
1317

1418
class CategoryPosition extends AbstractDb
1519
{
20+
/**
21+
* @var ProductMetadataInterface
22+
*/
23+
private $productMetaData;
24+
25+
public function __construct(
26+
Context $context,
27+
ProductMetadataInterface $productMetadata,
28+
$connectionName = null
29+
) {
30+
$this->productMetaData = $productMetadata;
31+
parent::__construct($context, $connectionName);
32+
}
33+
1634
/**
1735
* Resource initialization
1836
*
@@ -32,9 +50,14 @@ protected function _construct()
3250
*/
3351
public function getCategoryPositions($productId, $storeId)
3452
{
53+
$table = $this->getMainTable();
54+
if (\class_exists(TableMaintainer::class)) {
55+
$tableMaintainer = ObjectManager::getInstance()->get(TableMaintainer::class);
56+
$table = $tableMaintainer->getMainTable($storeId);
57+
}
3558
$select = $this->getConnection()
3659
->select()
37-
->from($this->getMainTable(), ['category_id', 'position'])
60+
->from($table, ['category_id', 'position'])
3861
->where('product_id = ?', $productId)
3962
->where('store_id = ?', $storeId);
4063
return $this->getConnection()->fetchAll($select);

main/src/Model/ResourceModel/GroupedProductAssociations.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use IntegerNet\Solr\Model\Data\ArrayCollection;
1616
use Magento\Catalog\Api\ProductAttributeRepositoryInterface as AttributeRepository;
1717
use Magento\Catalog\Api\Data\ProductInterface;
18+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1819
use Magento\Framework\EntityManager\MetadataPool;
1920
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
2021
use Magento\Framework\Model\ResourceModel\Db\Context as ResourceContext;
@@ -30,18 +31,24 @@ class GroupedProductAssociations extends AbstractDb implements ProductAssociatio
3031
* @var AttributeRepository
3132
*/
3233
private $attributeRepository;
34+
/**
35+
* @var ProductResource
36+
*/
37+
private $productResource;
3338

3439
private $productEntityLinkField;
3540

3641
public function __construct(
3742
ResourceContext $context,
3843
MetadataPool $metadataPool,
3944
AttributeRepository $attributeRepository,
45+
ProductResource $productResource,
4046
$connectionName = null
4147
) {
4248
$this->metadataPool = $metadataPool;
4349
parent::__construct($context, $connectionName);
4450
$this->attributeRepository = $attributeRepository;
51+
$this->productResource = $productResource;
4552
}
4653

4754
/**
@@ -66,18 +73,20 @@ public function getAssociations($parentIds)
6673
$statusAttributeId = $this->attributeRepository->get('status')->getAttributeId();
6774
$bind = [':link_type_id' => ProductLinkResource::LINK_TYPE_GROUPED, ':status_attribute_id' => $statusAttributeId];
6875

76+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
6977
$select = $connection->select()->from(
7078
['l' => $this->getMainTable()],
7179
['product_id', 'linked_product_id']
7280
)->join(
7381
['cpe' => $this->getTable('catalog_product_entity')],
74-
sprintf(
75-
'cpe.%s = l.product_id',
76-
$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()
77-
)
82+
'cpe.entity_id = l.product_id'
7883
)->join(
7984
['cpei' => $this->getTable('catalog_product_entity_int')],
80-
'cpei.entity_id = l.linked_product_id AND cpei.attribute_id = :status_attribute_id',
85+
sprintf(
86+
'cpei.%s = cpe.%s AND cpei.attribute_id = :status_attribute_id',
87+
$linkField,
88+
$linkField
89+
),
8190
''
8291
)->where(
8392
'link_type_id = :link_type_id'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @copyright Copyright (c) 2018 integer_net GmbH (http://www.integer-net.de/)
6+
* @author Andreas von Studnitz <[email protected]>
7+
*/
8+
9+
namespace IntegerNet\Solr\Plugin;
10+
11+
use Magento\Eav\Model\Config as EavConfig;
12+
13+
class CategoryDataProviderPlugin
14+
{
15+
/**
16+
* @var EavConfig
17+
*/
18+
private $eavConfig;
19+
20+
public function __construct(
21+
EavConfig $eavConfig
22+
) {
23+
$this->eavConfig = $eavConfig;
24+
}
25+
26+
public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result)
27+
{
28+
$meta = $result;
29+
$meta = array_replace_recursive($meta, $this->prepareFieldsMeta(
30+
$this->getFieldsMap(),
31+
$subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
32+
));
33+
return $meta;
34+
}
35+
36+
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
37+
{
38+
$result = [];
39+
foreach ($fieldsMap as $fieldSet => $fields) {
40+
foreach ($fields as $field) {
41+
if (isset($fieldsMeta[$field])) {
42+
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
43+
}
44+
}
45+
}
46+
return $result;
47+
}
48+
49+
private function getFieldsMap()
50+
{
51+
return [
52+
'solr' => [
53+
'solr_exclude',
54+
'solr_exclude_children',
55+
'solr_remove_filters',
56+
'solr_boost',
57+
]
58+
];
59+
}
60+
}

main/src/etc/adminhtml/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<plugin name="search_weight_as_text" type="IntegerNet\Solr\Plugin\FrontTabPlugin" sortOrder="-10" />
66
</type>
77

8+
<!-- Necessary for full functionality of category attributes -->
9+
<!-- See See https://github.com/magento/magento2/issues/13440#issuecomment-392744685 -->
10+
<type name="Magento\Catalog\Model\Category\DataProvider">
11+
<plugin name="integernet_solr" type="IntegerNet\Solr\Plugin\CategoryDataProviderPlugin" />
12+
</type>
13+
814
<!-- Bugfix: Always use the frontend URL model for categories -->
915
<!-- necessary for autosuggest cache, to generate the right store urls -->
1016
<type name="Magento\Catalog\Model\Category">

main/src/etc/mview.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
/**
4-
* Same subscriptions as catalogsearch_fulltext
4+
* Same subscriptions as catalogsearch_fulltext, plus category links
55
*/
66
-->
77
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
@@ -18,6 +18,7 @@
1818
<table name="catalog_product_bundle_selection" entity_column="parent_product_id" />
1919
<table name="catalog_product_super_link" entity_column="product_id" />
2020
<table name="catalog_product_link" entity_column="product_id" />
21+
<table name="catalog_category_product" entity_column="product_id" />
2122
</subscriptions>
2223
</view>
2324
</config>

0 commit comments

Comments
 (0)