Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/booleanAnd.rightNotBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
'count' => 1,
'path' => __DIR__ . '/../app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in &&, int|string|null given on the right side.',
'count' => 1,
'path' => __DIR__ . '/../app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in &&, int|string|null given on the right side.',
'count' => 1,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/booleanNot.exprNotBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@
'count' => 1,
'path' => __DIR__ . '/../app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in a negated boolean, mixed given.',
'count' => 2,
'path' => __DIR__ . '/../app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in a negated boolean, Varien_Data_Form_Element_Abstract|null given.',
'count' => 1,
Expand Down
2 changes: 2 additions & 0 deletions app/OpenMageVersionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,6 @@ interface OpenMageVersionInterface
public const VERSION_20_17_0 = '20.17.0';

public const VERSION_20_18_0 = '20.18.0';

public const VERSION_20_19_0 = '20.19.0';
}
177 changes: 77 additions & 100 deletions app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,130 +12,102 @@
*
* @package Mage_Adminhtml
*/
class Mage_Adminhtml_Block_Catalog_Product_Edit extends Mage_Adminhtml_Block_Widget
class Mage_Adminhtml_Block_Catalog_Product_Edit extends Mage_Adminhtml_Block_Widget_Container
{
public function __construct()

Check failure on line 17 in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=OpenMage_magento-lts&issues=AZ6ITCfPVPa98KNy1aDe&open=AZ6ITCfPVPa98KNy1aDe&pullRequest=5624
{
parent::__construct();
$this->setTemplate('catalog/product/edit.phtml');
$this->setId('product_edit');
}

/**
* Retrieve currently edited product object
*
* @return Mage_Catalog_Model_Product
*/
public function getProduct()
{
return Mage::registry('current_product');
}

/**
* @inheritDoc
*/
#[Override]
protected function _prepareLayout()
{
if (!$this->getRequest()->getParam('popup')) {
$this->setChild(
'back_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Back'),
'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/', ['store' => $this->getRequest()->getParam('store', 0)])),
'class' => 'back',
]),
);
} else {
$this->setChild(
'back_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Close Window'),
'onclick' => 'window.close()',
'class' => 'cancel',
]),
);
$isConfigured = $this->getIsConfigured();
$isReadOnly = $this->getProduct()->isReadonly();
$isPopup = (bool) $this->getRequest()->getParam('popup');
$isProductId = (bool) $this->getProductId();
$isProductSetId = (bool) $this->getProductSetId();

if ($isPopup) {
$this->_addButton(self::BUTTON_TYPE_CLOSE, [
'label' => Mage::helper('catalog')->__('Close Window'),
'onclick' => 'window.close()',
'class' => 'cancel',
], -1);
}

if (!$this->getProduct()->isReadonly()) {
$this->setChild(
'reset_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Reset'),
'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/*', ['_current' => true])),
'class' => 'reset',
]),
);

$this->setChild(
'save_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Save'),
'onclick' => 'productForm.submit()',
'class' => 'save',
]),
);
if (!$isPopup) {
$this->_addButton(self::BUTTON_TYPE_BACK, [
'label' => Mage::helper('catalog')->__('Back'),
'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/', ['store' => $this->getRequest()->getParam('store', 0)])),
'class' => 'back',
], -1);
}

if (!$this->getRequest()->getParam('popup')) {
if (!$this->getProduct()->isReadonly()) {
$this->setChild(
'save_and_edit_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Save and Continue Edit'),
'onclick' => Mage::helper('core/js')->getSaveAndContinueEditJs($this->getSaveAndContinueUrl()),
'class' => 'save continue',
]),
);
}
if (!$isReadOnly) {
$this->_addButton(self::BUTTON_TYPE_RESET, [
'label' => Mage::helper('catalog')->__('Reset'),
'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/*', ['_current' => true])),
'class' => 'reset',
], -1);
}

if ($this->getProduct()->isDeleteable()) {
$this->setChild(
'delete_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Delete'),
'onclick' => Mage::helper('core/js')->getConfirmSetLocationJs($this->getDeleteUrl()),
'class' => 'delete',
]),
);
}
if (!$isPopup && $isProductId && $this->getProduct()->isDeleteable()) {
$this->_addButton(self::BUTTON_TYPE_DELETE, [
'label' => Mage::helper('catalog')->__('Delete'),
'onclick' => Mage::helper('core/js')->getConfirmSetLocationJs($this->getDeleteUrl()),
'class' => 'delete',
]);
}

if ($this->getProduct()->isDuplicable() && $this->getProduct()->getId()) {
if ($this->getProduct()->getMediaGalleryImages()->count() === 0) {
$onClickAction = Mage::helper('core/js')->getSetLocationJs($this->getDuplicateUrl(true));
} else {
$skipImgOnDuplicate = $this->helper('catalog/image')->skipProductImageOnDuplicate();
$onClickAction = "openDuplicateDialog('" . $this->getDuplicateUrl(false) . "','" . $this->getDuplicateUrl(true) . "'); return false;";
if (!$isPopup && $isProductId && $isConfigured && $this->getProduct()->isDuplicable()) {
if ($this->getProduct()->getMediaGalleryImages()->count() === 0) {
$onClickAction = Mage::helper('core/js')->getSetLocationJs($this->getDuplicateUrl(true));
} else {
$skipImgOnDuplicate = $this->helper('catalog/image')->skipProductImageOnDuplicate();
$onClickAction = "openDuplicateDialog('" . $this->getDuplicateUrl(false) . "','" . $this->getDuplicateUrl(true) . "'); return false;";

if ($skipImgOnDuplicate !== Mage_Catalog_Model_Product_Image::ON_DUPLICATE_ASK) {
$onClickAction = Mage::helper('core/js')->getSetLocationJs($this->getDuplicateUrl((bool) $skipImgOnDuplicate));
}
if ($skipImgOnDuplicate !== Mage_Catalog_Model_Product_Image::ON_DUPLICATE_ASK) {
$onClickAction = Mage::helper('core/js')->getSetLocationJs($this->getDuplicateUrl((bool) $skipImgOnDuplicate));
}
}

$this->setChild(
'duplicate_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('catalog')->__('Duplicate'),
'onclick' => $onClickAction,
'class' => 'add duplicate',
]),
);
$this->_addButton(self::BUTTON_TYPE_DUPLICATE, [
'label' => Mage::helper('catalog')->__('Duplicate'),
'onclick' => $onClickAction,
'class' => 'add duplicate',
], 1);
}

if ($isProductSetId && $isConfigured && !$isReadOnly) {
$this->_addButton(self::BUTTON_TYPE_SAVE, [
'label' => Mage::helper('catalog')->__('Save'),
'onclick' => 'productForm.submit()',
'class' => 'save',
], 1);

if (!$isPopup) {
$this->_addButton(self::BUTTON_TYPE_SAVE_EDIT, [
'label' => Mage::helper('catalog')->__('Save and Continue Edit'),
'onclick' => Mage::helper('core/js')->getSaveAndContinueEditJs($this->getSaveAndContinueUrl()),
'class' => 'save continue',
], 1);
}
}
}

return parent::_prepareLayout();
/**
* Retrieve currently edited product object
*
* @return Mage_Catalog_Model_Product
*/
public function getProduct()
{
return Mage::registry('current_product');
}

/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]

Check failure on line 110 in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "Use $this->getButtonsHtml('header')" 6 times.

See more on https://sonarcloud.io/project/issues?id=OpenMage_magento-lts&issues=AZ6ITCfPVPa98KNy1aDf&open=AZ6ITCfPVPa98KNy1aDf&pullRequest=5624
public function getBackButtonHtml()
{
return $this->getChildHtml('back_button');
Expand All @@ -144,6 +116,7 @@
/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]
public function getCancelButtonHtml()
{
return $this->getChildHtml('reset_button');
Expand All @@ -152,6 +125,7 @@
/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]
public function getSaveButtonHtml()
{
return $this->getChildHtml('save_button');
Expand All @@ -160,6 +134,7 @@
/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]
public function getSaveAndEditButtonHtml()
{
return $this->getChildHtml('save_and_edit_button');
Expand All @@ -168,6 +143,7 @@
/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]
public function getDeleteButtonHtml()
{
return $this->getChildHtml('delete_button');
Expand All @@ -176,6 +152,7 @@
/**
* @return string
*/
#[Deprecated(message: 'Use $this->getButtonsHtml(\'header\')', since: OpenMageVersionInterface::VERSION_20_19_0)]
public function getDuplicateButtonHtml()
{
return $this->getChildHtml('duplicate_button');
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Adminhtml/Block/Widget/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Mage_Adminhtml_Block_Widget_Container extends Mage_Adminhtml_Block_Templat

public const BUTTON_TYPE_VOID = 'void';

public const BUTTON_TYPE_DUPLICATE = 'duplicate';

/**
* So-called "container controller" to specify group of blocks participating in some action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@
?>
<div class="content-header">
<h3 class="icon-head head-products"><?php echo $this->getHeader() ?></h3>
<p class="content-buttons form-buttons"><?php echo $this->getBackButtonHtml() ?>
<?php echo $this->getCancelButtonHtml() ?>
<?php if($this->getProductId()): ?>
<?php echo $this->getDeleteButtonHtml() ?>
<?php if($this->getProductSetId() && $this->getIsConfigured()): ?>
<?php echo $this->getDuplicateButtonHtml() ?>
<?php endif ?>
<?php endif ?>
<?php if($this->getProductSetId() && $this->getIsConfigured()): ?>
<?php echo $this->getSaveButtonHtml() ?>
<?php echo $this->getSaveAndEditButtonHtml() ?>
<?php endif ?>
</p>
<p class="content-buttons form-buttons"><?php echo $this->getButtonsHtml('header') ?></p>
</div>
<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="product_edit_form" enctype="multipart/form-data">
<?php echo $this->getBlockHtml('formkey')?>
Expand Down
Loading