Magento Multistore - how to modfiy checkout.phtml - php

I am using onestepcheckout.
I have added another webshop.
Now both webshops are using /app/design/frontend/base/default/template/onestepcheckout/checkout.phtml
Problems:
We have modified in the past this file but I cant fix this problem:
->. We show the question: New at hatstore? Hatstore is our shopname.
How can I make this question display dynamically?
so "New at clothesstore" is displayed when they visit our other clothingstore.
->. We have forced also in this file a url to register:
hxxp://haststore.com/webshop/customer/account/create/
How can I change this, so this will be dynamically too:
hxxp://%shopurl%/%shopstorename%/customer/account/create/
I've searched a lot but couldnt find it. Can you help me?

You can use a simple if else condition in your template file
First get the store(webshop) ID / code from magento backend from Configuration > Manage Stores.
$code = Mage::app()->getStore()->getCode();
if($code == 'hat') // suppose your store code for HATSHOP is hat.
{
echo 'question: New at hatstore?';
//anything else
}
else
{
echo 'question: New at clothstore?';
//anything else
}

Follow anz's answer. To get current store base URL
$this->getUrl('');
If need to get customer/account, then try like this
$this->getUrl('customer/account');

Related

giving custom argument vlue in 'q' variable

**also posted on druapl.stackexchange
https://drupal.stackexchange.com/questions/150500/giving-custom-argument-vlue-in-q-variable
**
apologies if question is ambiguous . the scenario is as follows:
in drupal 7 , we want to use a custom template page when a specific value is given for the q variable in url .
for example if we give http://localhost/drupal/?q=xyz/123 , we want to use a custom template page say page-xyz.tpl.php ..
have a hunch that hooks and template.php file may be the key components here but not sure what to exactly do..
any help appreciated.
you could implement theme_preproccess_page() (or node, or html) to control this in your template.php
function YOURTHEME_preproccess_page(&$vars) {
if (isset($_GET['q']) && $_GET['q'] == 'xyz/123') {
$vars['theme_hook_suggestions'][] = 'page_xyz';
}
}
that should work, but I would like to recommend not use the '?q=xyz' solution, but do an preproccess that should work to all your pages, like this.
function YOURTHEME_preproccess_page(&$vars) {
$title = strreplace(' ','_', $vars['node']->title);
//if you use the transliteration module, instead of strreplace
//use transliteration_get($vars['node']->title);
$vars['theme_hook_suggestions'][] = 'page_'.$title;
}
now that should work for every page that you want to make a custom template. Just add the file and clear the chaches. If you don't have the page template to the specific page, it's ok, drupal will use the default.

How to make different categories view from one php file

My title might seems unclear. I will describe what I want to do.Let's say the picture shown below is my index.php. If I click 0-100 in 'Select by price', it redirects me to another php file. The difference between this index.php and the '0-100' is just a mysql query that shows different products according to the price in the products box and same for all the others too. Now I realize that it is not a good way to do. And I tried to google my problem but as I am new in PHP i could not find the exact technological name to search in internet. Could you please help me how can I solve my problem or please share the link like my problem.
1. One way would be to use php get variables in the php file, and echo items if price lies between the variable value.
Your url would be something likeindex.php?low=0&high=100.
This gives you two variables, the lower limit on price and the higher limit on price.
While echoing the product you can check for condition,
if($price>=$_GET['low'] && $price<=$_GET['high']){
//then only show the item.
}
2. Another way would be to use javascript or jquery.
Where you can iterate over items and hide them if they do not belong to selected range client side itself. Hence, the page will have to be reloaded if user changes the price ranges.
You should use 'switch', very basic solution:
Click
<?php
if(!isset($_GET['price_from']) && !isset($_GET['price_to']))
{
redirect to index or something
}
switch($_GET['price_from'].'-'.$_GET['price_to'])
{
case '0-100':
echo 'Your content';
break;
case '100-300':
echo 'Your content';
break;
case '300-500':
echo 'Your content';
break;
default:
load index or something
}

Drupal 7 - Page template suggestion based on specific alias

I'm poor php developer and i need code for my template.php to set specific template for some pages:
Example:
mypage/blog/about-me
mypage/blog/about-you
mypage/blog/about-us
Uses page--blog-about-first.tpl.php.
mypage/blog/about-him
mypage/blog/about-her
mypage/blog/about-them
Uses page--blog-about-second.tpl.php.
I can't find it anywhere so i'm asking here.
Check the naming conventions here:
https://drupal.org/node/1089656
If you need to do something more complex you can use the instructions here/:
https://drupal.org/node/223440#custom-suggestions
// Page template suggestions based off URL alias
$alias=drupal_get_path_alias($_GET['q']);
$args=explode('/', $alias);
if ($args[0]=='blog/about-me') {
$vars['theme_hook_suggestions'][] = 'page__simple_blog';
}
elseif ($args[0]=='artist') {
$vars['theme_hook_suggestions'][] = 'page__simple_blog';
}
This is the code. I got link /blog/about-me and link /artist. Suggestion works for artist page, but not for blog/about-me. Solution?

In wordpress I am manipulation 404 response. I want to give the response before 404 error is given to google

May be the question in title is not explaining what exactly I want. So I will explain one logic and then ask what problem I am getting from that.
We are using wordpress.
We have 2 categories Option1(Having 64 different values) and Option2(Having 8 different values). We wanted url like ourdomain/Option1/Option2 depending on users location. And data on that url will be specific according to that Option1 and Option2. We dont wanted all this 64*8 actual wordpress pages to be created.
So after searching much on net we had one solution that I implemented one plugin for routing.
IN that code snippet was as follow.
function site_router() {
global $route,$wp_query,$window_title;
error_reporting(E_ALL);
if ( $wp_query->is_404 )
{
$wp_query->is_404 = false;
$cUrl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$targetUrl="";
switch($cUrl)
{
/* According to condition I had written diffent cases like below.
*/
default :
{
include(get_template_directory() . "/home.php" );
$template =locate_template('pagepath/home.php');
$window_title = 'dynamically it will come';
if ($template) {
load_template($template);
die;
}
}
}
}
}
add_action( 'wp', 'site_router');
So by this my purpose was fulfilled successfully.
But now problem is that google is saying they are getting back a 404 error. I think obviosly it will give as after it gives the error we are doing all template loading and all stuff.
So Can any body guide me how can I do this before that 404 response is given to google.
I posted the question on wordpress stackexchange and got the answer over there. the link is as below.
https://wordpress.stackexchange.com/questions/70345/in-wordpress-i-am-manipulation-404-response-i-want-to-give-the-response-before

Accessing custom variables from a .phtml in Magento

I have a file (js.phtml) where my code executes. I need to access some user data. When I error_log($this) in js.phtml, it displays, "Mage_Core_Block_Template" - which is confusing to me. I would expect that to be the parent class, not the value of the class getting passed to my .phtml file.
So, how do I supply the .phtml file with custom objects or methods? I'm super new to Magento and I've just been dropped into a task, so I apologize for possibly using incorrect terminology.
Edit:
My full file path is:
/app/design/frontend//default/template/customer/welcome/js.phtml
There is also a full module dir here:
/app/code/local//Customer/
Edit:
I need access to the users country and userid. It's ok if country is null.
Edit:
I've been doing additional research, it looks like I can do something like this:
Current user in Magento?
But I haven't tried it in code yet ....
Edit: Figured it out:
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getEntityId(), true));
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getCountry(), true));
To get customer ID:
echo Mage::getSingleton('customer/session')->getCustomer()->getId();
To get country - depends from which address. Here's an example of getting the country code from the default billing address:
echo Mage::getSingleton('customer/session')->getCustomer()->getDefaultBillingAddress()->getCountry();
I am somewhat new to Magento, but I think this should work.
$customer = Mage::getSingleton('customer/session')->getCustomer();
That gets the customer object. Then...
echo $customer->getAddresses();
That should get the country somewhere in the address. As for userid...I don't see it on the documentation page..You could try
echo $customer->getAttributes();
And see what is in there. The documentation page is at:
http://docs.magentocommerce.com/Mage_Customer/Mage_Customer_Model_Customer.html

Categories