Skip to content

Commit

Permalink
Merge branch 'main' into fix-Mage_Core_Controller_Front_Router-geturl
Browse files Browse the repository at this point in the history
  • Loading branch information
kiatng authored Nov 18, 2024
2 parents d4609a6 + f39a667 commit 48c80ba
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 77 deletions.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs.openmage.org
2 changes: 1 addition & 1 deletion app/code/core/Mage/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getFeedXml()
$data = $this->getFeedData();
$xml = new SimpleXMLElement($data);
} catch (Exception $e) {
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?>');
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><feed />');
}

return $xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function getFormHtml(Varien_Object $entity, $entityType = 'quote')
*/
public function getItems()
{
if (!$this->isOutputEnabled('Mage_GiftMessage')) {
return false;
}

/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');

Expand All @@ -51,7 +55,7 @@ public function getItems()

foreach ($allItems as $item) {
if ($this->_getGiftmessageSaveModel()->getIsAllowedQuoteItem($item)
&& $helper->getIsMessagesAvailable('item', $item, $this->getStore())
&& $helper->getIsMessagesAvailable($helper::TYPE_ITEM, $item, $this->getStore())
) {
// if item allowed
$items[] = $item;
Expand Down Expand Up @@ -82,6 +86,6 @@ public function canDisplayGiftmessage(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getEntity(), $this->getEntity()->getStoreId());
return $helper->getIsMessagesAvailable($helper::TYPE_CONFIG, $this->getQuote(), $this->getStoreId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public function isGiftMessagesAvailable($item = null)
$helper = $this->helper('giftmessage/message');

if (is_null($item)) {
return $helper->getIsMessagesAvailable('items', $this->getQuote(), $this->getStore());
return $helper->getIsMessagesAvailable($helper::TYPE_ITEMS, $this->getQuote(), $this->getStore());
}

return $helper->getIsMessagesAvailable('item', $item, $this->getStore());
return $helper->getIsMessagesAvailable($helper::TYPE_ITEM, $item, $this->getStore());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function render(Varien_Object $row)
{
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
if (!$helper->getIsMessagesAvailable('order_item', $row, $this->getColumn()->getGrid()->getStore())) {
if (!$helper->getIsMessagesAvailable($helper::TYPE_ORDER_ITEM, $row, $this->getColumn()->getGrid()->getStore())) {
return '&nbsp;';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@ public function canDisplayGiftmessage()
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getEntity(), $this->getEntity()->getStoreId());
return $helper->getIsMessagesAvailable($helper::TYPE_ORDER, $this->getEntity(), $this->getEntity()->getStoreId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function canDisplayGiftmessage()
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable(
'order_item',
$helper::TYPE_ORDER_ITEM,
$this->getItem(),
$this->getItem()->getOrder()->getStoreId()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Mage_GiftMessage_Block_Adminhtml_Product_Helper_Form_Config extends Mage_A
/**
* Get config value data
*
* @return mixed
* @return bool
*/
protected function _getValueFromConfig()
{
return Mage::getStoreConfig(Mage_GiftMessage_Helper_Message::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS);
return Mage::getStoreConfigFlag(Mage_GiftMessage_Helper_Message::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function canDisplayGiftmessageForm()
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
return $helper->getIsMessagesAvailable('items', $quote, $quote->getStore());
return $helper->getIsMessagesAvailable($helper::TYPE_ITEMS, $quote, $quote->getStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function canDisplayGiftMessage()
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable(
'item',
$helper::TYPE_ITEM,
$item,
$item->getStoreId()
);
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/GiftMessage/Block/Message/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public function getEscaped($value, $defaultValue = '')
*/
public function isMessagesAvailable()
{
return Mage::helper('giftmessage/message')->isMessagesAvailable('quote', $this->getEntity());
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->isMessagesAvailable($helper::TYPE_CONFIG, $this->getEntity());
}

/**
Expand Down
118 changes: 63 additions & 55 deletions app/code/core/Mage/GiftMessage/Helper/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class Mage_GiftMessage_Helper_Message extends Mage_Core_Helper_Data
public const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS = 'sales/gift_options/allow_items';
public const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER = 'sales/gift_options/allow_order';

public const TYPE_ADDRESS_ITEM = 'address_item';
public const TYPE_CONFIG = 'config';
public const TYPE_ITEM = 'item';
public const TYPE_ITEMS = 'items';
public const TYPE_ORDER = 'order';
public const TYPE_ORDER_ITEM = 'order_item';

protected $_moduleName = 'Mage_GiftMessage';

/**
Expand Down Expand Up @@ -88,74 +95,75 @@ public function getInline($type, Varien_Object $entity, $dontDisplayContainer =
/**
* Check availability of giftmessages for specified entity.
*
* @param string $type
* @param Mage_Core_Model_Store|integer $store
* @return bool|int
* @param self::TYPE_* $type $type
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return bool
*/
public function isMessagesAvailable($type, Varien_Object $entity, $store = null)
{
if ($type == 'items') {
$items = $entity->getAllItems();
if (!is_array($items) || empty($items)) {
return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
}
if ($entity instanceof Mage_Sales_Model_Quote) {
$_type = $entity->getIsMultiShipping() ? 'address_item' : 'item';
} else {
$_type = 'order_item';
}

foreach ($items as $item) {
if ($item->getParentItem()) {
continue;
switch ($type) {
case self::TYPE_ITEMS:
$items = $entity->getAllItems();
if (!is_array($items) || empty($items)) {
return Mage::getStoreConfigFlag(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
}
if ($this->isMessagesAvailable($_type, $item, $store)) {
return true;
if ($entity instanceof Mage_Sales_Model_Quote) {
$_type = $entity->getIsMultiShipping() ? self::TYPE_ADDRESS_ITEM : self::TYPE_ITEM;
} else {
$_type = self::TYPE_ORDER_ITEM;
}
}
} elseif ($type == 'item') {
return $this->_getDependenceFromStoreConfig(
$entity->getProduct()->getGiftMessageAvailable(),
$store
);
} elseif ($type == 'order_item') {
return $this->_getDependenceFromStoreConfig(
$entity->getGiftMessageAvailable(),
$store
);
} elseif ($type == 'address_item') {
$storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId();

if (!$this->isCached('address_item_' . $entity->getProductId())) {
$this->setCached(
'address_item_' . $entity->getProductId(),
Mage::getModel('catalog/product')
->setStoreId($storeId)
->load($entity->getProductId())
->getGiftMessageAvailable()
foreach ($items as $item) {
if ($item->getParentItem()) {
continue;
}
if ($this->isMessagesAvailable($_type, $item, $store)) {
return true;
}
}
// no break
case self::TYPE_ITEM:
return $this->_getDependenceFromStoreConfig(
$entity->getProduct()->getGiftMessageAvailable(),
$store
);
}
return $this->_getDependenceFromStoreConfig(
$this->getCached('address_item_' . $entity->getProductId()),
$store
);
} else {
return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store);
}
case self::TYPE_ORDER_ITEM:
return $this->_getDependenceFromStoreConfig(
$entity->getGiftMessageAvailable(),
$store
);
case self::TYPE_ADDRESS_ITEM:
$storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId();
$cacheId = self::TYPE_ADDRESS_ITEM . '_' . $entity->getProductId();

return false;
if (!$this->isCached($cacheId)) {
$this->setCached(
$cacheId,
Mage::getModel('catalog/product')
->setStoreId($storeId)
->load($entity->getProductId())
->getGiftMessageAvailable()
);
}
return $this->_getDependenceFromStoreConfig(
$this->getCached($cacheId),
$store
);
default:
return Mage::getStoreConfigFlag(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store);
}
}

/**
* Check availability of gift messages from store config if flag eq 2.
*
* @param int $productGiftMessageAllow
* @param Mage_Core_Model_Store|integer $store
* @return bool|int
* @param bool $productGiftMessageAllow
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return bool
*/
protected function _getDependenceFromStoreConfig($productGiftMessageAllow, $store = null)
{
$result = Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
$result = Mage::getStoreConfigFlag(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
if ($productGiftMessageAllow === '' || is_null($productGiftMessageAllow)) {
return $result;
} else {
Expand All @@ -166,9 +174,9 @@ protected function _getDependenceFromStoreConfig($productGiftMessageAllow, $stor
/**
* Alias for isMessagesAvailable(...)
*
* @param string $type
* @param Mage_Core_Model_Store|integer $store
* @return bool|int
* @param self::TYPE_* $type
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return bool
*/
public function getIsMessagesAvailable($type, Varien_Object $entity, $store = null)
{
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Install/etc/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<mcrypt/>
</mcrypt>
<pdo/>
<pdo_mysql/>
<simplexml/>
<soap/>
<spl/>
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Sales/Block/Order/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public function canDisplayGiftmessage(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getOrder());
return $helper->getIsMessagesAvailable($helper::TYPE_ORDER, $this->getOrder());
}
}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Sales/Block/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public function canDisplayGiftmessage(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getOrder());
return $helper->getIsMessagesAvailable($helper::TYPE_ORDER, $this->getOrder());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ public function canDisplayGiftmessage(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order_item', $this->getOrderItem()) && $this->getItem()->getGiftMessageId();
return $helper->getIsMessagesAvailable(
$helper::TYPE_ORDER_ITEM,
$this->getOrderItem()
) && $this->getItem()->getGiftMessageId();
}

public function getGiftMessage(): ?Mage_GiftMessage_Model_Message
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Sales/Block/Order/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function canDisplayGiftmessage(Mage_Sales_Model_Order_Item $item): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order_item', $item) && $item->getGiftMessageId();
return $helper->getIsMessagesAvailable($helper::TYPE_ORDER_ITEM, $item) && $item->getGiftMessageId();
}
}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Sales/Block/Order/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public function canDisplayGiftmessage(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getOrder());
return $helper->getIsMessagesAvailable($helper::TYPE_ORDER, $this->getOrder());
}
}
7 changes: 5 additions & 2 deletions app/code/core/Mage/Sales/Block/Order/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function canDisplayGiftmessageItems(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('items', $this->getOrder());
return $helper->getIsMessagesAvailable($helper::TYPE_ITEMS, $this->getOrder());
}

public function canDisplayGiftmessageOrder(): bool
Expand All @@ -136,6 +136,9 @@ public function canDisplayGiftmessageOrder(): bool
}
/** @var Mage_GiftMessage_Helper_Message $helper */
$helper = $this->helper('giftmessage/message');
return $helper->getIsMessagesAvailable('order', $this->getOrder()) && $this->getOrder()->getGiftMessageId();
return $helper->getIsMessagesAvailable(
$helper::TYPE_ORDER,
$this->getOrder()
) && $this->getOrder()->getGiftMessageId();
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-pdo_mysql": "*",
"ext-simplexml": "*",
"ext-soap": "*",
"ext-zlib": "*",
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/unit/Mage/Downloadable/Helper/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function setUp(): void
* @dataProvider provideGetFilePathData
*
* @group Mage_Downloadable
* @group Mage_Downloadable_Helper
*/
public function testGetFilePath(string $expectedResult, string $path, ?string $file): void
{
Expand Down
Loading

0 comments on commit 48c80ba

Please sign in to comment.