Development discussions around Shopify APIs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
Hi I am following https://www.sitepoint.com/shopify-app-development-made-simple/ tutorial.
I have obtained access token and stored it in database after install the app goes to myapp page.
Lets say user has already installed the app and goes to my app . How can I get the shop name in my embedded app so I can get its accesstoken and perform requests.
Since the app already is in iframe and to get access token from database I have to use shop name but how can I get that in iframe ?
You should see a GET request and its parameters. One of the parameters is the shop name.
In the tutorial, it's done in the following line:
1. $query = $_GET;
2. $store = $query['shop'];
So $store is the shop name.
Thanks a lot Felix !
There is no good php api for detailed stuff support is good only for ruby on rails . I had figued this by checking there were iframe parameters but it good to be confident about things from a official person !
Hello Zack,
just as a side note: I'm not an employee or "official person" of shopify.
if (isset($_SERVER['HTTP_REFERER'])) { $referalUrl = $_SERVER['HTTP_REFERER']; $qs = parse_url($referalUrl, PHP_URL_QUERY); if (!empty($qs)) { parse_str($qs, $output); print_r($output); $shop = preg_replace('/.myshopify.com$/', '', $output['shop']); //get store name without fullurl // TODO check for key existence $_SESSION['shop'] = $shop; } }
This code will return shop name everytime you logged in. Hope this will help anyone. This code works for me.
$_SESSION['shop'] = $_GET['shop'];
works for first time only. When you logged in after logout, it doesnot return any value.
Hey so to get the shop if ur using the next.js boilerplate code from shopify-cli
go to pages -> _app.js, u'll get it in the ctx.query object in the getInitialProps method so just return it
MyApp.getInitialProps = async ({ ctx }) => {
return {
host: ctx.query.host,
shop: ctx.query.shop
};
};
now u should be able to access it from props of MyApps class
class MyApp extends App {
render() {
const { Component, pageProps, host, shop } = this.props;
return (
<AppProvider i18n={translations}>
<Provider
config={{
apiKey: API_KEY,
host: host,
forceRedirect: true,
}}
>
<MyProvider Component={Component} shop={shop} {...pageProps} />
</Provider>
</AppProvider>
);
}
}
User | RANK |
---|---|
5 | |
5 | |
4 | |
4 | |
4 |
Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022Shipping can be one of the most vital parts to set up and manage your business. Understand...
By Ollie Dec 16, 2022