This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

Getting product info can be a pain if you don't know where to look for the code that does so within the core. I want to make this easy for everyone. My hours of frustration are now yours to enjoy. In your custom block controller on_page_view() function include the following:

    $page = Page::getCurrentPage();
    $pageid = $page->getCollectionID();
    $db = Loader::db();

    if($page->getCollectionTypeName() == 'Product Detail'){ // Start Product Detail Check

        Loader::model('product/model', 'core_commerce');
        $uh = Loader::helper('urls', 'core_commerce');
        $productid = $db->GetOne('select productID from CoreCommerceProducts where cID = ?', array($pageid));
        if ($productid > 0) {
            $product = CoreCommerceProduct::getByID($productid);
            $productname = $product->getProductName();
            $productdescription = $product->getProductDescription();
            $productdesc = strip_tags($productdescription);
           } // End Product Detail Check

This code first checks that the block is on a product_detail page type, then checks whether there is a product associated with the page or not. If everything checks out, the product name and product description will then be available in the $productname and $productdesc variables respectively. Use them in whatever manner you need.

** This can be seen working within the block controller of the Enlil Facebook Product block in my Enlil Facebook Plugins package. Here, when the block is placed on product pages, it is setting Facebook name and description meta tags for use in the wall post when the page is shared by Facebook users.

Loading Conversation