Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
065dce9
Merge branch 'develop'
avstudnitz Dec 21, 2017
fdb15b2
Make product indexing compatible to Magento 2.2 regarding category info
avstudnitz Aug 16, 2018
17ba17c
Use correct method to retrieve databse table name of category product…
avstudnitz Aug 27, 2018
5c8d3d8
Use PHP 7.1 for CI
schmengler Aug 27, 2018
d5a42bf
Revert "Use PHP 7.1 for CI"
schmengler Aug 27, 2018
3ca470e
Restore compatibility to PHP 7.0 and lower.
avstudnitz Aug 27, 2018
eef0915
Merge remote-tracking branch 'composer/2.2-compatibility' into 2.2-co…
avstudnitz Aug 27, 2018
b267717
Fix usage of TableMaintainer class
avstudnitz Aug 28, 2018
a89bb74
Add area code emulation to store emulation.
avstudnitz Sep 17, 2018
5b33de3
Merge develop
avstudnitz Sep 17, 2018
7901112
Emulate area code for all cases the indexer can run
avstudnitz Sep 17, 2018
ca1456d
Fix indexing for Magento Commerce edition
avstudnitz Sep 21, 2018
1ea4799
Update unit test for area code emulation, remove duplicate
schmengler Oct 10, 2018
8a76296
Use latest Magento versions 2.1.15 and 2.2.6 for CI
schmengler Oct 10, 2018
c24943f
Wercker: Replace mageinferno image with meanbee image
schmengler Oct 10, 2018
c115ba1
Use PHP 7.1 for Magento 2.2 in CI (PHP 7.0 for Magento 2.1)
schmengler Oct 10, 2018
3bedc22
Skip broken test for Magento >=2.2.5 (product fixtures issue)
schmengler Oct 10, 2018
986b3c4
Remove DB isolation from test with reindex
schmengler Oct 10, 2018
0504353
Only add autosuggest HTML to index if autosuggest is active
schmengler Oct 10, 2018
bb54bf1
Magento cannot handle return types in Proxy generation
schmengler Oct 10, 2018
b4aaa59
Fix category attributes
avstudnitz Oct 19, 2018
6217dad
Add comment
avstudnitz Oct 19, 2018
864d536
Add indexing of products if they are assigned to a category
avstudnitz Oct 24, 2018
c4bb05b
Merge pull request #58 from integer-net/trigger-index-on-category-pro…
avstudnitz Dec 4, 2018
5c698ef
Merge pull request #57 from integer-net/fix-category-attributes
avstudnitz Dec 4, 2018
764d80e
Merge pull request #56 from integer-net/skip-html-index-if-unnecessary
avstudnitz Dec 4, 2018
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
18 changes: 12 additions & 6 deletions build/install-magento.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -x
echo memory_limit=-1 >> /usr/local/etc/php/php.ini
git checkout -b tmp
git add -A
git config --global user.email "wercker@localhost"
git config --global user.name "Wercker"
git commit --allow-empty -m "tmp"
export MODULE_DIR=`pwd`
export M2SETUP_DB_HOST=$MYSQL_CI_PORT_3306_TCP_ADDR
Expand All @@ -20,10 +22,15 @@ export M2SETUP_VERSION=$1
export M2SETUP_USE_SAMPLE_DATA=false
export M2SETUP_USE_ARCHIVE=true
export COMPOSER_HOME=$WERCKER_CACHE_DIR/composer
BIN_MAGENTO=magento-command

# Reconfigure composer after COMPOSER_HOME has been changed
[ ! -z "${COMPOSER_MAGENTO_USERNAME}" ] && \
composer config -a -g http-basic.repo.magento.com $COMPOSER_MAGENTO_USERNAME $COMPOSER_MAGENTO_PASSWORD

mysqladmin -u$M2SETUP_DB_USER -p"$M2SETUP_DB_PASSWORD" -h$M2SETUP_DB_HOST create $M2SETUP_DB_NAME
/usr/local/bin/mage-setup
cd /srv/www
composer config http-basic.repo.magento.com $MAGENTO_REPO_PUBLIC_KEY $MAGENTO_REPO_PRIVATE_KEY
DEBUG=true magento-installer
cd /var/www/magento
composer config repositories.solr-module vcs $MODULE_DIR
composer config repositories.solr-autosuggest vcs [email protected]:integer-net/solr-magento2-autosuggest.git
composer config repositories.solr-base vcs [email protected]:integer-net/solr-base.git
Expand All @@ -42,6 +49,5 @@ composer update
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
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
sed -i -e "s/solr-magento2-tests/core0/g" vendor/integer-net/solr-magento2/main/test/integration/_files/solr_config.dist.php
bin/magento module:enable IntegerNet_Solr
bin/magento setup:di:compile
bin/magento setup:upgrade
$BIN_MAGENTO module:enable IntegerNet_Solr
$BIN_MAGENTO setup:di:compile
18 changes: 9 additions & 9 deletions build/integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export M2SETUP_DB_USER=root
export M2SETUP_DB_PASSWORD=$MYSQL_CI_ENV_MYSQL_ROOT_PASSWORD
export TEST_DB_NAME=magento_integration_tests
mysqladmin -u$M2SETUP_DB_USER -p"$M2SETUP_DB_PASSWORD" -h$M2SETUP_DB_HOST create $TEST_DB_NAME
cp $MODULE_DIR/main/test/integration/phpunit.xml.dist /srv/www/dev/tests/integration/phpunit.xml
cp $MODULE_DIR/main/test/integration/install-config-mysql.php /srv/www/dev/tests/integration/etc/
sed -i -e "s/DB_HOST/$M2SETUP_DB_HOST/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_USER/$M2SETUP_DB_USER/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_PASSWORD/$M2SETUP_DB_PASSWORD/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_NAME/$TEST_DB_NAME/g" /srv/www/dev/tests/integration/etc/install-config-mysql.php
cd /srv/www/dev/tests/integration
cp $MODULE_DIR/main/test/integration/phpunit.xml.dist /var/www/magento/dev/tests/integration/phpunit.xml
cp $MODULE_DIR/main/test/integration/install-config-mysql.php /var/www/magento/dev/tests/integration/etc/
sed -i -e "s/DB_HOST/$M2SETUP_DB_HOST/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_USER/$M2SETUP_DB_USER/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_PASSWORD/$M2SETUP_DB_PASSWORD/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
sed -i -e "s/DB_NAME/$TEST_DB_NAME/g" /var/www/magento/dev/tests/integration/etc/install-config-mysql.php
cd /var/www/magento/dev/tests/integration
php ../../../vendor/phpunit/phpunit/phpunit

cp $MODULE_DIR/categories/test/integration/phpunit.xml.dist /srv/www/dev/tests/integration/phpunit.xml
cd /srv/www/dev/tests/integration
cp $MODULE_DIR/categories/test/integration/phpunit.xml.dist /var/www/magento/dev/tests/integration/phpunit.xml
cd /var/www/magento/dev/tests/integration
php ../../../vendor/phpunit/phpunit/phpunit
15 changes: 13 additions & 2 deletions main/src/Model/Bridge/ProductRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use IntegerNet\Solr\Implementor\Product as ProductInterface;
use IntegerNet\Solr\Implementor\ProductRenderer as ProductRendererInterface;
use IntegerNet\Solr\Indexer\IndexDocument;
use IntegerNet\Solr\Model\Config\FrontendStoresConfig;
use Magento\Framework\App\State as AppState;
use Magento\Framework\View\LayoutInterface;

Expand All @@ -27,10 +28,18 @@ class ProductRenderer implements ProductRendererInterface
* @var AppState
*/
private $appState;
/**
* @var FrontendStoresConfig
*/
private $storesConfig;
/**
* @var bool
*/
private $isLayoutLoaded = false;

public function __construct(LayoutInterface\Proxy $layout, AppState $appState)
public function __construct(LayoutInterface\Proxy $layout, AppState $appState, FrontendStoresConfig $storesConfig)
{
$this->storesConfig = $storesConfig;
$this->layout = $layout;
$this->appState = $appState;
}
Expand Down Expand Up @@ -65,7 +74,9 @@ public function addResultHtmlToProductData(ProductInterface $product, IndexDocum
// We need direct access to the Magento product
throw new \InvalidArgumentException('Magento 2 product bridge expected, '. get_class($product) .' received.');
}
$this->addAutosuggestItemHtml($product, $productData);
if ($this->storesConfig->byStoreId($product->getStoreId())->getAutosuggestConfig()->isActive()) {
$this->addAutosuggestItemHtml($product, $productData);
}
//TODO if $useHtmlInResult, render product list and grid HTML
}

Expand Down
4 changes: 4 additions & 0 deletions main/src/Model/Config/FrontendStoresConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public function __construct(StoreManagerInterface $storeManager, ConfigFactory $
parent::__construct($configByStore);
}

public function byStoreId($storeId)
{
return $this[$storeId];
}
}
29 changes: 19 additions & 10 deletions main/src/Model/Indexer/Fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@
use IntegerNet\Solr\Plugin\UrlFactoryPlugin;
use Magento\Framework\Indexer\ActionInterface;
use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
use Magento\Framework\App\State;

class Fulltext implements ActionInterface, MviewActionInterface
{
/**
* @var ProductIndexer
*/
private $solrIndexer;

/**
* @param ProductIndexerFactory $solrIndexerFactory
* @var State
*/
public function __construct(ProductIndexerFactory $solrIndexerFactory)
{
private $state;

public function __construct(
ProductIndexerFactory $solrIndexerFactory,
State $state
) {
$this->solrIndexer = $solrIndexerFactory->create();
$this->state = $state;
}

/**
Expand Down Expand Up @@ -91,12 +96,16 @@ private function reindex(
$sliceId = null,
$totalNumberSlices = null
) {
$this->solrIndexer->reindex(
$productIds,
$emptyIndex,
$restrictToStoreIds,
$sliceId,
$totalNumberSlices
$this->state->emulateAreaCode(
'frontend',
[$this->solrIndexer, 'reindex'],
[
$productIds,
$emptyIndex,
$restrictToStoreIds,
$sliceId,
$totalNumberSlices
]
);
}
}
25 changes: 24 additions & 1 deletion main/src/Model/ResourceModel/CategoryPosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,28 @@
*/
namespace IntegerNet\Solr\Model\ResourceModel;

use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Model\ResourceModel\Db\Context;

class CategoryPosition extends AbstractDb
{
/**
* @var ProductMetadataInterface
*/
private $productMetaData;

public function __construct(
Context $context,
ProductMetadataInterface $productMetadata,
$connectionName = null
) {
$this->productMetaData = $productMetadata;
parent::__construct($context, $connectionName);
}

/**
* Resource initialization
*
Expand All @@ -32,9 +50,14 @@ protected function _construct()
*/
public function getCategoryPositions($productId, $storeId)
{
$table = $this->getMainTable();
if (\class_exists(TableMaintainer::class)) {
$tableMaintainer = ObjectManager::getInstance()->get(TableMaintainer::class);
$table = $tableMaintainer->getMainTable($storeId);
}
$select = $this->getConnection()
->select()
->from($this->getMainTable(), ['category_id', 'position'])
->from($table, ['category_id', 'position'])
->where('product_id = ?', $productId)
->where('store_id = ?', $storeId);
return $this->getConnection()->fetchAll($select);
Expand Down
19 changes: 14 additions & 5 deletions main/src/Model/ResourceModel/GroupedProductAssociations.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use IntegerNet\Solr\Model\Data\ArrayCollection;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface as AttributeRepository;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context as ResourceContext;
Expand All @@ -30,18 +31,24 @@ class GroupedProductAssociations extends AbstractDb implements ProductAssociatio
* @var AttributeRepository
*/
private $attributeRepository;
/**
* @var ProductResource
*/
private $productResource;

private $productEntityLinkField;

public function __construct(
ResourceContext $context,
MetadataPool $metadataPool,
AttributeRepository $attributeRepository,
ProductResource $productResource,
$connectionName = null
) {
$this->metadataPool = $metadataPool;
parent::__construct($context, $connectionName);
$this->attributeRepository = $attributeRepository;
$this->productResource = $productResource;
}

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

$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$select = $connection->select()->from(
['l' => $this->getMainTable()],
['product_id', 'linked_product_id']
)->join(
['cpe' => $this->getTable('catalog_product_entity')],
sprintf(
'cpe.%s = l.product_id',
$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()
)
'cpe.entity_id = l.product_id'
)->join(
['cpei' => $this->getTable('catalog_product_entity_int')],
'cpei.entity_id = l.linked_product_id AND cpei.attribute_id = :status_attribute_id',
sprintf(
'cpei.%s = cpe.%s AND cpei.attribute_id = :status_attribute_id',
$linkField,
$linkField
),
''
)->where(
'link_type_id = :link_type_id'
Expand Down
60 changes: 60 additions & 0 deletions main/src/Plugin/CategoryDataProviderPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* integer_net Magento Module
*
* @copyright Copyright (c) 2018 integer_net GmbH (http://www.integer-net.de/)
* @author Andreas von Studnitz <[email protected]>
*/

namespace IntegerNet\Solr\Plugin;

use Magento\Eav\Model\Config as EavConfig;

class CategoryDataProviderPlugin
{
/**
* @var EavConfig
*/
private $eavConfig;

public function __construct(
EavConfig $eavConfig
) {
$this->eavConfig = $eavConfig;
}

public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result)
{
$meta = $result;
$meta = array_replace_recursive($meta, $this->prepareFieldsMeta(
$this->getFieldsMap(),
$subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
));
return $meta;
}

private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
{
$result = [];
foreach ($fieldsMap as $fieldSet => $fields) {
foreach ($fields as $field) {
if (isset($fieldsMeta[$field])) {
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
}
}
}
return $result;
}

private function getFieldsMap()
{
return [
'solr' => [
'solr_exclude',
'solr_exclude_children',
'solr_remove_filters',
'solr_boost',
]
];
}
}
6 changes: 6 additions & 0 deletions main/src/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<plugin name="search_weight_as_text" type="IntegerNet\Solr\Plugin\FrontTabPlugin" sortOrder="-10" />
</type>

<!-- Necessary for full functionality of category attributes -->
<!-- See See https://github.com/magento/magento2/issues/13440#issuecomment-392744685 -->
<type name="Magento\Catalog\Model\Category\DataProvider">
<plugin name="integernet_solr" type="IntegerNet\Solr\Plugin\CategoryDataProviderPlugin" />
</type>

<!-- Bugfix: Always use the frontend URL model for categories -->
<!-- necessary for autosuggest cache, to generate the right store urls -->
<type name="Magento\Catalog\Model\Category">
Expand Down
3 changes: 2 additions & 1 deletion main/src/etc/mview.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Same subscriptions as catalogsearch_fulltext
* Same subscriptions as catalogsearch_fulltext, plus category links
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
Expand All @@ -18,6 +18,7 @@
<table name="catalog_product_bundle_selection" entity_column="parent_product_id" />
<table name="catalog_product_super_link" entity_column="product_id" />
<table name="catalog_product_link" entity_column="product_id" />
<table name="catalog_category_product" entity_column="product_id" />
</subscriptions>
</view>
</config>
9 changes: 9 additions & 0 deletions main/test/integration/Database/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use IntegerNet\Solr\Model\Bridge\AttributeRepository;
use IntegerNet\Solr\Model\Bridge\Product;
use Magento\Catalog\Model\Product as MagentoProduct;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\TestFramework\ObjectManager;
use PHPUnit\Framework\TestCase;
use TddWizard\Fixtures\Catalog\ProductBuilder;
Expand All @@ -37,6 +38,14 @@ class ProductRepositoryTest extends TestCase
protected function setUp()
{
$this->objectManager = ObjectManager::getInstance();
//TODO fix test on Magento 2.2.5
/** @var ProductMetadataInterface $productMetadata */
$productMetadata = $this->objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class);
if (version_compare($productMetadata->getVersion(), '2.2.5', '>=')) {
$this->markTestSkipped(
'This test does not terminate on Magento 2.2.5 because of https://github.com/tddwizard/magento2-fixtures/issues/13'
);
}
$this->productRepository = $this->objectManager->create(ProductRepository::class);
}

Expand Down
Loading