0

Prestashop 1.5.4.x 以下のコードで適切な category_link、画像、価格を取得するにはどうすればよいですか? 名前、リンク、製造元、category_full を適切に出力します。スクリプトで表示される価格の形式が正しくありません: 191.26073 instead of 191.26 and 65 instead of 65.00。画像スクリプトが間違ったパスを表示する場合: http://mysite.x10.mx/img/p/8-27-large.jpg、正しいパッチは http://mysite.x10.mx/27-thickbox_default/picture である必要があります。 jpg

私が使用した完全なコード:

<?php
include(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');
// Get data
$number = (intval(Tools::getValue('n')) ? intval(Tools::getValue('n')) : 10000);
$orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position');
$orderWayValues = array(0 => 'ASC', 1 => 'DESC');
$orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[intval(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));
$orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[intval(Configuration::get('PS_PRODUCTS_ORDER_WAY'))]));
if (!in_array($orderBy, $orderByValues))
$orderBy = $orderByValues[0];
if (!in_array($orderWay, $orderWayValues))
$orderWay = $orderWayValues[0];
//$id_category = (intval(Tools::getValue('id_category')) ? intval(Tools::getValue('id_category')) : 1);
$currency = new Currency(intval($cookie->id_currency));
$affiliate = (Tools::getValue('ac') ? '?ac='.Tools::getValue('ac') : '');

$categTree = Category::getRootCategory()->recurseLiteCategTree(0);

function constructTreeNode($node){
    $ret = ';';
    $ret .= $node['id'].'|'.$node['name'].';';
    if(!empty($node['children']))
    {
        $ret .= ';';
        foreach ($node['children'] AS $child)
            $ret .= constructTreeNode($child);
        $ret .= ';';
    }
    return $ret;
}
foreach ($categTree['children'] AS $child)
    $ulTree .= constructTreeNode($child);

$tab_cat=explode(';',$ulTree);
foreach ($tab_cat as $id2cat){
$tab_id2cat=explode('|',$id2cat);
if (!empty($tab_id2cat)) $tab_cat_final[$tab_id2cat[0]]=$tab_id2cat[1];
}

header("Content-Type:text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<root>
<?php
foreach ($tab_cat_final as $id_category=>$name_category){
$products = Product::getProducts(intval($cookie->id_lang), 0, ($number > 10000 ? 10000 : $number), $orderBy, $orderWay, $id_category, true);
foreach ($products AS $product)
{
  $image = Image::getImages(intval($cookie->id_lang), $product['id_product']);
  $prix=Product::getPriceStatic($product['id_product']);
  if ($product['reduction_percent']>0) $prix_promo=$prix*(1-$product['reduction_percent']/100);else $prix_promo=($prix-$product['reduction_price']);


  echo "<item>\n";
  echo "<name><![CDATA[".$product['name']."]]></name>\n";
                echo "<link><![CDATA[".htmlspecialchars($link->getproductLink($product['id_product'], $product['link_rewrite'], Tools::getValue('id_category'))).$affiliate."]]></link>\n";
  echo "<price>".$prix."</price>\n";
  echo "<image>"._PS_BASE_URL_.__PS_BASE_URI__."img/p/".$image[0]['id_product']."-".$image[0]['id_image']."-large.jpg</image>\n";
  echo "<category_full><![CDATA[".$name_category."]]></category_full>\n";
                echo "<category_link><![CDATA[".htmlspecialchars($link->getcategoryLink($category['id_category'], $category['link_rewrite'], Tools::getValue('id_category'))).$affiliate."]]></category_link>\n";
  echo "<manufacturer><![CDATA[".$product['manufacturer_name']."]]></manufacturer>\n";
  echo "<reference><![CDATA[".$product['id_product']."]]></reference>\n";
  echo "</item>\n";
}
}
?>
</root>
4

1 に答える 1

0

コードは次のとおりです。

$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
foreach ($tab_cat_final as $id_category=>$name_category)
{
$products = Product::getProducts(intval($cookie->id_lang), 0, ($number > 10000 ? 10000 : $number), $orderBy, $orderWay, $id_category, true);
foreach ($products AS $product)
{
$price = Product::getPriceStatic($product['id_product']);
if ($product['reduction_percent'] > 0)
$prix_promo = $price * (1 - $product['reduction_percent'] / 100);
else
$prix_promo = ($price-$product['reduction_price']);

$id_image = Image::getCover($product['id_product']);
$image_link = $link->getImageLink($product['link_rewrite'], $id_image, 'large_default');

echo "<item>\n";
echo "<name><![CDATA[".$product['name']."]]></name>\n";
echo "<link><![CDATA[".htmlspecialchars($link->getproductLink($product['id_product'],     $product['link_rewrite'], Tools::getValue('id_category'))).$affiliate."]]></link>\n";
echo "<price>".Tools::displayPrice($price, $default_currency)."</price>\n";
echo "<image>".$image_link."</image>\n";
echo "<category_full><![CDATA[".$name_category."]]></category_full>\n";
echo "<category_link><![CDATA[".htmlspecialchars($link-    >getcategoryLink($category['id_category'], $category['link_rewrite'],     Tools::getValue('id_category'))).$affiliate."]]></category_link>\n";
echo "<manufacturer><![CDATA[".$product['manufacturer_name']."]]></manufacturer>\n";
echo "<reference><![CDATA[".$product['id_product']."]]></reference>\n";
echo "</item>\n";
}
}

適切な価格を取得する方法は次のとおりです。

$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
Tools::displayPrice($prix, $default_currency)

画像を正しく取得するには、次のようにします。

$id_image = Image::getCover($product['id_product']);
$image_link = $link->getImageLink($product['link_rewrite'], $id_image, 'large_default');
于 2013-05-20T08:46:06.073 に答える