Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function feed_google_csv()
- {
- $feed_url = getcwd() . "/public/feed_google/feed_google_csv.csv";
- if (!is_dir(getcwd() . "/public/feed_google")) {
- mkdir(getcwd() . "/public/feed_google/");
- }
- $key1 = "ID";
- $key2 = "Item title";
- $key3 = "Final URL";
- $key4 = "Image URL";
- $key5 = "Sale price";
- $list[] = array(
- $key1, $key2, $key3, $key4, "Item subtitle", "Item description", "Price",
- $key5, "Item category", "Contextual keywords"
- );
- $this->db->select('id,titleRU,titleRO,uriRU,uriRO,SKU,price,discount_price,
- (SELECT products_img.img FROM products_img WHERE products_img.product_id=products.id LIMIT 1) as img,
- (SELECT categories.uriRO FROM categories WHERE categories.id=products.category_id) as cat_uri,
- (SELECT categories.titleRO FROM categories WHERE categories.id=products.category_id) as cat_title,
- (SELECT brands.title FROM brands WHERE brands.id=products.brand_id) as brand_title,');
- $this->db->where('price >', 0);
- $this->db->where('on_stock >', 0);
- $this->db->where('isShown', 1);
- $property = $this->db->get("products")->result();
- foreach ($property as $key => $item) {
- $ttl = 'Colecție ' . $item->titleRO . ' de la ' . $item->brand_title . ' în Moldova';
- $dsc = 'Cumpără marfuri din colecție ' . $item->titleRO . ' în Chișinău. Cel mai mare sortiment de marfuri pentru casa stilată de la Rafi Decor.';
- if (!empty($item->discount_price)) {
- $price = $item->price;
- $sale_price = $item->discount_price . ' MDL';
- } else {
- $price = $item->price;
- $sale_price = '';
- }
- $lastwo = substr($item->id, -2);
- $list[] = array(
- "$item->id",
- "$item->titleRO",
- "https://rafidecor.md/ro/catalog/".$item->cat_uri."/" . $item->uriRO . "",
- "https://rafidecor.md/public/products/$lastwo/$item->img",
- "$ttl",
- "$dsc",
- "$price MDL",
- "$sale_price",
- "$item->cat_title",
- "$item->cat_title",
- );
- }
- $fp = fopen($feed_url, 'w+');
- foreach ($list as $fields) {
- fputcsv($fp, $fields);
- }
- fclose($fp);
- // $this->dump($list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement