Created
May 13, 2020 17:16
-
-
Save NazarenkoDenis/056deb3b34cbafb84a86d5c88c6c5d1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Mirasvit | |
* Path: /html/app/code/local/Mirasvit/Advr/Helper/ | |
* This source file is subject to the Mirasvit Software License, which is available at https://mirasvit.com/license/. | |
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future. | |
* If you wish to customize this module for your needs. | |
* Please refer to http://www.magentocommerce.com for more information. | |
* | |
* @category Mirasvit | |
* @package mirasvit/extension_advr | |
* @version 1.2.12 | |
* @copyright Copyright (C) 2019 Mirasvit (https://mirasvit.com/) | |
*/ | |
class Mirasvit_Advr_Helper_Data extends Mage_Core_Helper_Abstract | |
{ | |
protected $variables = array(); | |
public function setVariable($key, $value) | |
{ | |
$variable = Mage::getModel('core/variable'); | |
$variable = $variable->loadByCode('advr_' . $key); | |
$value = serialize($value); | |
$variable->setPlainValue($value) | |
->setHtmlValue(Mage::getSingleton('core/date')->gmtTimestamp()) | |
->setName($key) | |
->setCode('advr_' . $key) | |
->save(); | |
return $variable; | |
} | |
public function getVariable($key, $force = false) | |
{ | |
if ($force || !isset($this->variables[$key])) { | |
$variable = Mage::getModel('core/variable')->loadByCode('advr_' . $key); | |
$this->variables[$key] = unserialize($variable->getPlainValue()); | |
} | |
return $this->variables[$key]; | |
} | |
public function saveCache($key, $value) | |
{ | |
$value = serialize($value); | |
Mage::app()->saveCache($value, 'advr_' . $key, array('CONFIG'), 100000000); | |
return $this; | |
} | |
public function loadCache($key) | |
{ | |
$value = Mage::app()->loadCache('advr_' . $key); | |
if ($value !== false) { | |
$value = unserialize($value); | |
} | |
return $value; | |
} | |
public function getAttributeOptionHash($attrCode) | |
{ | |
$options = $this->loadCache($attrCode); | |
if ($options === false) { | |
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attrCode); | |
$options = array(); | |
if ($attribute && $attribute->usesSource() && $attribute->getFrontendModel() == '' && Mage::getModel($attribute->getSourceModel())) { | |
if (!method_exists($attribute, 'setAttribute')) { | |
return false; | |
} | |
$allOptions = $attribute->getSource()->getAllOptions(false); | |
foreach ($allOptions as $opt) { | |
if (is_scalar($opt['value'])) { | |
$options[$opt['value']] = $opt['label']; | |
} | |
} | |
} | |
$this->saveCache($attrCode, $options); | |
} | |
return $options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment