display products in member area in amember pro

155 Views Asked by At

i want to display products of one only particular category at member's area of amember.

i want to add code from site.php file.

can any one know how can i display products in block in member's area?

how can i handle query related operation from site.php in amember?

i have added block by using following code.now i want to display products in this block.

    Am_Di::getInstance()->blocks->add(new Am_Block('member/main/right',    'blockname', 'block_id', null, function (Am_View $v) {
    $html = <<<CUT
     <p>
want to display products here
     </p>
CUT;
    return $html;  
});
1

There are 1 best solutions below

0
On

I assume you want to show only products that user has access to. Here is code that you can use to achieve it. You can put it to site.php file. In this example I show products from category with id = 1, feel free to change it to necessary value.

$cat_id = 1;
$cat_product = Am_Di::getInstance()->productCategoryTable->getCategoryProducts();

if (($u = Am_Di::getInstance()->auth->getUser())
    && array_intersect($u->getActiveProductIds(), $cat_product[$cat_id])) {

    Am_Di::getInstance()->blocks->add(
        new Am_Block('member/main/right', 'My Products', 'product-cat-1', null,
            function(Am_View $v) use ($u, $cat_product, $cat_id) {
                $out = '';
                foreach ($u->getActiveProducts() as $p) {
                    if (!in_array($p->pk(), $cat_product[$cat_id])) continue;
                    $out .= sprintf("<li>%s</li>\n", Am_Html::escape($p->title));
                }
                return sprintf('<ul class="am-widget-list">%s</ul>', $out);
            }));
}