Carry get parameter to checkout in Shopify - shopify

If a customer lands on any page of the Shopify site (not Plus), with a referral parameter in GET (?ref=something), how can this value be carried over to the checkout and order confirmation pages, where the domain is different?
One idea I had was to set a cookie on our domain, and then modify URL one navigates to upon clicking Checkout to include the values of the cookies, but I am unsure if this is the cleanest way, and where the best place to modify the URL would be.
I see that _ga parameter appears to be included automatically, in checkout URL. How can this be done for custom GET parameters?

One is the tricky way for doing this by modifying the checkout URL before submitting.
For doing this on your cart.liquid file find the form with action="/cart" and add attribute:
onsubmit="update_action(this)"
And add the javascript code at the bottom of your theme.liquid file :
<script type="text/javascript">
function update_action(form){
var new_action;
var some_value = "something";
var form_action = form.action;
if( (form_action.indexOf("?") >= 0) ) {
if(form_action.indexOf("ref")>=0) {
new_action = form_action.replaceAt(form_action.indexOf("ref"),"ref="+some_value);
}else{
new_action = form_action+"&ref="+some_value;
}
}else{
new_action = form_action+"?ref="+some_value;
}
$(form).attr("action",new_action);
}
</script>
Hope this will solve your problem.

Note that the ref and landing page are automatically stored by Shopify, meaning without you doing anything, you get those values in the order placed by the customer. You do not have manually manipulate them as per this thread.
Why do you need the value on checkout (you can do nothing with it anyway) and why on the order confirmation where again, it serves no purpose for the customer?

Related

Is there a named routes and default params equivalent for Razor Pages page routes?

I have a JobPosts/Index page with multiple GET parameter bindings to allow filtering: let's take CityId and IsRemote for example. I don't want these to be passed as query string parameters, instead I want to use friendly routes for them. So I have defined these:
options.Conventions.AddPageRoute("/JobPosts/Index", "cities/{cityId}/jobs");
options.Conventions.AddPageRoute("/JobPosts/Index", "remote-jobs");
options.Conventions.AddPageRoute("/JobPosts/Index", "jobs");
The routes work just fine when I type them in the browser and the CityId one is bound properly, but two things are missing.
First, there is no way to specify a default value for my IsRemote param, which I want to set to true ONLY when using the remote-jobs URL.
And second, when trying to generate a URL like this:
<a asp-area="" asp-page="/JobPosts/Index" asp-route-cityId="#Model.CityId"></a>
I get the following URL:
https://localhost:44391/jobs?cityId=2265885
When what I actually expect is:
https://localhost:44391/cities/2265885/jobs
So it looks like the tag helper or the part responsible for constructing the URL doesn't look at all at the different routes to try and get a best match based on the list of parameters. Actually, it will always use the last page route defined for that page.
Nor do I have the option anywhere to specify a route name for the page route and then use asp-route to explicitly say which route I want.
Any ideas how to achieve that? Or if it's something that's on the roadmap for Razor Pages?
EDIT: Hardcoding the href is not an option. I want this to go through the proper routing services as there are other things to be done as well, like generating culture-specific URL for non-english users (eg. {cultureId}/cities/{cityId}/jobs - this is done through route conventions. Hardcoding the href would obviously bypass that.
There is a easy way to set IsRemote default value.
public bool IsRemote { get; set; } = true;
This tag asp-page will link to Page /JobPosts/Index.csthml directly,
https://localhost:44391/JobPosts?cityId=2265885
= https://localhost:44391/JobPosts/Index?cityId=2265885
If you are looking forward the URL https://localhost:44391/jobs?cityId=2265885
you could try this a tag to request.
Go to JobPosts
———————————————————————————————
Using a middleware to handle /remote-jobs
app.Run(next => async context =>
{
if (context.Request.Path == "/remote-jobs")
{
return View with default IsRemote
}
});

Implementing Google Custom Search with filtering

I have to implement a page with multiple google-powered search forms. We have a license from Google for CSE, and this is the situation:
I have a search form that's present at the top of every page that performs a simple search and displays the results in a separate page. This works.
I have a particular page that, in addition, shows another two search forms: one should filter articles by category, another should filter articles by category and restrict the result to a certain month. I have added a meta key with the publication date to each article for this.
I have gotten a bit lost in the documentation, though: if I add
<gcse:searchbox-only resultsUrl="/[site]/stat/search/google_search_results.html"></gcse:searchbox-only></div>
to the page, I can't filter the results. If I start to meddle with a CustomSearchObject, I don't see an option to show results on a different page.
For category-based filtering, I've tried appending
more:pagemap:metatags-taxonomies:news
to the query argument in the results page URL, and it does work, but I don't understand how to inject this to the form.
For restricting based on dates, I tried adding
&sort=more:pagemap:metatags-pubdate:r:YYYYMMDD:YYYYMMDD
but haven't been able to make it work. Getting the XML does work:
http://www.google.com/search?q=intitle:[mysite]%20more:pagemap:metatags-taxonomies:News&sort=metatags-pubdate:r:20120401:20120830&cx=[mykey]client=google-csbe&output=xml
returns correct results.
Is there documentation that doesn't assume so much? All I find are code snippets without context. I've checked Filtering and sorting, Custom Search Element Control API, and of course this site, but I can't put all the pieces together.
I managed to implement what I wanted. In the search page, I built simple forms pointing to my results pages (this might not be doable if you must implement google branding), and in the results page I put the following:
(in the <head>)
<script src="http://www.google.com/jsapi"></script>
<script>
// This function extracts the query from the URL (if GET) or builds a search query.
// Code removed to simplify the example.
function buildQuery () {
return '<?php echo $_POST['q'];?> more:pagemap:metatags-taxonomias:News'); // injecting the taxonomy metatag filter
}
google.load('search', '1', {language : 'es'});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] = {'sort':'metatags-pubdate:d,metatags-pubdate:r:<?php echo $_POST['startdate'];?>:<?php echo $_POST['enddate'];?>'}; // these come from the POST request, are processed earlier in the script.
var customSearchControl = new google.search.CustomSearchControl('XXXXXXXXXXX', customSearchOptions); // Put your own App key here.
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var drawOptions = new google.search.DrawOptions();
drawOptions.enableSearchResultsOnly(); // I don't want the search box here
customSearchControl.draw('cse-results-press', drawOptions);
var query = parseQuery();
if (query) {
customSearchControl.execute(query);
}
}, true);
</script>
In the <body>:
<div id="cse-results-press">Loading...</div>

Funnel non-activated users to a single page and restricting access

So, given that I have user table with a field of "is_confirmed", I want funnel anyone with an "is_confirmed" that is equal to 0 to a single url using the redirect...
Is there a way to do this check so that it only needs to be implemented once? I guess a good example would be the default user functionality of how any page that requires a logged-in user forces the user to the login page...
Haven't tried this specifically myself, but based on Yii's documentation one would probably redirect the user inside the login action based on the value. If the user is confirmed, call the CWebUser::login(..) method to store the identity in persistent storage and use the returnUrl redirect, otherwise the user is not confirmed so skip that part and just render the in limbo page.
Inside your SiteController::actionLogin() you'll probably do something like this (additionally the UserIdentity component should have a method for returning the value of the confirmation field)-
$identity = new UserIdentity();
if($identity->authenticate()) {
if($identity->isConfirmed() == 1) {
Yii::app()->user->login($identity);
$this->redirect(Yii::app()->user->returnUrl);
} else {
$this->render('not_yet_confirmed_view');
}
} else {
throw new CHttpException(500,'Internal Server Error. Could not authenticate.');
}
Edit- Removed the accidental extra CWebUser::login() and clarified that the UserIdentity component will require just a bit of additional smarts.

WHMCS Addon Module with Multiple Pages

I am currently working on developing my first WHMCS Addon Module, and so far everything has gone very well. However, I need to make multiple content pages, and the only way to display output according to the Wiki Article is to echo it in the output function. How can I create individual pages when the only way to display content is via a single PHP function?
I am assuming using divs, and hiding the relevant divs, although not exactly the best method. It says you can use the "modulelink" variable to link back to the module, but I have no idea how to use this, or if it can be used for making multiple content pages.
http://docs.whmcs.com/Addon_Module_Developer_Docs
After some tinkering, it was much more simple than I realized, and the "modulelink" variable was just so you could link back to the page. To create additional pages, you can basically just do something along the lines of...
Datacenters
Then in the output function have...
$category = $_GET['catid'];
if ($category == "1" || $category == "")
{
//page 1 content here
}
else if ($category == "2")
{
//page 2 content here
}
and so on.

Handling a return from Google Checkout

I need to capture server side a notification of a users payment. I've gone through a good majority of the documentation with no luck, but will go through it again. Is there a way to enable a "return to site" after they complete the order?
I searched google checkout return url and got http://www.phpexpertsforum.com/return-url-in-google-checkout-after-payment-t561.html
veerlapallavi wrote...
There are 2 methods through which you
can provide the return URL. 1) Go to
your Google checkout account and Open
the settings. In the settings>>Profile
you can find a field with name "Public
business website:" provide your return
URL there.
2) The second method is , You can pass
the value to Google Checkout with the
HTML form as a hidden variable.
<input name="continue_shopping_url"
type="hidden"
value="http://www.yousite.com/payment_success.php">
OR
Set a function as below
SetContinueShoppingUrl("http://www.yousite.com/payment_success.php");
function SetContinueShoppingUrl($url)
{ $this->continue_shopping_url =
$url; }
Hope that helps.
It looks like you can configure gcheckout to send you XML notifications, but I don't see how you can associate it with a particular order ID other than matching fields or something...
http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Notification_API.html#new_order_notifications