我不明白我的代码有什么问题。我正在 Joomla 下制作一个网站模板!2.5.9 和 VirtueMart 2.0.20b。
我正在处理Category pagetplname/html/com_virtuemart/category/default.php
和Product pagetplname/html/com_virtuemart/productdetails/default.php
。
在这两个页面上,我需要以百分比显示税:即:20% 税。
对于产品页面,它是:
$product->prices['Tax'];
对于类别页面,它是:
<?php foreach ($products as $product):?>
<li>
<?php echo $product->prices['Tax'];?>
</li>
<?php endforeach;?>
var_dump()
对这两个都做一个它给了我这个输出:
array
204 => // <- Remember this number as FIRST ARRAY
array
0 => string 'TAXNAME_TITLE' (length=12)
1 => string '10.0000' (length=7) // <- I need this value!
2 => string '+%' (length=2)
3 => string '1' (length=1)
4 => string '47' (length=2)
5 => string '' (length=0)
6 => string '1' (length=1)
7 => string '204' (length=3)
为了获得我需要的价值,我这样做:
$productPriceTaxUnit = reset($product->prices['Tax']);
$productPriceTaxUnit = $productPriceTaxUnit['1'];
$productPriceTaxUnit = JText::_('COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX') . ' ' .number_format($productPriceTaxUnit, '2', '.', '') . '%';
echo $productPriceTaxUnit;
它工作正常,但在FIRST ARRAY
等于的类别页面上给204
了我一个错误,但如果它等于,1
那么一切都很好。
有人看到我在这里做错了一步吗?
提前致谢
====== ** 第一次更新** ========
这是一个 SQL 调试:
SELECT SQL_CALC_FOUND_ROWS l.`virtuemart_product_id`
FROM `ar9hu_virtuemart_products_sk_sk` as l JOIN `ar9hu_virtuemart_products` AS p using (`virtuemart_product_id`)
LEFT JOIN `ar9hu_virtuemart_product_categories` as pc
ON p.`virtuemart_product_id` = `pc`.`virtuemart_product_id`
LEFT JOIN `ar9hu_virtuemart_categories_sk_sk` as c
ON c.`virtuemart_category_id` = `pc`.`virtuemart_category_id`
LEFT JOIN `ar9hu_virtuemart_product_shoppergroups`
ON p.`virtuemart_product_id` = `ar9hu_virtuemart_product_shoppergroups`.`virtuemart_product_id`
LEFT
OUTER JOIN `ar9hu_virtuemart_shoppergroups` as s
ON s.`virtuemart_shoppergroup_id` = `ar9hu_virtuemart_product_shoppergroups`.`virtuemart_shoppergroup_id`
WHERE ( p.`published`="1"
AND `pc`.`virtuemart_category_id` = 9
AND `pc`.`virtuemart_category_id` > 0
AND ( s.`virtuemart_shoppergroup_id`= "1" OR s.`virtuemart_shoppergroup_id` IS NULL ) )
group by p.`virtuemart_product_id`
ORDER BY `p`.product_sku ASC
LIMIT 0, 10
====== ** 第二次更新** ========
这是我在类别页面上遇到的错误:
Notice: Trying to get property of non-object in D:\wamp\www\baranik\templates\baranik\html\com_virtuemart\category\default.php on line 119
Call Stack
# Time Memory Function Location
1 0.0002 652096 {main}( ) ..\index.php:0
2 0.0714 9131016 JSite->dispatch( ) ..\index.php:42
3 0.0749 9542784 JComponentHelper::renderComponent( ) ..\application.php:197
4 0.0785 9691392 JComponentHelper::executeComponent( ) ..\helper.php:351
5 0.0789 9787480 require_once( 'D:\wamp\www\baranik\components\com_virtuemart\virtuemart.php' ) ..\helper.php:383
6 0.0980 12819808 JController->execute( ) ..\virtuemart.php:99
7 0.0980 12819888 VirtueMartControllerCategory->display( ) ..\controller.php:761
8 0.0980 12821880 JController->display( ) ..\category.php:60
9 0.1006 13209152 VirtuemartViewCategory->display( ) ..\controller.php:722
10 0.2021 19796592 JView->display( ) ..\view.html.php:244
11 0.2021 19796592 JView->loadTemplate( ) ..\view.php:205
12 0.2031 19910088 include( 'D:\wamp\www\baranik\templates\baranik\html\com_virtuemart\category\default.php' ) ..\view.php:649