Beispiel #1
0
 private function parse_basket($basket)
 {
     $result = array();
     $nom_list = ORM::factory('Nomenclature')->where('id', 'IN', array_keys($basket))->find_all();
     $product_list = ORM::factory('catalog_Element')->where('id', 'IN', array_unique($nom_list->as_array(NULL, 'product_id')))->find_all()->as_array('id');
     $catalog_element = new Catalog_Element();
     $product_props = $catalog_element->get_properties($product_list);
     $nom_list = $nom_list->as_array('id');
     $nomenclature_element = new Nomenclature_Element();
     $nom_props = $nomenclature_element->get_properties($nom_list);
     foreach ($basket as $_key => $_count) {
         $_orm_nom = Arr::get($nom_list, $_key);
         if (empty($_orm_nom)) {
             continue;
         }
         $_orm_product = Arr::get($product_list, $_orm_nom->product_id);
         if (empty($_orm_product)) {
             continue;
         }
         $_props = Arr::get($nom_props, $_orm_nom->id, array());
         $result[$_key] = array('product_id' => $_orm_product->id, 'nomenclature_id' => $_orm_nom->id, 'name' => make_nomenclature_name($_orm_product, $_orm_nom), 'count' => (int) $_count, 'price' => Arr::path($_props, 'Price.value'), 'discount' => $this->discount($product_props, $_props));
     }
     return $result;
 }
Beispiel #2
0
 private function _get_nomenclature($orm)
 {
     $nomenclature_element = new Nomenclature_Element();
     $nom_list = $nomenclature_element->get_list($orm->id);
     $nom_properties = $nomenclature_element->get_properties($nom_list);
     $request = $this->request->current();
     $query_array = array_intersect_key($request->query(), array_filter(array('no_cache' => TRUE, 'p' => FALSE)));
     $query_string = Helper_Page::make_query_string($query_array);
     $query_string = empty($query_string) ? '' : '?' . $query_string;
     $link_tpl = $request->url() . $query_string . '#item-';
     $result = array();
     foreach ($nom_list as $_orm) {
         $_props = Arr::get($nom_properties, $_orm->id, array());
         $_size_name = Arr::path($_props, 'Size.value.Name.value');
         $_duvet_cover = Arr::path($_props, 'Size.value.DuvetCover.value');
         $_bedsheet = Arr::path($_props, 'Size.value.Bedsheet.value');
         $_pillowslip = Arr::path($_props, 'Size.value.Pillowslip.value');
         $_price = Arr::path($_props, 'Price.value');
         $_discount = Arr::path($_props, 'Discount.value');
         $result[] = array('id' => $_orm->id, 'name' => "{$orm->title} ({$_size_name})", 'link' => $link_tpl . $_orm->id, 'price' => $_price, 'discount' => $_discount, 'size' => array('name' => $_size_name, 'duvet_cover' => implode(', ', Arr::pluck($_duvet_cover, 'value')), 'bedsheet' => implode(', ', Arr::pluck($_bedsheet, 'value')), 'pillowslip' => implode(', ', Arr::pluck($_pillowslip, 'value'))));
     }
     usort($result, function ($elm_1, $elm_2) {
         if ($elm_1['price'] == $elm_2['price']) {
             return 0;
         }
         return $elm_1['price'] > $elm_2['price'] ? -1 : 1;
     });
     return $result;
 }