Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
7
Indexable
public function getProductData($orderId , $withLink = true)
    {
        $OrderItemsTable = $this->loadModel('OrderItems');
        $this->loadModel('Products');

        $query = $OrderItemsTable->find();

        $query->select([
            'oi_product_id' => 'OrderItems.oi_product_id',
            'oi_master_product_id' => 'OrderItems.oi_master_product_id',
            'oi_order_id' => 'OrderItems.oi_order_id',
            'product_code' => 'Product.product_code',
            'product_id' => 'Product.product_id',
            
        ]);
        $query->innerJoin(['Product' => 'fp_products'], ['Product.product_id = OrderItems.oi_product_id']);
        $query->where([
            'OrderItems.oi_order_id ' => $orderId,
            'OrderItems.oi_master_product_id IS NULL'
        ]); 
        $masterProductData = $query->toArray();
        $itemCodes = [];
        if(isset($masterProductData) && !empty($masterProductData))
        {
            foreach($masterProductData as $currProductData)
            { 
                if($withLink === true)                       
                {
                    $itemCodes[] = "<a href='" . Router::url(['controller' => 'products', 'action' => 'view', $currProductData->product_id , '0', '0', $orderId . "-Orders"]) . "' data-toggle='ajaxModal' class='text-green cursor-pointer priority'>" .  $currProductData->product_code . " </a>";
                }
                else
                {
                    $itemCodes[] =  $currProductData->product_code;
                }
                
            }

            if(!empty($itemCodes))
            {
                if($withLink === true)                       
                {
                    $item_code =  implode('<br /> ', $itemCodes); 
                }
                else
                {
                    $item_code = implode("\n", $itemCodes);
                }

                
            }
        }
        else 
        {
            $item_code = '-';    
        }
        return $item_code;
    }
Editor is loading...
Leave a Comment