开发者

Magento, Help with SQL Query to get full product URL's

So, basically I am looking to interact with the database outside of Magento. Upon reviewing tables in the database, catalog_product_flat_1 seems to store the majority of the information I am looking to retrieve so this gets me just all about everything but the final step.

I am trying to understand the relations within the Magento DB and get all the full product URL's into my newly created table.

The purpose of this is for an SEO/PPC initiative where having a nice list of every product sku, name, brand, description and url direct开发者_StackOverflowly to the product would make the work a breeze.

I have everything working just fine aside from the full product URL.

I have been doing a good amount of reading and it appears more people are using SQL injections within the normal Magento methods, but I am looking to do this with the database outside of the site.

Any help would be greatly appreciated.


Running raw SQL commands against the Magento database is time-consuming, not upgrade-proof and, in some cases, dangerous. Use the models made available to you in the Magento codebase to perform your queries.

You could achieve your sku, name, brand, description and url would be done with:

<?php
require_once 'app/Mage.php';

Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);

umask(0);
Mage::app();

$fhandle = fopen("dump.csv", "w");
$products = Mage::getModel('catalog/product')->getCollection()
                                             ->addAttributeToSelect('*');

foreach ($products as $product) {
    $data = array(
        $product->getSku(),
        $product->getName(),
        $product->getBrand(), // Or whatever your attribute name is..
        $product->getDescription(),
        $product->getUrlPath()  
    );

    fputcsv($fhandle, $data);
}

fclose($fhandle);

I don't follow your use of "SQL Injections". They are attacks, not ways of programming.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜