Skip to content

Commit

Permalink
Merge branch 'main' into sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Nov 29, 2024
2 parents e000dea + bcf0e84 commit 3c87e61
Show file tree
Hide file tree
Showing 21 changed files with 636 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
false,
false,
false,
false,
true,
false,
false,
false,
Expand Down
4 changes: 2 additions & 2 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public static function run($code = '', $type = 'store', $options = [])
*
* @param array $options
*/
protected static function _setIsInstalled($options = [])
private static function _setIsInstalled($options = [])
{
if (isset($options['is_installed']) && $options['is_installed']) {
self::$_isInstalled = true;
Expand All @@ -793,7 +793,7 @@ protected static function _setIsInstalled($options = [])
*
* @param array $options
*/
protected static function _setConfigModel($options = [])
private static function _setConfigModel($options = [])
{
if (isset($options['config_model']) && class_exists($options['config_model'])) {
$alternativeConfigModelName = $options['config_model'];
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function save($product = null)

$selection['selection_id'] = $selectionModel->getSelectionId();

if ($selectionModel->getSelectionId()) {
if ($selectionModel->getSelectionId() && !$selectionModel->isDeleted()) {
$excludeSelectionIds[] = $selectionModel->getSelectionId();
$usedProductIds[] = $selectionModel->getProductId();
}
Expand Down
22 changes: 20 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class Mage_Catalog_Helper_Product_Url extends Mage_Core_Helper_Url
'צ' => 'c', 'ק' => 'q', 'ר' => 'r', 'ש' => 'w', 'ת' => 't', '' => 'tm',
];

protected array $_convertTableShort = ['@' => 'at', '©' => 'c', '®' => 'r', '' => 'tm'];

protected array $_convertTableCustom = [];

/**
* Check additional instruction for conversion table in configuration
*/
Expand All @@ -93,7 +97,9 @@ public function __construct()
$convertNode = Mage::getConfig()->getNode('default/url/convert');
if ($convertNode) {
foreach ($convertNode->children() as $node) {
$this->_convertTable[(string) $node->from] = (string) $node->to;
if (property_exists($node, 'from') && property_exists($node, 'to')) {
$this->_convertTableCustom[(string) $node->from] = (string) $node->to;
}
}
}
}
Expand All @@ -105,14 +111,26 @@ public function __construct()
*/
public function getConvertTable()
{
return $this->_convertTable;
return $this->_convertTable + $this->_convertTableShort + $this->_convertTableCustom;
}

public function getConvertTableCustom(): array
{
return $this->_convertTableCustom;
}

public function getConvertTableShort(): array
{
return $this->_convertTableShort + $this->_convertTableCustom;
}

/**
* Process string based on conversion table
*
* @param string $string
* @return string
* @deprecated
* @see Mage_Catalog_Model_Url::formatUrlKey()
*/
public function format($string)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function beforeSave($object)
$urlKey = $object->getName();
}

if (method_exists($object, 'setLocale')) {
$locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $object->getStoreId());
$object->setLocale($locale);
}

$object->setData($attributeName, $object->formatUrlKey($urlKey));

return $this;
Expand Down
25 changes: 18 additions & 7 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class Mage_Catalog_Model_Category extends Mage_Catalog_Model_Abstract
*/
protected $_urlModel;


protected ?string $locale = null;

/**
* Initialize resource mode
*/
Expand Down Expand Up @@ -501,9 +504,10 @@ public function getUrlModel()
public function getCategoryIdUrl()
{
Varien_Profiler::start('REGULAR: ' . __METHOD__);
$urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->formatUrlKey($this->getName());
$locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $this->getStoreId());
$urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->setLocale($locale)->formatUrlKey($this->getName());
$url = $this->getUrlInstance()->getUrl('catalog/category/view', [
's' => $urlKey,
's' => $urlKey,
'id' => $this->getId(),
]);
Varien_Profiler::stop('REGULAR: ' . __METHOD__);
Expand All @@ -518,11 +522,18 @@ public function getCategoryIdUrl()
*/
public function formatUrlKey($str)
{
$str = Mage::helper('catalog/product_url')->format($str);
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', $str);
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');
return $urlKey;
return $this->getUrlModel()->setLocale($this->getLocale())->formatUrlKey($str);
}

public function getLocale(): ?string
{
return $this->locale;
}

public function setLocale(?string $locale)
{
$this->locale = $locale;
return $this;
}

/**
Expand Down
53 changes: 2 additions & 51 deletions app/code/core/Mage/Catalog/Model/Category/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,13 @@
*/

/**
* Catalog category url
* Catalog Url model
*
* @category Mage
* @package Mage_Catalog
*/
class Mage_Catalog_Model_Category_Url
class Mage_Catalog_Model_Category_Url extends Mage_Catalog_Model_Url
{
/**
* Url instance
*
* @var Mage_Core_Model_Url
*/
protected $_url;

/**
* Factory instance
*
* @var Mage_Catalog_Model_Factory
*/
protected $_factory;

/**
* Url rewrite instance
*
* @var Mage_Core_Model_Url_Rewrite
*/
protected $_urlRewrite;

/**
* Initialize Url model
*/
Expand Down Expand Up @@ -113,32 +92,4 @@ protected function _getRequestPath(Mage_Catalog_Model_Category $category)
}
return false;
}

/**
* Retrieve Url instance
*
* @return Mage_Core_Model_Url
*/
public function getUrlInstance()
{
if ($this->_url === null) {
/** @var Mage_Core_Model_Url $model */
$model = $this->_factory->getModel('core/url');
$this->_url = $model;
}
return $this->_url;
}

/**
* Retrieve Url rewrite instance
*
* @return Mage_Core_Model_Url_Rewrite
*/
public function getUrlRewrite()
{
if ($this->_urlRewrite === null) {
$this->_urlRewrite = $this->_factory->getUrlRewriteInstance();
}
return $this->_urlRewrite;
}
}
15 changes: 14 additions & 1 deletion app/code/core/Mage/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
*/
protected $_reviewSummary = [];

protected ?string $locale = null;

/**
* Initialize resources
*/
Expand Down Expand Up @@ -1681,7 +1683,18 @@ public function getUrlInStore($params = [])
*/
public function formatUrlKey($str)
{
return $this->getUrlModel()->formatUrlKey($str);
return $this->getUrlModel()->setLocale($this->getLocale())->formatUrlKey($str);
}

public function getLocale(): ?string
{
return $this->locale;
}

public function setLocale(?string $locale)
{
$this->locale = $locale;
return $this;
}

/**
Expand Down
65 changes: 1 addition & 64 deletions app/code/core/Mage/Catalog/Model/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,10 @@
* @category Mage
* @package Mage_Catalog
*/
class Mage_Catalog_Model_Product_Url extends Varien_Object
class Mage_Catalog_Model_Product_Url extends Mage_Catalog_Model_Url
{
public const CACHE_TAG = 'url_rewrite';

/**
* URL instance
*
* @var Mage_Core_Model_Url
*/
protected $_url;

/**
* URL Rewrite Instance
*
* @var Mage_Core_Model_Url_Rewrite
*/
protected $_urlRewrite;

/**
* Factory instance
*
* @var Mage_Catalog_Model_Factory
*/
protected $_factory;

/**
* @var Mage_Core_Model_Store
*/
Expand All @@ -59,32 +38,6 @@ public function __construct(array $args = [])
$this->_store = !empty($args['store']) ? $args['store'] : Mage::app()->getStore();
}

/**
* Retrieve URL Instance
*
* @return Mage_Core_Model_Url
*/
public function getUrlInstance()
{
if ($this->_url === null) {
$this->_url = Mage::getModel('core/url');
}
return $this->_url;
}

/**
* Retrieve URL Rewrite Instance
*
* @return Mage_Core_Model_Url_Rewrite
*/
public function getUrlRewrite()
{
if ($this->_urlRewrite === null) {
$this->_urlRewrite = $this->_factory->getUrlRewriteInstance();
}
return $this->_urlRewrite;
}

/**
* 'no_selection' shouldn't be a valid image attribute value
*
Expand Down Expand Up @@ -132,21 +85,6 @@ public function getProductUrl($product, $useSid = null)
return $this->getUrl($product, $params);
}

/**
* Format Key for URL
*
* @param string $str
* @return string
*/
public function formatUrlKey($str)
{
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');

return $urlKey;
}

/**
* Retrieve Product Url path (with category if exists)
*
Expand Down Expand Up @@ -281,7 +219,6 @@ protected function _getRequestPath($product, $categoryId)
if ($rewrite->getId()) {
return $rewrite->getRequestPath();
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function beforeSave($object)
$urlKey = $object->getName();
}

if (method_exists($object, 'setLocale')) {
$locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $object->getStoreId());
$object->setLocale($locale);
}
$object->setData($attributeName, $object->formatUrlKey($urlKey));

return $this;
Expand Down
Loading

0 comments on commit 3c87e61

Please sign in to comment.