Category Archives: Magento

magento 2 unable to unserialize value

Open the file \vendor\magento\framework\Serialize\Serializer\json.php and replace the function unserialize() with the below

public function unserialize($string) {
/* Added the following if clause to resolve the issue */
if($this->is_serialized($string)){
$string = $this->serialize($string);
}
$result = json_decode($string, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Unable to unserialize value.');
}
return $result;
}

Also add the following function as well

function is_serialized($value, &$result = null) {
// Bit of a give away this one
if (!is_string($value))
{
return false;
}
// Serialized false, return true. unserialize() returns false on an
// invalid string or it could return false if the string is serialized
// false, eliminate that possibility.
if ($value === 'b:0;')
{
$result = false;
return true;
}
$length = strlen($value);
$end = '';
switch ($value[0])
{
case 's':
if ($value[$length - 2] !== '"')
{
return false;
}
case 'b':
case 'i':
case 'd':
// This looks odd but it is quicker than isset()ing
$end .= ';';
case 'a':
case 'O':
$end .= '}';
if ($value[1] !== ':')
{
return false;
}
switch ($value[2])
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return false;
}
case 'N':
$end .= ';';
if ($value[$length - 1] !== $end[0])
{
return false;
}
break;
default:
return false;
}
if (($result = @unserialize($value)) === false)
{
$result = null;
return false;
}
return true;
}

Magento 2: setup upgrade error “We can’t find the role for the user you wanted”

open the file
vendor/magento/module-authorization/Model/Acl/AclRetriever.php and replaced the below code

if (!$role) {
throw new AuthorizationException(
__('We can\'t find the role for the user you wanted.')
);
}
$allowedResources = $this->getAllowedResourcesByRole($role->getId());

with

if (!$role) {
$allowedResources = array();
}

and revert it on sucess.

magento setup upgrade Unexpected error. Unable to create oAuth consumer account.

I have encountered this issue while community to enterprise migration and it was happening since the base table ‘oauth_consumer‘ was not available.

CREATE TABLE oauth_consumer (   entity_id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
updated_at timestamp NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
name varchar(255) NOT NULL COMMENT 'Name of consumer',
key varchar(32) NOT NULL COMMENT 'Key code',
secret varchar(32) NOT NULL COMMENT 'Secret code',
callback_url text COMMENT 'Callback URL',
rejected_callback_url text NOT NULL COMMENT 'Rejected callback URL',
PRIMARY KEY (entity_id),
UNIQUE KEY OAUTH_CONSUMER_KEY (key),
UNIQUE KEY OAUTH_CONSUMER_SECRET (secret),
KEY OAUTH_CONSUMER_CREATED_AT (created_at),
KEY OAUTH_CONSUMER_UPDATED_AT (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='OAuth Consumers';

Magento 2 Requested store is not found

This issue can be fixed by issuing the following queries

UPDATE store SET store_id = 0 WHERE code='admin';
UPDATE store_group SET group_id = 0 WHERE name='Default';
UPDATE store_website SET website_id = 0 WHERE code='admin';

It can also be solved by modify StoreManager.php (/vendor/magento/module-store/Model/StoreManager.php)

If $storeId is not defined: It retrive data from COOKIE first, otherwise return the default store code.

if (!isset($storeId) || '' === $storeId || $storeId === true) {
if (null === $this->currentStoreId) {
\Magento\Framework\Profiler::start('store.resolve');
$this->currentStoreId = $this->storeResolver->getCurrentStoreId(); \Magento\Framework\Profiler::stop('store.resolve');
}
$storeId = $this->currentStoreId;
}

To

if(!$storeId) {
if(isset($_COOKIE['store']) && $_COOKIE['store'] !== ''){
$storeId = $_COOKIE['store'];
} else {
$storeId = $this->getDefaultStoreView()->getCode();
}
}

Magento 2 css not working

I have fixed the issue by modifying option in config Stores>Configuration -> Advanced -> Developer ->Sign Static Files (dev_static_sign) -> No.

As the admin panel was not accessible I made this change at DB level.

insert into core_config_data (config_id, scope, scope_id, path, value) values (null, 'default', 0, 'dev/static/sign', 0);

Simple product with custom options and configurable products

The custom option variants can not be managed in the inventry.

You can not controll if there are various custom options like color, size etc.

You have limited options like only few colors. Where as in configurable products huge number of product variation is possible.

You can not sell custom option variant separately.

It is easy to create product with custom options compare to configurable products.