I am working on a website in magento. Which has two store (base, boutique) and 4 store view
base (fr,en) and boutique (bfr,ben).
Now when I am using store URL in site url. I am getting 4 urls for every store view
http://example.com/en
http://example.com/fr
http://example.com/boutique/ben
http://example.com/boutique/bfr
We want the url of other store as shown below :
http://example.com/boutique/en
http://example.com/boutique/fr
but we have already store view with these codes.
Please help how to solve this.
You cannot use the same code for 2 store views. Period.
But you can try a different approach to have your url's like this.
Don't use 'Add store codes to url' and instead actually create the folders you need fr, en, boutique/en, boutique/fr and copy the index.php and .htaccess files to each one of those folders and replace the following.
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
with
$mageFilename = '../app/Mage.php';
or
$mageFilename = '../../app/Mage.php';
depending on the depth of the folders.
And replace this
Mage::run($mageRunCode, $mageRunType);
with
Mage::run('store code here', 'store'); //instead of store code view put en, fr, ben or bfr
You also need to adjust the base urls for each store view from system->configuration.
Related
I do have 5 shops:
http://www.mainshop.com
http://www.mainshop.com/subshop/
http://www.mainshop.com/subshops/
http://www.mainshop.com/subshops3/
http://www.mainshop.com/subshop4/
But everytime i click on the url for a categroy it keeps giving a Magento 404 error.
I did copy the index.php and htaccess to that subdirs and changed this line:
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'subshop1';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
I also changed the configuration of that specific website:
The 404 comes to cms pages and category pages. Can't figure it out.
Magento creates a full links like this:
{{unsecure_base_url}}../skin/
http://www.example.com/shop/../skin/
which wont work ofcourse... Try inserting the full links ;)
Like this:
http://www.example.com/skin/
Have you used store views for each shop on one magento installation? You should not have sub directories for each shop and no need to copy index.php or any other file to a subdirectory. I think you have misunderstood how magento store views work. What you should do is enable the option for the storecode to be shown in each URL. When you setup your store view you specify the code which will be used (e.g. subdir1, subdir2 or whatever you want it to be). You need to use store views as you are using the same base URL which you need to change back to be default for each store view so it should be http://www.mainshop.com/ for every store view or website. This will allow you to achieve what you are trying to, without modding any magento code. Read this document in the wiki for more information how to do it properly http://www.magentocommerce.com/knowledge-base/entry/overview-how-multiple-websites-stores-work/
I'm building a website with a custom content management system, and I want to build a slug area like wordpress. I want to retrieve the path name from my front-end depending on the page they're on, and echo that out in my backend in the slug area.
I'm using php and my front-end is dynamic, which means I have one page, and depending on what the user clicks on, I will include that file.
What I want the code to look like for the slug in the backend:
<?php
//front end path/ echo $slug;
?>
My front-end path looks something like this: blahblah/index.php/slug-name
I have a slug stored in the database that I will echo out, but my problem is I don't know how to retrieve the front end path and echo it out in the backend. I realize I can type the front-end path manually, but I think doing it dynamically would be better incase I move my website to a different location in the future.
I've tried using pathinfo or $_SERVER but that echos out my backend path rather than my front end.
Hopefully I was clear, if not, ask me to clarify something. Thanks again.
You need the rewrite module for apache or nginx.
That allows you to do like this:
PrettyPath(This will be seen to all visitors): http://blah.com/blah/bl/ah/test
=> RealPath(This can be used for develop): http://blah.com/blah/index.php?slug=bl/ah/test
You can do beautiful job like this for using rewrite module. (Rewrite Example)
$front_end_path = 'your/site/path';
$full_url = $front_end_path . $slug;
I am currently working on a magento site that is in 2 languages (French and Dutch). The approach I am taking is as follows:
Create a folder in the web root (named nl)
Import the index.php and .htaccess file to that folder
In the index.php I modify the following line:
Mage::run('nl'); // to specify the store view i want to load
When I check, the categories, CMS content etc are still in the default language. The following code:
Mage::app()->getStore()->getName();
returns the fr store's name.
What is it that I'm doing wrong? I think a viable solution would be to set the store to run in index.php...
Could someone please let me know how to load a store by ID?
After hours of huffing and puffing i was able to figure out a way to set the store id programatically :)
In the index.php file, (in your language specific folder), add the following:-
$store_id = 'your_store_id_here';
$mageRunCode = 'store view code';
$mageRunType = 'store';
Mage::app()->setCurrentStore($store_id);
Mage::run($mageRunCode, $mageRunType);
Hope someone will find this information useful :)
You will get all store details here
<?php
$allStores = Mage::app()->getStores();
foreach ($allStores as $_eachStoreId => $val)
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
echo $_storeId;
echo $_storeCode;
echo $_storeName;
}
?>
To redirect to the specified store, you need to redirect the page along with the store code.
http://www.mywebsite.com/index.php/store_code/
Please check the template/page/switch/stores.phtml for more details
If the reason you're doing the htaccess stuff is so that you can generate URLs specific to each store, you may want to go with the configuration option that does that for you, should be in System > Config > Web
I am developing a simple website. It will have close to 20 pages. It has a 3 level hierarchy.
Home
MenuStub
Category1
Page1
Page2
Category2
Page1
Page2
....
....
....
The main navigation will have 4 - 5 items representing each 'category'
This will be constant for all the pages. I am not even planning to
highlight the current category or anything.
Previously I decided to put the menu HTML stub alone in a separate file
and use PHP include to include it in all pages.
But, relative paths might be frustrating. Assume that the menu stub
file is located at the root directory.
So, in the root-level pages, the php include will read like
include "menustub.html";
in the second level pages, it should say
include "../menustub.html";
and in third level pages, it should say
include "../../menustub.html";
First, is this the best way to include a single file
across all pages in a website?
Second, if the website grows big, and many more levels
are added, maintaining this will be a problem. If I suddenly
decide to move an entire set of pages one (or several) levels
up or down, I should manually go and change the relative paths
in each file.
Am I missing something here? Is there a universal way to point
to a particular file, that every page will understand, regardless
of where it is located?
What is the best way to have a stub and include it in all the pages
without having these maintenance nightmares?
Common ways to solve this problem is either by using include_path: In your config, add the dir with such files to include path, and you can simply do
include "menustub.html";
from anywhere.
See http://se2.php.net/manual/en/ini.core.php#ini.include-path
It can be set from php.ini and in code. Not sure if it can be set in .htaccess files
Another way is to set a root directory variable and always use it:
include "{$rootDir}/menustub.html";
There is also the option of using auto append/prepend, which means you tell php to always append or prepend a file, see http://se2.php.net/manual/en/ini.core.php (auto_prepend_file)
$rootDir can either be set from configuration, or automatically using $_SERVER['DOCUMENT_ROOT']. The former is good if you use it for shared files (shared between several web apps), the latter for convenience if the files are located under one webapp directory strucure.
It would be much more dynamic to have the index file do all the including, and use GET parameters to tell it which page is to be include.
For example, consider a directory structure like this:
/
index.php
/ui
header.html
menu.html
footer.html
Cat1/
Page1.html
Page2.html
Cat2/
Page3.html
Page4.html
If you were to always call the index file, including the name of the category and page you wanted to see, like: index.php?category=Cat1&page=Page1, you could do something like this:
<?php
// Include a header and a menu, defined in their own HTML files.
include('ui/header.html');
include('ui/menu.html');
// Set up a list of valid categories and their sub pages.
$pages = array(
'Cat1' => array(
'Page1',
'Page2'
),
'Cat2' => array(
'Page3',
'Page4'
)
);
// Find the category and page to use.
if(isset($_GET['category'], $pages[$_GET['category']])) {
$category = $_GET['category'];
} else {
$category = 'Cat1';
}
if(isset($_GET['page'], $pages[$category][$_GET['page']])) {
$page = $_GET['page'];
} else {
$page = 'Page1';
}
// Include the selected content page.
include("ui/{$category}/{$page}.html");
// Include a footer
include('ui/footer.html');
?>
This way you can expand the content as far and deep as you want without having to repeat your includes in every single new file.
I use CodeIgniter, I'm happy with that, but I have a question.
I build my projects under /www/projectname/beta/... directory, so at my code, at many parts like including some images or css files or etc. I have to make ... src="/projectname/beta/... so when I complete the website, I need to edit so many pages to clear these /projectname/beta/ path and make it / for main root. or when I start new project with same base, first of all I need to edit these paths at all files.
now, how can I define a variable like
$projectbetapath =
"/projectname/beta/";
and have access from everywhere, like global. where can I add such line, and how can I access this var from everywhere?
Thanks!! appreciate!
Why don't you add a constant in your index.php file?
define('BETA_PATH', '/beta');
When the site leaves the beta stage you just do:
define('BETA_PATH', '');
There are two answers to your question:
Set your variables as array fields of $config in application/config/config.php and access them with $this->config->item('name');
Use the URL-helper (Or $this->config->item('base_url')) to get the current base path whenever you have to type in a path.
The second answer will give you full flexibility, you'll only have to modify the base URL in config.php if the project moves.