I duplicated products magento and my urls are product-1.html product-2.html - magento

I have made my magento store (community)
I have used duplicate product on a lot of products and I didn't get that the URL key field had to be changed for every product i thought i would solve it self.
Now i have about 100 products and unfortunately they are now named example:
/HaircolorBlack.html , /haircolorblack-1.html, /haircolorblack-2.html and so on.
I wonder if there are any way to easy make magento re create the url after what the products meta title is?
This would be so helpful.
I saw this two year old post about approx the same thing but I didn't wanted to use that script since I don't know if it might break anything in my magento since its been so much updates. Here is link: Clearing URL keys in Magento
Also I need total moron instructions on where to put the script to. Sorry ;)
Thanks a lot.
S

You can create a one off script using magento itself.. add this script somewhere in your magento root folder (beside index.php):
<?php
require_once "app/Mage.php";
Mage::app('admin'); // must be admin to do changes
function convertToUrlKey($string) {
return $string; // I WILL LEAVE YOU TO SOLVE THIS PART
}
foreach(Mage::getModel('catalog/product')->getCollection() as $product):
$metaTitle = $product->getMetaTitle();
$urlKey = convertToUrlKey($metaTitle);
try {
$product->setUrlKey($urlKey);
$product->save();
echo "Assigned url key {$urlKey} to {$product->getName()}.\n";
} catch(Exception $ex) {
echo "ERROR: {$ex->getMessage()}";
}
endforeach;
Obviously this is not a complete solution as you will have to re-create the convertToUrlKey function for the correct behavior of converting 'Black Hair Color' to 'black-hair-color' and also ensure that there will be no duplicate url keys generated..
You can run the script by browsing to it or running through SSH:
$ cd magentoProject
$ php -f changeUrlkeys.php
Good luck!

Related

Magento Tables and how they work with the database

I been trying to understand Magento and I read many things on the wiki, but I couldn't figure out How does Magento works with database tables? because I didn't see any SQL
I would reccomend read over this blog post from Alan Storm:
http://alanstorm.com/magento_models_orm
He explains quite abit about the Magento ORM system, and in my opinion that entire site is a great resource for any Magneto developer.
If you watch your MySQl log, the calls made by magento can sometimes be 500 lines long or longer ... These calls are dynamically constructed using XML files. The best way to manipulate Magento data manually is to use MAGE:: calls or use a direct database connection by using:
$read = $resource->getConnection('core_read');
$sql = "select * from [YOUR_TABLE] where 1 limit 1";
$result = $read->query($sql);
It's either that or calls that look like:
$value = 'some value';
$item->setData('some_key', $value);
$item->save();
Magento is object oriented, so those are the most commonly accepted and used ways to retrieve/set data in Magento. I hope that helps.
Read chapter 5 onwards from the knowledge base.
You are not really asking a question so no one can help on the specifics, I always find that you learn best by doing, I find the best way to mess around with magento is to create a test.php file in shell/ with the following: (for example)
<?php
require('abstract.php');
class Test extends Mage_Shell_Abstract
{
function run(){ //call your functions here
echo 'running ..';
$this->database();
}
function database() { //you can create as many functions as you like
$entityId = '4449'; //product id
$product=Mage::getModel("catalog/product")->load($entityId);
var_dump($product->getAttributeText('size'));
}
}
$test = new Test();
$test -> run();
Then you can run from console:
php test.php
and it returns in my example
running ..string(11) "Extra Large"
Hope this helps you, next time be more specific.

Shipping Methods are not working in magento 1.7

I activated flat shipping in the shipping options and whenever you do checkout it says “Sorry, no quotes are available for this order at this time.”Any one please help me since i am a beginner in magento.
EDIT
I have tried other shipping methods too its also showing the same. we have upgraded Magento ver. 1.4.1.1 to magento 1.7. Any help would be greatly appreciated..
EDIT 2
After upgrading community folder contains only Phoenix folder. After that i added Biebersdorffolder by seeing an error in checkout page. I don't the the purpose of folders AW and RocketWeb. Since i am not familiar with magento.
If the image is not visible i have added the image in this url
http://i47.tinypic.com/14smix1.jpg
do you have any Checkout files modified on your project? Or maybe custom checkout.
I will list the code locations you need to check to make sure your Shipping works correctly.
So to begin with: Magento has very special work process with Shipping rates - it's called "collectRates" and is some modification of pattern "composite".
To make sure that everything works correctly on the code basis you need to first check the Onepage.php model (app/code/core/Mage/Checkout/Model/Type/Onepage.php): lines 330, 341, 556, 616; There should be code
{address}->setCollectShippingRates(true)
where {address} is current address variable.
This code is significant for future "collectRates" processes, because just when the Onepage Checkout page is initializing the "collectRates" process has already been processed, and the flag "collect_shipping_rates" is set to "false". If it's not set back to true, the next "collectRates" process will not be performed.
After you check the location above, and it still doesn't work - you might want to add some logging to Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates method. If method is properly executed and return some rates from $this->getAddress()->getGroupedAllShippingRates() call, there might be some issues with .phtml template on your locan theme (default path to .phtml is app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml).
Here's how you can log the outcome from $this->getAddress()->getGroupedAllShippingRates() call (Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates method):
$groups = $this->getAddress()->getGroupedAllShippingRates();
$printGroupes = array();
foreach ($groups as $code => $groupItems) {
foreach ($groupItems as $item) {
$printGroupes[$code][] = $item->getData();
}
}
Mage::log($printGroupes, null,'special.log');
Please note, that the result array with all rates will be logged into "special.log" under var/logs folder.
I wish I could be more of help, but the issue requires some digging into code, the debugger will be even more helpful than logging, if you can get hold of one.
Cheers!
Price should be entered for Flat Rate shipping to work
The problem might be of the country selection
Ship to applicable countries is set to "Specific Country" and you selected "Canada".
So you will see this shipping method only if you select Canada on the frontend during the checkout.
Or
You can make this to All Countries and check whether its working or not.

Product description page not shown, error 404

using magento 1.7.0.2 here, having already tested lot of recommended solutions (reindexing, clearing cache, assuring no url rewrite is done, etc) I give up and ask the question.
We are importing a bunch of products (around 150) into the demo store, together with 2 new categories and lot of new attributes (around 200). After some issues we finally managed to get the products shown both on backend and frontend, great.
But when clicking on any newly imported product we get the 404 error page from Magento with the "Whoops, our bad...". After 2 days searching and trying different approaches still haven't found a solution. Reindexing, clearing cache, checking the url rewrite option, changing 'localhost' for '127.0.0.1' on the core_config_data table, and some other solutions that worked for others, no use for us.
Any clue?
Other than the solutions found we have checked that the products are enabled, visibility is set for both catalog and search, there is a website assigned and quantity is bigger than zero. Also we manually created a product with all the correct attributes values and its description page is visible. Comparing (both using backend and database tables/fields) with the imported products averything seems to be exactly the same.
I'm self answering. Thanks to #sulman that pointed in the correct direction.
Yes, visibility was ok for all the products and it was correctly settled as for both Catalog and Search. But the problem was that in our import script we didn't check for the existence and correct assignment of the attribute to the imported product. Therefore the attribute existed but it was not linked to the already existing visbility attribute.
Here a sample code in case is needed, see the opening if (isset($attributeId)) that checks if the attribute exists or not.
if (isset($attributeId))
{
$entityAttributeModel = Mage::getModel('catalog/product_attribute_api');
$attributeList = $entityAttributeModel->items($attributeSetId);
$attributeLink = $this->search($attributeList, 'attribute_id', $attributeId);
if (sizeof($attributeLink) == 0)
{
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeToGroup($this->getEntityTypeId(), $attributeSetId, $groupId, $attributeId);
}
$model = Mage::getModel('catalog/resource_eav_attribute');
$attribute = $model->load($attributeId);
}

Magento Ajax add to cart not working for subsites

I've written a small script that is called via ajax for adding products to the cart.
$request = Mage::app()->getRequest();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();
foreach($pids as $pid){
if(!pid || $pid == ''){continue;}
$product = Mage::getModel('catalog/product')->load($pid);
$cart->addProduct($product, $qty);
}
$session->setCartWasUpdated(true);
$cart->save();
I have a multi site setup and this script works fine when it is run under the main site but when I run it under one of the subsites it doesn't add it to the cart.
I've tried having the addtocart.php in the root of the subsite (and including the main sites mage.php) and have also tried adding it to the root of the main site, But nothing works.
Do I need to specify the website id somewhere?
Thanks
First take the easy step of setting a cookie domain prefixed with a single period. This acts like a wildcard.
The default behaviour is to not share carts between stores. In your 'small script' make sure the correct store is chosen the first time you initialise the app.
Mage::app($storeId);
Sometimes when crossing domains you need to include the SID as an URL parameter. I'm not sure how you would find that value, perhaps from the referrer page..?

Set Special Price Programmatically In Magento

I am trying to write a script that will set a special price on a product with a start and an end date. When I run my script it does successfully set the special price, but the start and end date do not populate in the admin panel.
The code I am running is as follows:
$product = Mage::getModel('catalog/product')->load(114912);
$product->setSpecialPrice( ($product->getPrice() * .90) );
$product->setSpecialFromDate('2010-11-01');
$product->setSpecialFromDateIsFormated(true);
$product->setSpecialToDate('2010-11-30');
$product->setSpecialToDateIsFormated(true);
$product->save();
Does anyone know what I am doing wrong here?
I have just tried your code on my catalog and it worked with a little adjustement.
You should pay attention to the loaded store;
it is not allowed to update certain product fields if the ADMIN store is not the currently loaded (Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);).
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
...
$product->save();
?>
This is just a guess but have you tried passing a timestamp like from time() and leaving out the setSpecialFromDateIsFormated(true)? That should cause the backend model to reformat it appropriately for you.

Resources