Example #1
0
 static function listResponse($imageSize, array $rows)
 {
     if ($rows) {
         $current = static::detectCurrentProduct();
         // prefetch all connected images as they're used in the view.
         File::all(prop('image', $rows));
         return array('rows' => S($rows, function ($product) use($current, $imageSize) {
             return array('image' => $product->image($imageSize), 'current' => $current and $current->id === $product->id) + $product->to_array();
         }));
     }
 }
Example #2
0
 function get_goods($id = null)
 {
     if ($result = $this->ajax($id)) {
         $this->layout = 'vanemart::block.cart.goods';
         $goods = $result->order_by('group')->get();
         // cache connected images all at once.
         File::all(prop('image', $goods));
         if ($this->in('grouped', 1)) {
             $groups = Group::where_in('id', prop('group', $goods))->lists('title', 'id');
         } else {
             $groups = array();
         }
         $rows = S($goods, function ($product) use($groups) {
             return array('image' => $product->image(200), 'group' => array_get($groups, $product->group)) + $product->to_array();
         });
         return compact('rows') + array('showGroups' => true);
     } else {
         return $result;
     }
 }