Skip to content

Commit 12e38a3

Browse files
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-49101
2 parents 5d411b2 + 53a52ec commit 12e38a3

File tree

19 files changed

+597
-34
lines changed

19 files changed

+597
-34
lines changed

app/code/Magento/CatalogRule/Model/CatalogRuleRepository.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\NoSuchEntityException;
1010
use Magento\Framework\Exception\CouldNotDeleteException;
1111
use Magento\Framework\Exception\CouldNotSaveException;
12+
use \Magento\Framework\Exception\ValidatorException;
1213

1314
class CatalogRuleRepository implements \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface
1415
{
@@ -51,7 +52,10 @@ public function save(Data\RuleInterface $rule)
5152
try {
5253
$this->ruleResource->save($rule);
5354
unset($this->rules[$rule->getId()]);
54-
} catch (\Exception $e) {
55+
} catch (ValidatorException $e) {
56+
throw new CouldNotSaveException(__($e->getMessage()));
57+
}
58+
catch (\Exception $e) {
5559
throw new CouldNotSaveException(__('Unable to save rule %1', $rule->getRuleId()));
5660
}
5761
return $rule;
@@ -63,7 +67,7 @@ public function save(Data\RuleInterface $rule)
6367
public function get($ruleId)
6468
{
6569
if (!isset($this->rules[$ruleId])) {
66-
/** @var \Magento\CatalogRule\Model\RuleFactory $rule */
70+
/** @var \Magento\CatalogRule\Model\Rule $rule */
6771
$rule = $this->ruleFactory->create();
6872

6973
/* TODO: change to resource model after entity manager will be fixed */
@@ -84,6 +88,8 @@ public function delete(Data\RuleInterface $rule)
8488
try {
8589
$this->ruleResource->delete($rule);
8690
unset($this->rules[$rule->getId()]);
91+
} catch (ValidatorException $e) {
92+
throw new CouldNotSaveException(__($e->getMessage()));
8793
} catch (\Exception $e) {
8894
throw new CouldNotDeleteException(__('Unable to remove rule %1', $rule->getRuleId()));
8995
}

app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,28 +287,31 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
287287
}
288288

289289
/**
290-
* Delete the object
291-
*
292-
* @param \Magento\Framework\Model\AbstractModel $object
290+
* @param AbstractModel $object
293291
* @return $this
294292
* @throws \Exception
295293
*/
296-
public function delete(AbstractModel $object)
294+
public function delete(\Magento\Framework\Model\AbstractModel $object)
297295
{
296+
//TODO: add object relation processor support (MAGETWO-49297)
298297
$this->transactionManager->start($this->getConnection());
299298
try {
300299
$object->beforeDelete();
301300
$this->_beforeDelete($object);
302-
$this->entityManager->delete('Magento\CatalogRule\Api\Data\RuleInterface', $object);
301+
$this->entityManager->delete(
302+
'Magento\CatalogRule\Api\Data\RuleInterface',
303+
$object
304+
);
303305
$this->_afterDelete($object);
304306
$object->isDeleted(true);
305307
$object->afterDelete();
306308
$this->transactionManager->commit();
307309
$object->afterDeleteCommit();
308-
} catch (\Exception $exception) {
310+
} catch (\Exception $e) {
309311
$this->transactionManager->rollBack();
310-
throw $exception;
312+
throw $e;
311313
}
314+
312315
return $this;
313316
}
314317
}

app/code/Magento/Cms/Model/Wysiwyg/Config.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Model\Wysiwyg;
77

8+
use Magento\Framework\Filesystem;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
810
use Magento\Ui\Component\Wysiwyg\ConfigInterface;
911

1012
/**
@@ -91,6 +93,11 @@ class Config extends \Magento\Framework\DataObject implements ConfigInterface
9193
*/
9294
protected $_storeManager;
9395

96+
/**
97+
* @var Filesystem
98+
*/
99+
protected $filesystem;
100+
94101
/**
95102
* @param \Magento\Backend\Model\UrlInterface $backendUrl
96103
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -100,6 +107,7 @@ class Config extends \Magento\Framework\DataObject implements ConfigInterface
100107
* @param \Magento\Widget\Model\Widget\Config $widgetConfig
101108
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
102109
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
110+
* @param Filesystem $filesystem
103111
* @param array $windowSize
104112
* @param array $data
105113
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -113,6 +121,7 @@ public function __construct(
113121
\Magento\Widget\Model\Widget\Config $widgetConfig,
114122
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
115123
\Magento\Store\Model\StoreManagerInterface $storeManager,
124+
Filesystem $filesystem,
116125
array $windowSize = [],
117126
array $data = []
118127
) {
@@ -125,6 +134,7 @@ public function __construct(
125134
$this->_widgetConfig = $widgetConfig;
126135
$this->_windowSize = $windowSize;
127136
$this->_storeManager = $storeManager;
137+
$this->filesystem = $filesystem;
128138
parent::__construct($data);
129139
}
130140

@@ -157,6 +167,9 @@ public function getConfig($data = [])
157167
'add_widgets' => true,
158168
'no_display' => false,
159169
'encode_directives' => true,
170+
'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(),
171+
'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl())
172+
. $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/',
160173
'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'),
161174
'popup_css' => $this->_assetRepo->getUrl(
162175
'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/ConfigTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* @covers \Magento\Cms\Model\Wysiwyg\Config
10+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1011
*/
1112
class ConfigTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -60,13 +61,19 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
6061
*/
6162
protected $assetFileMock;
6263

64+
/**
65+
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
protected $filesystemMock;
68+
6369
/**
6470
* @var array
6571
*/
6672
protected $windowSize = [];
6773

6874
protected function setUp()
6975
{
76+
$this->filesystemMock = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
7077
$this->backendUrlMock = $this->getMockBuilder('Magento\Backend\Model\UrlInterface')
7178
->disableOriginalConstructor()
7279
->getMock();
@@ -110,7 +117,8 @@ protected function setUp()
110117
'widgetConfig' => $this->widgetConfigMock,
111118
'scopeConfig' => $this->scopeConfigMock,
112119
'windowSize' => $this->windowSize,
113-
'storeManager' => $this->storeManagerMock
120+
'storeManager' => $this->storeManagerMock,
121+
'filesystem' => $this->filesystemMock,
114122
]
115123
);
116124
}
@@ -139,12 +147,26 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
139147
['cms/wysiwyg/directive'],
140148
['cms/wysiwyg_images/index']
141149
);
150+
$this->backendUrlMock->expects($this->once())
151+
->method('getBaseUrl')
152+
->willReturn('localhost/index.php/');
142153
$this->assetRepoMock->expects($this->atLeastOnce())
143154
->method('getUrl')
144155
->withConsecutive(
145156
['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'],
146157
['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css']
147158
);
159+
$this->filesystemMock->expects($this->once())
160+
->method('getUri')
161+
->willReturn('pub/static');
162+
/** @var \Magento\Framework\View\Asset\ContextInterface|\PHPUnit_Framework_MockObject_MockObject $contextMock */
163+
$contextMock = $this->getMock(\Magento\Framework\View\Asset\ContextInterface::class);
164+
$contextMock->expects($this->once())
165+
->method('getBaseUrl')
166+
->willReturn('localhost/pub/static/');
167+
$this->assetRepoMock->expects($this->once())
168+
->method('getStaticViewFileContext')
169+
->willReturn($contextMock);
148170
$this->authorizationMock->expects($this->atLeastOnce())
149171
->method('isAllowed')
150172
->with('Magento_Cms::media_gallery')
@@ -161,6 +183,8 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
161183
$this->assertEquals($expectedResults[0], $config->getData('someData'));
162184
$this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
163185
$this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
186+
$this->assertEquals('localhost/pub/static/', $config->getData('baseStaticUrl'));
187+
$this->assertEquals('localhost/pub/static/', $config->getData('baseStaticDefaultUrl'));
164188
}
165189

166190
public function getConfigDataProvider()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Block\Plugin\Product\Media;
7+
8+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
9+
10+
/**
11+
* Class Gallery
12+
*/
13+
class Gallery extends \Magento\Catalog\Block\Product\View\AbstractView
14+
{
15+
/**
16+
* @var \Magento\Catalog\Model\Product\Gallery\ReadHandler
17+
*/
18+
private $productGalleryReadHandler;
19+
20+
/**
21+
* @var \Magento\Framework\Json\EncoderInterface
22+
*/
23+
private $jsonEncoder;
24+
25+
/**
26+
* @var \Magento\Framework\Json\DecoderInterface
27+
*/
28+
private $jsonDecoder;
29+
30+
/**
31+
* Gallery constructor.
32+
* @param \Magento\Catalog\Block\Product\Context $context
33+
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
34+
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $productGalleryReadHandler
35+
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
36+
* @param \Magento\Framework\Json\DecoderInterface $jsonDecoder
37+
* @param array $data
38+
*/
39+
public function __construct(
40+
\Magento\Catalog\Block\Product\Context $context,
41+
\Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
42+
\Magento\Catalog\Model\Product\Gallery\ReadHandler $productGalleryReadHandler,
43+
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
44+
\Magento\Framework\Json\DecoderInterface $jsonDecoder,
45+
array $data = []
46+
) {
47+
$this->productGalleryReadHandler = $productGalleryReadHandler;
48+
$this->jsonEncoder = $jsonEncoder;
49+
$this->jsonDecoder = $jsonDecoder;
50+
parent::__construct($context, $arrayUtils, $data);
51+
}
52+
53+
/**
54+
* @param \Magento\Catalog\Block\Product\View\Gallery $subject
55+
* @param string $result
56+
* @return string
57+
*
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function afterGetOptionsMediaGalleryDataJson(
61+
\Magento\Catalog\Block\Product\View\Gallery $subject,
62+
$result
63+
) {
64+
$result = $this->jsonDecoder->decode($result);
65+
if ($this->getProduct()->getTypeId() == 'configurable') {
66+
/** @var Configurable $productType */
67+
$productType = $this->getProduct()->getTypeInstance();
68+
$products = $productType->getUsedProducts($this->getProduct());
69+
$attributes = $productType->getConfigurableAttributesAsArray($this->getProduct());
70+
/** @var \Magento\Catalog\Model\Product $product */
71+
foreach ($attributes as $attribute) {
72+
foreach ($products as $product) {
73+
$attributeValue = $product->getData($attribute['attribute_code']);
74+
if ($attributeValue) {
75+
$key = $attribute['attribute_code'] . '_' . $attributeValue;
76+
$result[$key] = $this->getProductGallery($product);
77+
}
78+
}
79+
}
80+
}
81+
return $this->jsonEncoder->encode($result);
82+
}
83+
84+
/**
85+
* @param \Magento\Catalog\Model\Product $product
86+
* @return array
87+
*/
88+
private function getProductGallery($product)
89+
{
90+
$result = [];
91+
$this->productGalleryReadHandler->execute('', $product);
92+
$images = $product->getMediaGalleryImages();
93+
foreach ($images as $image) {
94+
$result[] = [
95+
'mediaType' => $image->getMediaType(),
96+
'videoUrl' => $image->getVideoUrl(),
97+
'isBase' => $product->getImage() == $image->getFile(),
98+
];
99+
}
100+
return $result;
101+
}
102+
}

0 commit comments

Comments
 (0)