Magento getProductListJSON需要更多数据

Magento getProductListJSON需要更多数据,magento,magento-1.7,Magento,Magento 1.7,调用getProductListJSON javascript函数的部分代码如下所示 $.getJSON(storeRootUrl + "jsoncatalog/product/list/id/"+id, function(jsonObj) { renderProductList(jsonObj,sid); }); 它返回图像、产品名称、描述和id 我希望它能返回更多,比如产品类型,如“简单、可配置等” 根据布局: <jsoncatalog_product_list>

调用getProductListJSON javascript函数的部分代码如下所示

$.getJSON(storeRootUrl + "jsoncatalog/product/list/id/"+id, function(jsonObj) {
    renderProductList(jsonObj,sid);
});
它返回图像、产品名称、描述和id

我希望它能返回更多,比如产品类型,如“简单、可配置等”

根据布局:

<jsoncatalog_product_list>
        <reference name="content">  
            <block type="paypal_catalog/json_product_list" output="toHtml" name="product_list"/>
        </reference>
    </jsoncatalog_product_list>
在哪里可以添加所需的额外字段

我是否走上了正确的轨道,或者甚至查看了返回数据的正确模板/php代码

请帮帮我,我已经有2年没有做Magento开发了,所以我必须重新学习这方面的知识


提前感谢。

这确实是一个输出的地方。然而,你需要深入挖掘。请看这一行:

$array = Mage::helper('paypal_catalog')->getProducts($category->getId());
这将填充jsonEncode在输出例程中使用的数组。这可能位于
app/code/community/Paypal/Catalog/Helper/
的某个地方

或者,您可以对
$array
进行后期处理,并将其添加到字段中。但是,我强烈反对这样做,因为在helper方法
getProducts
中,您可能会有更好的运气(和性能)


祝你好运。

我最终得到了以下代码,这不是最有效的,但此移动应用解决方案列表中的产品从未超过5种

将代码添加到:

$array = Mage::helper('paypal_catalog')->getProducts($category->getId());
$this->setCurrenCategoryKey($category->getId());
并使之:

$array = Mage::helper('paypal_catalog')->getProducts($category->getId());
foreach ($array['items'] as &$productitem) {
    $productId = $productitem['id'];
    $product = Mage::getModel('catalog/product')->load($productId);
    if(!is_null($product)){
        $productitem['type'] = $product->getTypeId();
        //Get all options for product
        $options = array();                 
        $options = $product->getOptions();
        if (count($options) > 0){
            $productitem['hasoptions'] = '1';
        }
        else
        {
            $productitem['hasoptions'] = '0';
        }
        $addTocartUrl = $this->helper('checkout/cart')->getAddUrl($product);
        $productitem['addTocartUrl'] = $addTocartUrl;
    }
    else{
        $productitem['type'] = 'simple';
        $productitem['hasoptions'] = '0';       
    }
}
$this->setCurrenCategoryKey($category->getId());
然后,我可以使用以下内容更改我的footer.phtml:

<!-- Product List Template -->
<div id="productListTemplate">
    <li onclick="checkQuickAdd(jQuery(this),'%url%');">
        <div class="product-image">%image%</div>
        <div class="product-content">
            <div class="product-title">%title%</div>
            <div class="product-description"><span class="counter" style="font-weight:bold;font-size:large;"></span> %description%</div>
            <div class="product-price">$%price%</div>
            <div class="quickadd"><a href="#" class="quickaddlink">+</a></div>
        </div>
        <div class="product-id" style="display:none;">%id%</div>
        <div class="product-hasoptions" style="display:none">%hasoptions%</div>
    </li>
</div>
这一定是我很长时间以来写的最低效的代码,但完成这项工作的时间非常短

我想以一种更有效的方式来做这件事


如有任何建议,将不胜感激

所以基本上,我的答案是什么?我已经做了数组后处理,但是正在寻找一个使用app/code/community/Paypal/Catalog/Helper的更有效的示例。没有时间实现更有效的方法。
<!-- Product List Template -->
<div id="productListTemplate">
    <li onclick="checkQuickAdd(jQuery(this),'%url%');">
        <div class="product-image">%image%</div>
        <div class="product-content">
            <div class="product-title">%title%</div>
            <div class="product-description"><span class="counter" style="font-weight:bold;font-size:large;"></span> %description%</div>
            <div class="product-price">$%price%</div>
            <div class="quickadd"><a href="#" class="quickaddlink">+</a></div>
        </div>
        <div class="product-id" style="display:none;">%id%</div>
        <div class="product-hasoptions" style="display:none">%hasoptions%</div>
    </li>
</div>
function checkQuickAdd(listitem,url)
{
    var hasOptions = jQuery(listitem).find(".product-hasoptions").text();
    var productId = jQuery(listitem).find(".product-id").text();
    var productTitle = jQuery(listitem).find(".product-title").text();
    if (hasOptions == '0'){

            try {
                jQuery(".ui-loader").css("display","block");
                var cartUrl = "/index.php/test/jsoncheckout/cart/add/product/" + productId;
                var cartno = jQuery(jQuery('.ui-page-active .menu-bar-item.itemright>div')[0]).attr('id').replace("cartCount","");
                var cartCount = jQuery(jQuery('.ui-page-active .menu-bar-item.itemright>div')[0]).text();
                jQuery.ajax( {
                    url : cartUrl,
                    type: "POST",
                    dataType : 'json',
                    contentType: "application/json; charset=utf-8",
                    async: true,
                    cache: false,
                    success : function(data) {
                        //alert("added");
                        var counter = 1;
                        var strCounter = jQuery(listitem).find(".counter").text();
                        if (strCounter != "") { counter = parseInt(strCounter) + 1; }
                        if (cartCount != "") { 
                            cartCount = parseInt(cartCount) + 1; 
                        }
                        else {
                            cartCount = 1;
                        }
                        jQuery(listitem).find(".counter").text(counter);

                        // update cart number
                        updateCartCount(cartCount, cartno);
                        jQuery(".ui-loader").css("display","none");        
                        alert("Added " + productTitle);
                    },
                    fail: function (msg) {
                        jQuery(listitem).find(".product-description").text(msg.d);
                        jQuery(".ui-loader").css("display","none");
                    }
                });
                jQuery(".ui-loader").css("display","none");
            } 
            catch (e) {
                alert(e);
                jQuery(".ui-loader").css("display","none");
            }

    }
    else{
        forwardURL(url);
    }
}