Skip to content

Commit b1a01af

Browse files
committed
Merge remote-tracking branch 'origin/product-video-PR4' into BugFestW4
2 parents 00d4476 + 740034e commit b1a01af

File tree

43 files changed

+1147
-1337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1147
-1337
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Attribute/Backend/Media.php

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -298,42 +298,30 @@ public function deleteGalleryValueInStore($valueId, $entityId, $storeId)
298298
* @param array $newFiles
299299
* @param int $originalProductId
300300
* @param int $newProductId
301-
* @return $this
301+
* @return array
302302
*/
303303
public function duplicate($attributeId, $newFiles, $originalProductId, $newProductId)
304304
{
305-
$mainTableAlias = $this->getMainTableAlias();
305+
$mediaGalleryEntities = $this->loadMediaGalleryEntities($attributeId, $originalProductId);
306306

307-
$select = $this->getConnection()->select()->from(
308-
[$mainTableAlias => $this->getMainTable()],
309-
['value_id', 'value']
310-
)->joinInner(
311-
['entity' => $this->getTable(self::GALLERY_VALUE_TO_ENTITY_TABLE)],
312-
$mainTableAlias . '.value_id = entity.value_id',
313-
['entity_id' => 'entity_id']
314-
)->where(
315-
'attribute_id = ?',
316-
$attributeId
317-
)->where(
318-
'entity.entity_id = ?',
319-
$originalProductId
320-
);
321-
322-
$valueIdMap = [];
323307
// Duplicate main entries of gallery
324-
foreach ($this->getConnection()->fetchAll($select) as $row) {
308+
$valueIdMap = [];
309+
foreach ($mediaGalleryEntities as $row) {
310+
$valueId = $row['value_id'];
325311
$data = [
326312
'attribute_id' => $attributeId,
327-
'value' => isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value'],
313+
'media_type' => $row['media_type'],
314+
'disabled' => $row['disabled'],
315+
'value' => isset($newFiles[$valueId]) ? $newFiles[$valueId] : $row['value'],
328316
];
317+
$valueIdMap[$valueId] = $this->insertGallery($data);
318+
$this->bindValueToEntity($valueIdMap[$valueId], $newProductId);
319+
}
329320

330-
$valueIdMap[$row['value_id']] = $this->insertGallery($data);
331-
$this->bindValueToEntity($valueIdMap[$row['value_id']], $newProductId);
332321

333-
}
334322

335323
if (count($valueIdMap) == 0) {
336-
return $this;
324+
return [];
337325
}
338326

339327
// Duplicate per store gallery values
@@ -345,12 +333,55 @@ public function duplicate($attributeId, $newFiles, $originalProductId, $newProdu
345333
);
346334

347335
foreach ($this->getConnection()->fetchAll($select) as $row) {
348-
unset($row['record_id']);
349-
$row['entity_id'] = $newProductId;
350336
$row['value_id'] = $valueIdMap[$row['value_id']];
337+
unset($row['record_id']);
351338
$this->insertGalleryValueInStore($row);
339+
$this->bindValueToEntity($row['value_id'], $newProductId);
352340
}
353341

354-
return $this;
342+
return $valueIdMap;
343+
}
344+
345+
/**
346+
* @param array $valueIds
347+
* @return array
348+
* @throws \Magento\Framework\Exception\LocalizedException
349+
*/
350+
public function loadMediaGalleryEntitiesbyId($valueIds)
351+
{
352+
$select = $this->getConnection()->select()->from(
353+
$this->getMainTable()
354+
)->where(
355+
'value_id IN(?)',
356+
$valueIds
357+
);
358+
359+
return $this->getConnection()->fetchAll($select);
360+
}
361+
362+
/**
363+
* @param int $attributeId
364+
* @param int $productId
365+
* @return array
366+
* @throws \Magento\Framework\Exception\LocalizedException
367+
*/
368+
public function loadMediaGalleryEntities($attributeId, $productId)
369+
{
370+
$mainTableAlias = $this->getMainTableAlias();
371+
$select = $this->getConnection()->select()->from(
372+
[$mainTableAlias => $this->getMainTable()]
373+
)->joinInner(
374+
['entity' => $this->getTable(self::GALLERY_VALUE_TO_ENTITY_TABLE)],
375+
$mainTableAlias . '.value_id = entity.value_id',
376+
['entity_id' => 'entity_id']
377+
)->where(
378+
'attribute_id = ?',
379+
$attributeId
380+
)->where(
381+
'entity.entity_id = ?',
382+
$productId
383+
);
384+
385+
return $this->getConnection()->fetchAll($select);
355386
}
356387
}

app/code/Magento/Catalog/Setup/UpgradeData.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@ public function __construct(CategorySetupFactory $categorySetupFactory)
4040
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4141
{
4242
$setup->startSetup();
43-
if (version_compare($context->getVersion(), '2.0.1') < 0) {
44-
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
45-
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
46-
47-
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
48-
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
49-
50-
$attributeGroup = $categorySetup->getAttributeGroup(
51-
$entityTypeId,
52-
$attributeSetId,
53-
'Images',
54-
'attribute_group_name'
55-
);
56-
if (isset($attributeGroup['attribute_group_name']) && $attributeGroup['attribute_group_name'] == 'Images') {
57-
// update General Group
58-
$categorySetup->updateAttributeGroup(
59-
$entityTypeId,
60-
$attributeSetId,
61-
$attributeGroup['attribute_group_id'],
62-
'attribute_group_name',
63-
'Images and Videos'
64-
);
65-
}
66-
}
67-
6843
if ($context->getVersion()
6944
&& version_compare($context->getVersion(), '2.0.1') < 0
7045
) {

app/code/Magento/Catalog/view/adminhtml/web/catalog/base-image-uploader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ define([
3838

3939
var findElement = function (data) {
4040
return $container.find('.image:not(.image-placeholder)').filter(function () {
41-
if(!$(this).data('image')) {
41+
if (!$(this).data('image')) {
4242
return false;
4343
}
4444
return $(this).data('image').file === data.file;

app/code/Magento/Catalog/view/adminhtml/web/catalog/category/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define([
2020

2121
var params = {};
2222
var fields = $('category_edit_form').getElementsBySelector('input', 'select');
23-
for(var i=0;i<fields.length;i++){
23+
for (var i=0; i<fields.length; i++) {
2424
if (!fields[i].name) {
2525
continue;
2626
}

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/composite/configure.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,9 @@ define([
703703
mageData.scripts.map(function(script) {
704704
return eval(script);
705705
});
706-
} catch (e) {}
706+
} catch (e) {
707+
708+
}
707709
this.restorePhase = false;
708710
}
709711
break;

app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ define([
301301
* @private
302302
*/
303303
_onOpenDialog: function(e, imageData) {
304-
if(imageData.media_type && imageData.media_type != 'image') {
304+
if (imageData.media_type && imageData.media_type != 'image') {
305305
return;
306306
}
307307
this._showDialog(imageData);
@@ -315,7 +315,7 @@ define([
315315
_showDialog: function (imageData) {
316316
var $imageContainer = this.findElement(imageData);
317317
var dialogElement = $imageContainer.data('dialog');
318-
if(!this.dialogTmpl) {
318+
if (!this.dialogTmpl) {
319319
alert('System problem!');
320320
return;
321321
}

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ define([
4646

4747
submitForm: function(form) {
4848
var self = this;
49-
if (form.has('input[type="file"]').length && form.find('input[type="file"]').val() !== '') {
49+
if (form.has('input[type="file"]').length && form.find('input[type="file"]').val() !== '') {
5050
self.element.off('submit');
5151
form.submit();
5252
} else {

app/code/Magento/ProductVideo/Block/Adminhtml/Product/Edit/NewVideo.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,45 @@
1212
*/
1313
class NewVideo extends \Magento\Backend\Block\Widget\Form\Generic
1414
{
15+
/**
16+
* Anchor is product video
17+
*/
18+
const PATH_ANCHOR_PRODUCT_VIDEO = 'catalog_product_video-link';
19+
1520
/**
1621
* @var \Magento\ProductVideo\Helper\Media
1722
*/
1823
protected $mediaHelper;
1924

25+
/**
26+
* @var \Magento\Framework\UrlInterface
27+
*/
28+
protected $urlBuilder;
29+
2030
/**
2131
* @var \Magento\Framework\Json\EncoderInterface
2232
*/
2333
protected $jsonEncoder;
2434

2535
/**
2636
* @param \Magento\Backend\Block\Template\Context $context
27-
* @param \Magento\ProductVideo\Helper\Media $mediaHelper
28-
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
2937
* @param \Magento\Framework\Registry $registry
3038
* @param \Magento\Framework\Data\FormFactory $formFactory
39+
* @param \Magento\ProductVideo\Helper\Media $mediaHelper
40+
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
3141
* @param array $data
3242
*/
3343
public function __construct(
3444
\Magento\Backend\Block\Template\Context $context,
3545
\Magento\Framework\Registry $registry,
3646
\Magento\Framework\Data\FormFactory $formFactory,
37-
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
3847
\Magento\ProductVideo\Helper\Media $mediaHelper,
48+
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
3949
array $data = []
4050
) {
4151
parent::__construct($context, $registry, $formFactory, $data);
4252
$this->mediaHelper = $mediaHelper;
53+
$this->urlBuilder = $context->getUrlBuilder();
4354
$this->jsonEncoder = $jsonEncoder;
4455
$this->setUseContainer(true);
4556
}
@@ -104,7 +115,8 @@ protected function _prepareForm()
104115
'title' => __('Url'),
105116
'required' => true,
106117
'name' => 'video_url',
107-
'note' => 'Youtube or Vimeo supported',
118+
'note' => $this->getNoteVideoUrl(),
119+
108120
]
109121
);
110122

@@ -158,7 +170,7 @@ protected function _prepareForm()
158170
'label' => '',
159171
'title' => __('Get Video Information'),
160172
'name' => 'new_video_get',
161-
'value' => 'Get Video Information',
173+
'value' => __('Get Video Information'),
162174
'class' => 'action-default'
163175
]
164176
);
@@ -248,4 +260,38 @@ protected function addMediaRoleAttributes(Fieldset $fieldset)
248260
}
249261
return $this;
250262
}
263+
264+
/**
265+
* Get note for video url
266+
*
267+
* @return \Magento\Framework\Phrase
268+
*/
269+
protected function getNoteVideoUrl()
270+
{
271+
$result = __('YouTube and Vimeo supported.');
272+
if ($this->mediaHelper->getYouTubeApiKey() === null) {
273+
$result = __(
274+
'Vimeo supported.<br />'
275+
. 'To add YouTube video, please <a href="%1">enter YouTube API Key</a> first.',
276+
$this->getConfigApiKeyUrl()
277+
);
278+
}
279+
return $result;
280+
}
281+
282+
/**
283+
* Get url for config params
284+
*
285+
* @return string
286+
*/
287+
protected function getConfigApiKeyUrl()
288+
{
289+
return $this->urlBuilder->getUrl(
290+
'adminhtml/system_config/edit',
291+
[
292+
'section' => 'catalog',
293+
'_fragment' => self::PATH_ANCHOR_PRODUCT_VIDEO
294+
]
295+
);
296+
}
251297
}

0 commit comments

Comments
 (0)