private function prepare_categories(&$data) { if (!is_array($data)) { $data = array($data); } $category = new Category(); $data = array_filter($data); $existing = $category->get($data); $count = count($data); $parent_id = 0; $result = array(); for ($i = 0; $i < $count; $i++) { $name = $data[$i]; if ($existing && isset($existing[$name])) { $parent_id = $existing[$name]; $result[$existing[$name]] = $name; } else { $new_category = new \Classes\Opencart\Category(); $new_category->name = $name; $new_category->url = Util::translate($new_category->name); $new_category->parent_id = $parent_id; if ($i == 0) { $new_category->top = 1; } if ($saved = $category->post($new_category)) { $existing[$name] = $parent_id = $saved->id(); $result[$saved->id()] = $name; } } } $data = $result; }
protected function bind_array($row = array()) { $this->product_id = (int) $row[0]; $this->model = $row[1]; $this->name = $row[2]; $this->price = $this->calculate_price(str_replace(',', '.', $row[3])); $this->image = $this->get_image_url($row[4]); $this->quantity = $this->translate_quantity($row[5]); $this->description = ''; /*if (!empty($row[6])) { $this->description .= '<br>' . $row[6]; }*/ $this->minimum = (int) (!$row[11]) ? 1 : $row[11]; $this->category = array($row[6], $row[7], $row[8]); $this->url = Util::translate($this->name); $this->tag = Seo::tags($this->name); $this->meta_title = Seo::meta_title($this->name); $this->meta_keyword = Seo::keywords($this->name); $this->meta_description = Seo::meta_description($this->name); }