theme can not be changed in magento 2.2.4 - magento

We have installed a fresh copy of magento 2.2.4 however it is not allowing us to change the theme and throwing the exception "Something went wrong while saving this configuration: Area is already set"

Please make changes given below Magento\Email\Model\AbstractTemplate.php
public function setForcedArea($templateId)
{
if ($this->area) {
throw new \LogicException(__('Area is already set'));
}
$this->area = $this->emailConfig->getTemplateArea($templateId);
return $this;
}
Replace above code with :-
public function setForcedArea($templateId)
{
if (!isset($this->area)) {
$this->area = $this->emailConfig->getTemplateArea($templateId);
}
return $this;
}
Using this code problem will be fixed however it is not a good practice to make changes in vendor files of magento.
You can also update to latest version of magento i.e. magento 2.2.5 onwards to fix this problem

Related

PhpStorm No Usages for get Attribute

I'm using the latest version of PhpStorm (2022.3.1) and Laravel 9+. This is not a huge issue, but rather a major eyesore.
For some reason when I use a Model to create a custom Attribute like this:
public function getFormattedStartDateAttribute(): string
{
if (!$this->start_date) {
return 'TBD';
} else {
return $this->start_date->format('M. d, Y');
}
}
And use in the view like this or this:
Date {{ $event->formattedStartDate }}
Date {{ $event->formatted_start_date }}
PhpStorm still says the method has no usages?
Image:
Is there a way to fix this? I've tried reindexing my project. This is a new feature called Code Vision.
The issue is very easy to solve, you can use barryvdh/laravel-ide-helper and then run php artisan ide:model, that will go over the models and create a PHPDoc block (you can add options and create them in the same model file or in a new file where you only have this PHPDock blocks), and PHPStorm will read this doc block and know when you are calling attributeWhatever is what type.
It will add this in your case:
/**
* #property string $formattedStartDate
*/
This way, any IDE that is capable of understanding PHPDock blocks, will understand that when you do $class->formattedStartDate, you are refering to that one, and it is of type string.
BUT, no IDE (unless using a plugin that I am not aware of) will understand that getFormattedStartDateAttribute -> formattedStartDate, so you will still get no usages for getFormattedStartDateAttribute, but at least you can track formattedStartDate and do whatever you want with it.
One quick tip, if you are using Laravel 9+, please change that code from:
public function getFormattedStartDateAttribute(): string
{
if (!$this->start_date) {
return 'TBD';
} else {
return $this->start_date->format('M. d, Y');
}
}
To:
public function formattedStartDate(): \Illuminate\Database\Eloquent\Casts\Attribute
{
return Attribute::get(
function ($value, $attributes) {
if (! $attributes['start_date']) {
return 'TBD';
} else {
return $attributes['start_date']->format('M. d, Y');
}
}
);
}
Why? Because using getFormattedStartDateAttribute is the old way, Laravel 9+ made it easier, read about Accessors.
See that getXXXXAttribute and setXXXXAttribute is not even present on the documentation anymore.

Laravel Voyager BREAD Image Edit and Delete Issue

I have ran into a problem with image upload using voyager BREAD System. If I delete or update an image using BREAD the old image not replaced or deleted. It is still in the storage directory. I was using latest version of voyager with laravel 5.5. Is there any solution to this problem? Thank you in advance.
There is no public function deleteBreadImages($data, $rows) {...} anymore in Laravel Voyager 1.2 class file vendor/tcg/voyager/src/http/controllers/VoyagerBreadController.php
After two days of googling same issue I figured out the Hard Solution...
in my case image field name is img and model name is Company
code is executed while the Model BREAD is updating
Works on Voyager 1.2
Hope it helps ))
use Storage;
class Company extends Model
{
public static function boot()
{
parent::boot();
static::updating(function($model)
{
// Check if Old File Exists
$oldFileExists = Storage::disk('public')->exists($model->original['img']);
// If Old File Exists DELETE it, else Continue Adding New Image
if($oldFileExists)
{
//Get File Extension:: .jpg .png .gif
$fileExt = substr(strrchr($model->original['img'], "."), 0);
//If File is not .GIF
if($fileExt != '.gif'){
// Delete Old Non-GIF Image
Storage::disk('public')->delete($model->original['img']);
}
// Find .gif , -static.gif Old Images And Delete
else{
// filename-static.gif
$staticOld = str_replace($fileExt,"-static".$fileExt,$model->original['img']);
// Delete Old Image.gif
Storage::disk('public')->delete($model->original['img']);
// Delete Old Image-static .gif if Exists
if($staticOld) Storage::disk('public')->delete($staticOld);
}
}
});
}
}
Hey please check below file in your project's vendor/tcg/voyager/src/http/controllers/VoyagerBreadController.php directory
and check for this
public function deleteBreadImages($data, $rows) {...}
function at line number 403.
in this function find $this->deleteFileIfExists($data->{$row->field}); make it un-comment and check.
may i hope this helps you

Error when adding SOAP/XML-RPC users and roles

I tried to upgrade Magento 1.9.0.1 to 1.9.1 via the Magento Connect facility and it seems to have stopped me being able to add users and roles for API access.
Here's the error:
Invalid method Mage_Admin_Model_User::validateCurrentPassword(Array
Has anyone ever come across this?
this issues can be solve
1) open the file app/code/core/Mage/Adminhtml/Controller/Action.php
2) After that see the function on line number 395 and comment the internel code into this.
protected function _validateCurrentPassword($password){
/*$user = Mage::getSingleton('admin/session')->getUser();
return $user->validateCurrentPassword($password);*/
}
I recently came across this same issue after upgrading Magento to a newer version of 1.9.
It should be noted that you should never modify core files, and the password validation should not necessarily be removed.
In my personal case, I restored the original function to the core file, however, you could just as easily extend the Mage_Admin_Model_User class.
The version of the function I used can be found below.
/**
* Validate password against current user password
* Returns true or array of errors.
*
* #return mixed
*/
public function validateCurrentPassword($password)
{
$result = array();
if (!Zend_Validate::is($password, 'NotEmpty')) {
$result[] = $this->_getHelper('adminhtml')->__('Current password field cannot be empty.');
} elseif (is_null($this->getId()) || !$this->_getHelper('core')->validateHash($password, $this->getPassword())){
$result[] = $this->_getHelper('adminhtml')->__('Invalid current password.');
}
if (empty($result)) {
$result = true;
}
return $result;
}

Magento - many of same cache requests

today I realized that the Magento doest a lot of same requests to my memcached server, it's requesting the key Zend_LocaleC_en_GB_currencynumber_ . Do you anyone know where is it generated and how can I improve it? It's probably somehow related to rendering of price box but I dont see reason why it's 50 times in a page. Thanks, Jaro.
Edited:
So far I did quick fix
Zend_Cache_Backend_Memcached::load
public function load($id, $doNotTestCacheValidity = false)
{
if ( isset($GLOBALS[$id]) ) {
return $GLOBALS[$id];
}
$tmp = $this->_memcache->get($id);
if (is_array($tmp) && isset($tmp[0])) {
$GLOBALS[$id] = $tmp[0];
return $tmp[0];
}
return false;
}
It's not nice but seems to be working. At least many of requests agains memcached server disappeared. Jaro.
It is one of the known issues in Zend Framework community. It even was reported as an improvement for 1.0.3 release (http://framework.zend.com/issues/browse/ZF-2311).
You fix make sense for Magento where a lot of calls to Zend_Currency is performed and connection to memcached having some limitations or slow enough.
For instance on most of the projects we are using memcached and haven't experienced too big loss in page load time with this calls.
However you can fix it in Magento to make a workaround with ZF:
Rewrite core/locale model in your module
Override currency() method
public function currency($currency)
{
if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) {
$currencyObject = parent::currency($currency);
$currencyObject->setFormat(array(
'format' => Zend_Locale_Data::getContent($this->getLocale(), 'currencynumber')
));
return $currencyObject;
}
return parent::currency($currency);
}

Magento on Wamp Not Showing Administrator Permissions

i am working on local system on WAMPSERVER 2.0 and I am installing the magento 1.6.2.0 and when i go to the System -> Permissions -> Roles and click on Administrators I got page broken screen. I have tried to change the max execution time, memory limit in php.ini etc but nothing works.
Please help me out.
Thanks
I made changes in the file app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Search function getRowUrl in the file.
public function getRowUrl($item)
{
$res = parent::getRowUrl($item);
return ($res ? $res : '#');
}
Replace this function with below function:
public function getRowUrl($item)
{
$res = parent::getUrl($item);
return ($res ? $res : '#');
}
It worked for me and resolved my issue. I know its not good to made changes in core files but i was working on local system and was stuck for this.
Regards,
Hanan Ali

Resources