Magento2
Power your online business with the most flexible and scalable ecommerce platform
Get random result from collection in magento 2
The best way is to use "orderRand()", so after you build your collection you can use this sets
$result= $collection->setPageSize(3)->getSelect()->orderRand();
the $result will contain three random result from your collection
Not getting correct label value of yes or no (Boolean) type attribute
I'm currently experiencing issues with the Boolean type attribute labels in the aggregations data of the products GraphQL response. If you're also facing this problem, please use the following workaround until it's resolved in the upcoming version.
https://github.com/magento/magento2/commit/09be7f8dfee335ec2a19553ff813c3160497a6e6
Magento2 - Get Quote Id from hashed graphql ID
In this wiki, we will write the code to get the entity id from hashed id for Magento2 Quote
protected $maskedQuoteIdToQuoteId;
public function __construct(
\Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
) {
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
}
then you can call execute function
$cartHash = "6zIMBpw1NSixrw8BpUzIMHOvAR9ZopYW";
$cartId = $this->maskedQuoteIdToQuoteId>execute($cartHash);
Magento 2 optimize the queue consumers
If you're experiencing issues with Magento 2 cron jobs getting stuck or running for a long time, there are ways to optimize how Magento handles the queue consumers.
By default, consumers will keep polling for messages as long as the number of processed messages is less than the max_messages value, which can be specified in the env.php file. However, this approach is typically recommended for larger merchants where a constant flow of messages is expected.
Converting CMS Page Content or any Custom content to HTML in Magento 2?
in the below example we will show how to convert the content to HTML in Magento2
Magento2 Framwork to deal with files/directories
To work with files in Magento2 you should follow the Framework rules, below are set of command we can use for each PHP command
Configure CodeSniffer in phpstorm for Magento2?
in this wiki, we will configure Magento 2 code standard and code styling
First, we will configure Code Sniffer for Magento2
Disable inline edit in ui listing in Magento2
to disable inline editing in UI listing grid in Magento2 please go to this file
Error after upgrading Magento to latest version
Sometime when you upgrade Magento to latest version you will have this error in the console
check all Magento 2 versions available to install via Composer
to check all available versions of Magneto you can use this command
Magento Open Source:
composer show magento/product-community-edition --all | grep -m 1 versions
Magento Commerce:
composer show magento/product-enterprise-edition --all | grep -m 1 versions