How to make the condition in magento? - magento

Now, I want to output something when the user register my site, how to make the condition, namely:
If()
If the user register my site, then on the page echo something.eg:
When the user is not registered on my site, the page echo "test". If he is registered on my site, then echo "hello." But when he logged in my site the second time, the page should also echo "test".
How to make the condition. Thank you.

try this
if(Mage::helper('customer')->isLoggedIn()){
}

From my understanding capturing the login event could be useful for what you want to achieve. See this detailed tutorial on how to do something very similar to what you are trying. On this case they are offering a reward for first order a client has made.
I have struggling with a bigger task and one of my middle steps was to capture an event, wich I accomplished by following the previous posted link. It was very useful.
Here is one of my questions about the subjetct (capturing events and redirecting), maybe it can help you too.

Related

Combine multiple form validate independently in flask-wtf and commit to db

I've created a questionnaire in which, each user visit '/{questionnaire_id}/{question_number}' to answer to them. To do so, when the user start the questionnaire, the app redirect the user to '/{questionnaire_id}/{question_0}' and when he submit the answer page will redirect to '/{questionnaire_id}/{question_1}' and so on.
I've created a field in my answer_db named 'completed' and it's default is 0. When the user answer to all questions the app will change the 'completed' field to 1 which implies that these answer could be added to analysis part.
It's work properly but it's not efficient. I want to use Ajax in a way that solve 2 problem for me.
Show all the questions in a same url to avoid redirection
Submit all the answers to db when all the questions answered which helps me to remove 'completed' field
I was wondering if it is possible or not

What code should I add (and where) on my website to track events/identify users on my website using segment.com?

I want to configure segment.com properly on my site and use it to manage all other apps/tools. I already installed the segment javascript on my site and used it as the source. Now, I am pushing these to MixPanel, Facebook, Google Analytics, etc.
What code should I add if I want to track an event and/or identify a user?
For simplicity's sake, i have a landing page (site.com/landing-page) with a form. After a successful submission, it redirects to a thank you page (site.com/thank-you-page).
The default settings already track the page views, and are pushing that same event to the different tools (FB: PageView, MixPanel: Loaded a Page, etc).
But in this case, i want to track the event and capture the person's information. And i don't know what to code to add and where.
My research so far
According to this article:
The best way to track new users is in client-side javascript on the welcome page after they signup, below we’ll explain why.
So, based on that, I add the code to my thank you page. But where? Header like adding GA scripts? body tag? I can add it anywhere, but i don't know where.
Next is what code should I add?
The example from the same article above:
When a new visitor goes to their site that visitor is anonymous. As soon as the visitor connects their Facebook account, Rdio knows who they are and creates a user record.
As part of that new user record the person is assigned a userId. Let’s say the new userId is 12345. Rdio will then need to fire the following calls on the welcome page:
analytics.identify('12345',{ name:'Jake Peterson', email:'friends#segment.com'});
analytics.track('Account Created',{ authentication:'Facebook'})
This gives me two problems: track and identify.
Track Problem
I'll start with the track. Based on how I understood this, assuming the event name i want to be added is "Downloaded PDF" then I want to store the title of it as well. It should look like this, right?
<script>
analytics.track('Downloaded PDF', {
title: 'Awesome Title'
});
</script>
Am I correct to enclose them inside <script> tags?
The tracking of an event seems a bit easier to understand that the identify part. But would love to know if i got that part right.
Identify Problem
Here, i have two questions:
where does userId come from? Is it automatically generated? For example, inside my MixPanel account, i see them. Is that what i use?
How do i reference to the userId? or any of the other traits I want to track in my code?
Taking from the same example above:
analytics.identify('12345',{ name:'Jake Peterson', email:'friends#segment.com'});
If i add this exact code on my thank you page, every signup will be assigned those values: '12345', 'Jake Peterson', and 'friends#segment.com', right?
What code should I add to (1) assign them the right userId (2) and get the name and email traits from the form of the previous page.
Let's say i'm only collecting first name and email.
analytics.identify("userId"{ firstName:"firstName", email:"email"});
If I add this code to my thank you page, will it automatically assign the userId, firstName, email values of the form that was submitted? That's the part I don't understand. What code to add to dynamically push the correct data.
And i know i'm not even adding the Alias part for MixPanel yet, but i just want to understand this part and the rest (hopefully) will be easier to understand.

WooCommerce - checkout - AJAX billing address check error

I have a problem with WooCommerce's checkout form (WooCommerce version 2.4.7). I sell a physical object and I have guest purchases enabled (with an option to register). I skip the cart, because it's unnecessary in my case. Anyway, when I input the billing address, at the end, AJAX call to checkout/?wc-ajax=update_order_review is made and the data returned from call is as follows:
{"result":"success","messages":"","reload":"false","fragments":{".woocommerce-checkout-review-order-table"
:"<table class=\ ... "}
The result is success, but the fields get emptied and the user is therefore prompted to input the address again and again ... with no success. I use the very well known Avada template and I don't really know, where to start debugging. I don't think it's the template issue.
Can anyone help?
For anyone who encountered this kind of problem, the solution seems to be to not to include the checkout.js file, which takes care of "AJAXy" stuff on Checkout page. You then have to do the input checks yourself.
The solution: Disable AJAX on checkout for WooCommerce
Have a nice day!

How to denied all requests except some in Magento

The question is not enough clear, so I will explain more.
My client has a requirement in mobile1 about the users all SHOULD not visit all request2
For example:
The users SHOULD: only visit some in below list:
mydomain.com/catalog/product/view
mydomain.com/cusotmer/account/any_action
mydomain.com/onepage/checkout/any_action
So, I am having a solution is at the method: Mage_Core_Controller_Varien_Action::preDispatch()
I will get the request variable to check what is moulde, controller, action. If it is valid in list, if not I will redirect to an accessed denied page.
I know that is bad, so I am looking for other solutions.
1: We've already designed a theme for mobile, just want to give for user some pages are necessary.
2: I mean to the router format: module/ controller/ action.
UPDATE:
Thanks all guys so much. Now, I understand what I need to do. I don't know how to close my question. So please help me if you can. I don't want to be a member who never accept the answer.
This is not good question which could be easy to answer, but very happy for help from #azakolyukin and #elgabbu
So, I think #azakolyukin's comment is correct answer.

Redirect CI problem

I'm kind of new with CodeIgniter and I'm still learning (a lot).
So I have a view and when I submit a form I 'call' the controller by surfing to the right URL dynamically e.g. site/delete
class Site extends Controller {
function index(){$this->load->view('...')}
function delete() {
$this->site_model->delete_row();
$this->index();
}
}
Now when that action is done (deleted the row) I'm calling $this->index(); to redirect to my initial page (which is good) but my url stays: site/delete . I want my URL to be ../site/index (or without the /index)
Any help would be appreciated :-) .
So far I found something to solve this:
instead of:
$this->index();
I'm using:
redirect('site');
Does anyone know this is a good practice?
Redirect is what you should use.
In the user guide:
http://codeigniter.com/user_guide/helpers/url_helper.html
they use it after checking if a user is logged in. Depending on if they are or not, they redirect to a different place.
Also, note that any code after the redirect won't run. Make sure and redirect after you've done everything you need to.
My preferred method is to have actions like that handled by the same method that will be seen by the user afterwards.
What if you go to /site/delete afterwards, as a user? It will either have to detect and throw a error (show a message) or redirect to an appropriate page. /site/delete has no meaning.
For example, if a user would normally see an overview after deleting, then my form will be posted to /site/index; with index quickly checking for the condition and calling _delete() in the same controller, before doing its normal work.
That way, if the user refreshes the page, or presses 'back', things should look consistent to them.
Another example would be that /settings/edit would post to itself - this means that it can act on the post and show any output (e.g. validation errors). It means there's no /settings/do_edit location on my site, and also means that the user can go back to /settings/edit safely, and see a form for editing their settings.
I suppose this is a subjective take on a perhaps objective question, and I would encourage feedback on my view, but it's my way of avoiding the problem you have asked about.
$this->index();
Call of function in a function simply execute the functionality within that function.
And url never changed.
for changing the url you should use.
redirect ( base_url().'site');
but you should load url helper in constructor.

Resources