private function test($item)
 {
     // start
     $formHTML = '<form action="/update-item-prices/' . $item->id . '" method="POST">';
     // get all prices associated to current item viewing
     $itemPrices = $this->getAllItemsPrices($item);
     $itemPricesArray = array();
     foreach ($itemPrices as $price) {
         $itemPricesArray[] = $price->id;
     }
     // get all price groups
     $priceGroups = \Caramba\Price\Models\Price_group::all();
     // loop through each price group and display the name
     foreach ($priceGroups as $priceGroup) {
         $formHTML .= '<p><strong>' . $priceGroup->name . '</strong></p>';
         // get prices associated to this group
         $pricesAssocWithGroup = $priceGroup->prices()->get();
         // loop through each price associated to this group
         foreach ($pricesAssocWithGroup as $price) {
             $checked = '';
             if (in_array($price->id, $itemPricesArray)) {
                 $checked = 'checked="checked"';
             }
             // if the current price is associated to this item then check the box
             $formHTML .= '<p><input type="checkbox" name="prices[]" ' . $checked . ' value="' . $price->id . '"> - ' . $price->name . ' (' . $price->price . ')</p>';
         }
     }
     $formHTML .= '<input type="submit" value="Update Prices" class="btn btn-small btn-info">';
     $formHTML .= '<input type="hidden" name="_token" value="' . csrf_token() . '">';
     $formHTML .= '</form>';
     return $formHTML;
 }
 public function create($input)
 {
     $priceGroup = new Price_group();
     $priceGroup->name = $input['name'];
     $priceGroup->save();
 }
 /**
  * Register any other events for your application.
  *
  * @param  \Illuminate\Contracts\Events\Dispatcher  $events
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     \Event::listen('Caramba\\Core\\Events\\GetHeaderDetails', function ($event) {
         // Handle the event...
         $sidebar_details = array();
         $sidebar_details[] = array('url' => '/price-groups', 'heading' => 'View All Price Groups');
         // $sidebar_details[] = array('url' => '/admin-item/create', 'heading' => 'Create an Item');
         return $sidebar_details;
     });
     \Event::listen('Caramba\\Price\\Events\\Active', function () {
         return 1;
     });
     \Event::listen('Caramba\\Price\\Events\\TableName', function () {
         // Handle the event...
         return 'prices';
     });
     \Event::listen('Caramba\\Price\\Events\\GetByID', function ($id) {
         // Handle the event...
         $priceModel = new \Caramba\Price\Models\Price();
         $price = $priceModel->find($id);
         return $price;
     });
     /*
     always use below two event listeners coding methods 
     when displaying package data in html tables
     */
     \Event::listen('Caramba\\Core\\Events\\Frontend.Action_ViewItem_OrderSection', function () {
         $testArray = array();
         $testArray['th'] = '<th>Name</th>';
         $testArray['th'] .= '<th>Price</th>';
         $testArray['relatedListener'] = 'Frontend.Action_ViewItem_OrderSectionMainBody_Price';
         return $testArray;
     });
     \Event::listen('Caramba\\Core\\Events\\Frontend.Action_ViewItem_OrderSectionMainBody_Price', function ($item) {
         // start
         $tableTDs = '';
         // $formHTML = '<h3>Order</h3>';
         // $formHTML = '<form action="/update-item-prices/'.$item->id.'" method="POST">';
         // $formHTML .= '<table class="table">';
         // $formHTML .= '<tbody>';
         // get all prices associated to current item viewing
         $itemPrices = $item->prices()->get();
         $itemPricesArray = array();
         foreach ($itemPrices as $price) {
             $itemPricesArray[] = $price->id;
         }
         // get all price groups
         $priceGroups = \Caramba\Price\Models\Price_group::all();
         // loop through each price group and display the name
         foreach ($priceGroups as $priceGroup) {
             $showPriceGroup = false;
             // get prices associated to this group
             $pricesAssocWithGroup = $priceGroup->prices()->get();
             $tableTHs = '<tr><th>Name</th><th>Price</th></tr>';
             $pricesHtml = '';
             // loop through each price associated to this group
             foreach ($pricesAssocWithGroup as $price) {
                 if (in_array($price->id, $itemPricesArray)) {
                     $pricesHtml .= '<tr><td>' . $price->name . '</td><td>' . $price->price . '</td></tr>';
                     $showPriceGroup = true;
                 }
             }
             if ($showPriceGroup === true) {
                 $tableTDs .= '<tr><td colspan="2" style="font-weight:bold;">' . $priceGroup->name . '</td></tr>';
                 // $formHTML .= '';
                 $tableTDs .= $pricesHtml;
             }
         }
         // end looping through price groups
         // $formHTML .= '</tbody>';
         // $formHTML .= '</table>';
         return $tableTDs;
         // end
         // $customerModel = new \Caramba\UserManagement\Models\Customer;
         // $customer = $customerModel->where('user_id','=',17)->first();
         /*return '<td>Price Info Body 1</td>
         			<td>Price Info Body 2</td>
         		';*/
     });
     //
 }
    private function getTableData($item)
    {
        $tableTDs = '';
        // get all prices associated to current item viewing
        $itemPrices = $item->prices()->get();
        $itemPricesArray = array();
        foreach ($itemPrices as $price) {
            $itemPricesArray[] = $price->id;
        }
        // get all price groups
        $priceGroups = \Caramba\Price\Models\Price_group::all();
        // loop through each price group and display the name
        foreach ($priceGroups as $priceGroup) {
            $showPriceGroup = false;
            // get prices associated to this group
            $pricesAssocWithGroup = $priceGroup->prices()->get();
            $tableTHs = '<tr style="background-color:#eee;"><th>Size</th><th>Price</th><th>Qty</th></tr>';
            $pricesHtml = '';
            // loop through each price associated to this group
            foreach ($pricesAssocWithGroup as $price) {
                if (in_array($price->id, $itemPricesArray)) {
                    $pricesHtml .= '<tr><td style="width:35%;">' . $price->name . '</td><td style="width:35%;">' . $price->price . '</td>
						<td style="width:40%;"><input style="width:40%;" name="qty_' . $price->id . '" type="text" /></td>
						</tr>';
                    $showPriceGroup = true;
                }
            }
            if ($showPriceGroup === true) {
                $tableTDs .= '<tr><td colspan="3" style="font-weight:bold;background-color:#ddd;">
									' . $priceGroup->name . '
									</td></tr>';
                $tableTDs .= $tableTHs;
                // $formHTML .= '';
                $tableTDs .= $pricesHtml;
            }
        }
        // end looping through price groups
        // $formHTML .= '</tbody>';
        // $formHTML .= '</table>';
        return $tableTDs;
    }