[SOLVED] This request requires scope=public_content, but this access token is not authorized with this scope
This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions
If you are getting this error while using Instagram API in Sandbox mode, all you need to do is authorize the scope by going to the below URL. Don’t forget to replace YOUR-CLIENT-ID with your Instagram client ID and YOUR-REDIRECT-URI with your valid redirect URI.
You may also need to authorize basic, comments, follower_list, likes or/and relationships if you are getting any of the below errors.
This request requires scope=comments, but this access token is not authorized with this scope. The user must re-authorize your application with scope=comments to be granted this permissions
This request requires scope=follower_list, but this access token is not authorized with this scope. The user must re-authorize your application with scope=follower_list to be granted this permissions
This request requires scope=likes, but this access token is not authorized with this scope. The user must re-authorize your application with scope=likes to be granted this permissions
This request requires scope=relationships, but this access token is not authorized with this scope. The user must re-authorize your application with scope=relationships to be granted this permissions
To authorize ALL the above scopes at once use below link replacing your client ID and redirect URI:
Magento 2 hello world module in 2 mins!
Create Magento 2 hello world module in 2 minutes!
To create a simple custom module in Magento2 which will give an output on frontend website from your module, follow below steps:
Change to app/code directory where all the Magento2 module lives. Notice there are no codepools (core, community, local) under this directory like it used to be in Magento 1.x
cd app/code |
Create your company name directory
mkdir Hello |
Create you module name directory
mkdir Hello/World |
Create etc directory to hold module config file
mkdir Hello/World/etc |
module.xml file is required only to hold module name and it’s version
vi Hello/World/etc/module.xml |
<?xml version="1.0"?> | |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> | |
<module name="Hello_World" setup_version="0.1.0" /> | |
</config> |
Register your module, this is required in all the modules. Only thing you will change is your module name (Hello_World)
vi Hello/World/registration.php |
<?php | |
\Magento\Framework\Component\ComponentRegistrar::register( | |
\Magento\Framework\Component\ComponentRegistrar::MODULE, | |
'Hello_World', | |
__DIR__ | |
); |
Create frontend directory under etc to define frontend routes. We are creating this because we want to output something on frontend website.
mkdir Hello/World/etc/frontend |
routes.xml is used to give your module a front name. Only thing you will be interested is
vi Hello/World/etc/frontend/routes.xml |
<?xml version="1.0"?> | |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> | |
<router id="standard"> | |
<route id="first" frontName="first"> | |
<module name="Hello_World" /> | |
</route> | |
</router> | |
</config> |
Create Controller directory to hold your module’s controller files
mkdir Hello/World/Controller |
Create your controller directory, this will become part of the url after frontName
mkdir Hello/World/Controller/Hello |
Create controller file, notice there is no controller action in Magento2 Controller. This will again become part of the url and will call execute() method of the class.
vi Hello/World/Controller/Hello/World.php |
<?php | |
namespace Hello\World\Controller\Hello; | |
class World extends \Magento\Framework\App\Action\Action | |
{ | |
public function execute() | |
{ | |
echo 'Hello world!'; | |
} | |
} |
Change directory to reach Magento 2 root directory
cd ../../ |
Enable your module, so an entry will go to app/etc/config.php file and cache will be cleared
bin/magento module:enable Hello_World |
This will add your module with it’s current version to DB table setup_module, without running this command you won’t see the changes of newly created module.
bin/magento setup:upgrade |
Check your module in browser: http://www.yourwebsite.com/first/hello/world. If you have done everything correct, it should output “Hello world!”
Magento get all items in cart
Magento get all the items currently in cart programatically using below code. You can place it anywhere you wish to get information, phtml or php file. Instead of Mage::getSingleton(‘checkout/session’)->getQuote() you can also use Mage::getSingleton(‘checkout/cart’)->getQuote() to get same results. If you want to see what all product information is retrieved you can use $product->getData() inside the foreach loop to display in array format.
$cart = Mage::getSingleton('checkout/session')->getQuote(); | |
//$cart->getAllItems() to get ALL items, parent as well as child, configurable as well as it's simple associated item | |
foreach ($cart->getAllVisibleItems() as $item) { | |
$product = $item->getProduct(); | |
$name = $product->getName(); | |
$sku = $product->getSku(); | |
} |
If you want all the items in collection format, you can call below code instead:
$itemsCollection = Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection(); |
Magento add static block to cms page
You can add static block to CMS page in Magento in following 2 ways:
1.) By adding code in Layout Update XML of CMS page:
<reference name="left"> | |
<block type="cms/block" name="block_name_anything"> | |
<action method="setBlockId"> | |
<block_id>STATIC_BLOCK_ID_HERE</block_id> | |
</action> | |
</block> | |
</reference> |
2.) By putting below code directly into CMS Page content area:
{{block type="cms/block" block_id="STATIC_BLOCK_ID_HERE"}} |
Make sure you flush Blocks HTML Output cache if your changes do not reflect on website.
Magento: Zipcode + 4 tax calculation bug fix
Magento bug fix for zipcode + 4 in tax calculation
Tax Calculation in Magento has a bug where customer can escape paying tax if they enter zipcode + 4 digit in USA. This is because you import 5 digit zipcodes with their tax rates in Magento admin, so if customer inputs their zipcode in zipcode+4 format their zipcode will not match with the imported one. Importing 5-digit zipcode ending in wildcard (*) does not solve this issue either.
Before this fix: If zipcode 90036 collects tax, 90036-1234 does NOT collect tax.
You can fix this bug by adding below code in your custom module:
config.xml
... | |
<global> | |
<models> | |
<tax_resource> | |
<rewrite> | |
<calculation>Namespace_Module_Model_Tax_Resource_Calculation</calculation> | |
</rewrite> | |
</tax_resource> | |
</models> | |
</global> | |
... |
Note that we are rewriting core logic of Tax Calculation. Now create folder structure in your custom module: app/code/local/Namespace/Module/Model/Tax/Resource/Calculation.php and copy below code:
<?php | |
class Namespace_Module_Model_Tax_Resource_Calculation extends Mage_Tax_Model_Resource_Calculation | |
{ | |
protected function _getRates($request) | |
{ | |
$countryId = $request->getCountryId(); | |
$regionId = $request->getRegionId(); | |
$postcode = $request->getPostcode(); | |
//12 = california, 25 = iowa | |
if($countryId == 'US' && in_array($regionId,array(12,25))) { | |
$postcode = substr(trim($request->getPostcode()),0,5); | |
$request->setPostcode($postcode); | |
} | |
return parent::_getRates($request); | |
} | |
} |
Above code will only take first 5 digits from the zipcode if the country is USA and state selected is either California or Iowa. You can change the states as per your requirement, to know what ID relates to different states you can look at the State/Province dropdown source code in checkout page.
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)