Skip to content

Commit

Permalink
Merge pull request #82 from magento-dragons/PR-P1
Browse files Browse the repository at this point in the history
[DRAGONS] BugFix (P1)
  • Loading branch information
balex13 committed Jun 9, 2016
2 parents 66883d5 + 19181c3 commit 26630f7
Show file tree
Hide file tree
Showing 30 changed files with 159 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;
use Magento\Eav\Helper\Data;
use Magento\Framework\App\ObjectManager;

class Advanced extends Generic
{
Expand All @@ -36,6 +38,11 @@ class Advanced extends Generic
*/
protected $disableScopeChangeList;

/**
* @var PropertyLocker
*/
private $propertyLocker;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -241,6 +248,7 @@ protected function _prepareForm()
$form->getElement('is_global')->setDisabled(1);
}
$this->setForm($form);
$this->getPropertyLocker()->lock($form);
return $this;
}

Expand All @@ -264,4 +272,17 @@ private function getAttributeObject()
{
return $this->_coreRegistry->registry('entity_attribute');
}

/**
* Get property locker
*
* @return PropertyLocker
*/
private function getPropertyLocker()
{
if (null === $this->propertyLocker) {
$this->propertyLocker = ObjectManager::getInstance()->get(PropertyLocker::class);
}
return $this->propertyLocker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ public function addValueSortToCollection($collection, $dir = 'asc')
$attributeCode = $this->getAttribute()->getAttributeCode();
$attributeId = $this->getAttribute()->getId();
$attributeTable = $this->getAttribute()->getBackend()->getTable();
$linkField = $this->getAttribute()->getEntity()->getLinkField();

if ($this->getAttribute()->isScopeGlobal()) {
$tableName = $attributeCode . '_t';

$collection->getSelect()->joinLeft(
[$tableName => $attributeTable],
"e.entity_id={$tableName}.entity_id" .
"e.{$linkField}={$tableName}.{$linkField}" .
" AND {$tableName}.attribute_id='{$attributeId}'" .
" AND {$tableName}.store_id='0'",
[]
Expand All @@ -114,13 +115,13 @@ public function addValueSortToCollection($collection, $dir = 'asc')

$collection->getSelect()->joinLeft(
[$valueTable1 => $attributeTable],
"e.entity_id={$valueTable1}.entity_id" .
"e.{$linkField}={$valueTable1}.{$linkField}" .
" AND {$valueTable1}.attribute_id='{$attributeId}'" .
" AND {$valueTable1}.store_id='0'",
[]
)->joinLeft(
[$valueTable2 => $attributeTable],
"e.entity_id={$valueTable2}.entity_id" .
"e.{$linkField}={$valueTable2}.{$linkField}" .
" AND {$valueTable2}.attribute_id='{$attributeId}'" .
" AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
[]
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Catalog/Model/Product/Visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ public function addValueSortToCollection($collection, $dir = 'asc')
$attributeCode = $this->getAttribute()->getAttributeCode();
$attributeId = $this->getAttribute()->getId();
$attributeTable = $this->getAttribute()->getBackend()->getTable();
$linkField = $this->getAttribute()->getEntity()->getLinkField();

if ($this->getAttribute()->isScopeGlobal()) {
$tableName = $attributeCode . '_t';
$collection->getSelect()->joinLeft(
[$tableName => $attributeTable],
"e.entity_id={$tableName}.entity_id" .
"e.{$linkField}={$tableName}.{$linkField}" .
" AND {$tableName}.attribute_id='{$attributeId}'" .
" AND {$tableName}.store_id='0'",
[]
Expand All @@ -227,13 +228,13 @@ public function addValueSortToCollection($collection, $dir = 'asc')
$valueTable2 = $attributeCode . '_t2';
$collection->getSelect()->joinLeft(
[$valueTable1 => $attributeTable],
"e.entity_id={$valueTable1}.entity_id" .
"e.{$linkField}={$valueTable1}.{$linkField}" .
" AND {$valueTable1}.attribute_id='{$attributeId}'" .
" AND {$valueTable1}.store_id='0'",
[]
)->joinLeft(
[$valueTable2 => $attributeTable],
"e.entity_id={$valueTable2}.entity_id" .
"e.{$linkField}={$valueTable2}.{$linkField}" .
" AND {$valueTable2}.attribute_id='{$attributeId}'" .
" AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
[]
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/Setup/CategorySetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ public function getDefaultEntities()
'sort_order' => 9,
'visible' => true,
'group' => 'General',
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
],
'options_container' => [
'type' => 'varchar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Edit\Tab;

use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;

class AdvancedTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down Expand Up @@ -42,6 +44,11 @@ class AdvancedTest extends \PHPUnit_Framework_TestCase
*/
protected $filesystem;

/**
* @var PropertyLocker|\PHPUnit_Framework_MockObject_MockObject
*/
protected $propertyLocker;

protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand All @@ -51,6 +58,7 @@ protected function setUp()
$this->localeDate = $this->getMock('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
$this->eavData = $this->getMock('Magento\Eav\Helper\Data', [], [], '', false);
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
$this->propertyLocker = $this->getMock(PropertyLocker::class, [], [], '', false);

$this->block = $objectManager->getObject(
'Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Advanced',
Expand All @@ -60,7 +68,8 @@ protected function setUp()
'localeDate' => $this->localeDate,
'yesNo' => $this->yesNo,
'eavData' => $this->eavData,
'filesystem' => $this->filesystem
'filesystem' => $this->filesystem,
'propertyLocker' => $this->propertyLocker,
]
);
}
Expand Down Expand Up @@ -93,6 +102,7 @@ public function testToHtml()
$this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']);
$this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface);
$directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path');
$this->propertyLocker->expects($this->once())->method('lock')->with($form);

$this->block->setData(['action' => 'save']);
$this->block->toHtml();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Source;

use Magento\Eav\Model\Entity\AbstractEntity;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class StatusTest extends \PHPUnit_Framework_TestCase
Expand All @@ -27,6 +28,11 @@ class StatusTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend|\PHPUnit_Framework_MockObject_MockObject */
protected $backendAttributeModel;

/**
* @var AbstractEntity|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entity;

protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
Expand All @@ -53,6 +59,7 @@ protected function setUp()
'getBackend',
'getId',
'isScopeGlobal',
'getEntity',
],
[],
'',
Expand All @@ -78,6 +85,11 @@ protected function setUp()
->will($this->returnSelf());
$this->backendAttributeModel->expects($this->any())->method('getTable')
->will($this->returnValue('table_name'));

$this->entity = $this->getMockBuilder(AbstractEntity::class)
->disableOriginalConstructor()
->setMethods(['getLinkField'])
->getMockForAbstractClass();
}

public function testAddValueSortToCollectionGlobal()
Expand All @@ -87,6 +99,9 @@ public function testAddValueSortToCollectionGlobal()
$this->collection->expects($this->once())->method('order')->with('attribute_code_t.value asc')
->will($this->returnSelf());

$this->attributeModel->expects($this->once())->method('getEntity')->willReturn($this->entity);
$this->entity->expects($this->once())->method('getLinkField')->willReturn('entity_id');

$this->status->setAttribute($this->attributeModel);
$this->status->addValueSortToCollection($this->collection);
}
Expand All @@ -105,6 +120,9 @@ public function testAddValueSortToCollectionNotGlobal()
$this->collection->expects($this->any())->method('getCheckSql')
->will($this->returnValue('check_sql'));

$this->attributeModel->expects($this->any())->method('getEntity')->willReturn($this->entity);
$this->entity->expects($this->once())->method('getLinkField')->willReturn('entity_id');

$this->status->setAttribute($this->attributeModel);
$this->status->addValueSortToCollection($this->collection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AddWebsitesFieldToCollection implements AddFieldToCollectionInterface
*/
public function addField(Collection $collection, $field, $alias = null)
{
$collection->addWebsiteNamesToResult();
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection->addWebsiteNamesToResult();
}
}
1 change: 0 additions & 1 deletion app/code/Magento/Catalog/etc/catalog_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<attribute name="default_sort_by" />
<attribute name="filter_price_range" />
<attribute name="image" />
<attribute name="category_ids" />
<attribute name="media_gallery_content" />
<attribute name="tier_price" />
<attribute name="gift_message_available" />
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/eav_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<attribute code="category_ids">
<field code="is_searchable" locked="true" />
<field code="used_for_sort_by" locked="true" />
<field code="is_used_in_grid" locked="true" />
<field code="is_visible_in_grid" locked="true" />
<field code="is_filterable_in_grid" locked="true" />
</attribute>
<attribute code="media_gallery">
<field code="is_searchable" locked="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ public function addValueSortToCollection($collection, $dir = \Magento\Framework\
$attributeCode = $this->getAttribute()->getAttributeCode();
$attributeId = $this->getAttribute()->getId();
$attributeTable = $this->getAttribute()->getBackend()->getTable();
$linkField = $this->getAttribute()->getEntity()->getLinkField();

if ($this->getAttribute()->isScopeGlobal()) {
$tableName = $attributeCode . '_t';
$collection->getSelect()
->joinLeft(
[$tableName => $attributeTable],
"e.entity_id={$tableName}.entity_id"
"e.{$linkField}={$tableName}.{$linkField}"
. " AND {$tableName}.attribute_id='{$attributeId}'"
. " AND {$tableName}.store_id='0'",
[]
Expand All @@ -173,14 +174,14 @@ public function addValueSortToCollection($collection, $dir = \Magento\Framework\
$collection->getSelect()
->joinLeft(
[$valueTable1 => $attributeTable],
"e.entity_id={$valueTable1}.entity_id"
"e.{$linkField}={$valueTable1}.{$linkField}"
. " AND {$valueTable1}.attribute_id='{$attributeId}'"
. " AND {$valueTable1}.store_id='0'",
[]
)
->joinLeft(
[$valueTable2 => $attributeTable],
"e.entity_id={$valueTable2}.entity_id"
"e.{$linkField}={$valueTable2}.{$linkField}"
. " AND {$valueTable2}.attribute_id='{$attributeId}'"
. " AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Eav\Test\Unit\Model\Entity\Attribute\Source;

use Magento\Eav\Model\Entity\AbstractEntity;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class BooleanTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -67,6 +68,13 @@ public function testAddValueSortToCollection(
$attributeMock = $this->getAttributeMock();
$attributeMock->expects($this->any())->method('isScopeGlobal')->will($this->returnValue($isScopeGlobal));

$entity = $this->getMockBuilder(AbstractEntity::class)
->disableOriginalConstructor()
->setMethods(['getLinkField'])
->getMockForAbstractClass();
$entity->expects($this->once())->method('getLinkField')->willReturn('entity_id');
$attributeMock->expects($this->once())->method('getEntity')->willReturn($entity);

$selectMock = $this->getMock('\Magento\Framework\DB\Select', [], [], '', false);

$collectionMock = $this->getCollectionMock();
Expand Down Expand Up @@ -173,7 +181,7 @@ protected function getCollectionMock()
*/
protected function getAttributeMock()
{
$attributeMockMethods = ['getAttributeCode', 'getId', 'getBackend', 'isScopeGlobal', '__wakeup'];
$attributeMockMethods = ['getAttributeCode', 'getId', 'getBackend', 'isScopeGlobal', '__wakeup' , 'getEntity'];
$attributeMock = $this->getMock(
'\Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $attributeMockMethods, [], '', false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ define([
*/
_OnChange: function ($this, $widget) {
var $parent = $this.parents('.' + $widget.options.classes.attributeClass),
$input = $parent.find('.' + $widget.options.classes.attributeInput);
attributeId = $parent.attr('attribute-id'),
$input = $widget.productForm.find(
'.' + $widget.options.classes.attributeInput + '[name="super_attribute[' + attributeId + ']"]'
);

if ($this.val() > 0) {
$parent.attr('option-selected', $this.val());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ public function testPricesSegmentation($categoryId, array $entityIds, array $int
['entityMetadata' => $entityMetadata]
);

/** @var \Magento\Framework\Search\Document[] $documents */
/** @var \Magento\Framework\Api\Search\Document[] $documents */
$documents = [];
foreach ($entityIds as $entityId) {
$rawDocument = [
[
'name' => $idKey,
'value' => $entityId,
],
[
'name' => 'score',
'value' => 1,
],
$idKey => $entityId,
'score' => 1,
];
$documents[] = $documentFactory->create($rawDocument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function assertProductIds($queryResponse, $expectedIds)
{
$actualIds = [];
foreach ($queryResponse as $document) {
/** @var \Magento\Framework\Search\Document $document */
/** @var \Magento\Framework\Api\Search\Document $document */
$actualIds[] = $document->getId();
}
sort($actualIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4223,4 +4223,6 @@
['Magento\Braintree\Test\Unit\Observer\ProcessBraintreePaymentTest'],
['Magento\Catalog\Model\Webapi\Product\Option\Type\File\Validator'],
['Magento\Catalog\Test\Unit\Webapi\Product\Option\Type\File\ValidatorTest'],
['Magento\Framework\Search\Document', 'Magento\Framework\Api\Search\Document'],
['Magento\Framework\Search\DocumentField'],
];
Loading

0 comments on commit 26630f7

Please sign in to comment.