Advertisement
MChaos

feed

Jan 26th, 2024
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1.     public function feed_google_csv()
  2.     {
  3.         $feed_url = getcwd() . "/public/feed_google/feed_google_csv.csv";
  4.         if (!is_dir(getcwd() . "/public/feed_google")) {
  5.             mkdir(getcwd() . "/public/feed_google/");
  6.         }
  7.  
  8.         $key1 = "ID";
  9.         $key2 = "Item title";
  10.         $key3 = "Final URL";
  11.         $key4 = "Image URL";
  12.         $key5 = "Sale price";
  13.         $list[] = array(
  14.             $key1, $key2, $key3, $key4, "Item subtitle", "Item description", "Price",
  15.             $key5, "Item category", "Contextual keywords"
  16.         );
  17.  
  18.         $this->db->select('id,titleRU,titleRO,uriRU,uriRO,SKU,price,discount_price,
  19.        (SELECT products_img.img FROM products_img WHERE products_img.product_id=products.id LIMIT 1) as img,
  20.             (SELECT categories.uriRO FROM categories WHERE categories.id=products.category_id) as cat_uri,
  21.             (SELECT categories.titleRO FROM categories WHERE categories.id=products.category_id) as cat_title,
  22.              (SELECT brands.title FROM brands WHERE brands.id=products.brand_id) as brand_title,');
  23.         $this->db->where('price >', 0);
  24.         $this->db->where('on_stock >', 0);
  25.         $this->db->where('isShown', 1);
  26.         $property = $this->db->get("products")->result();
  27.  
  28.         foreach ($property as $key => $item) {
  29.  
  30.             $ttl = 'Colecție ' . $item->titleRO . ' de la ' . $item->brand_title . ' în Moldova';
  31.             $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.';
  32.             if (!empty($item->discount_price)) {
  33.                 $price = $item->price;
  34.                 $sale_price = $item->discount_price . ' MDL';
  35.             } else {
  36.                 $price = $item->price;
  37.                 $sale_price = '';
  38.             }
  39.             $lastwo = substr($item->id, -2);
  40.             $list[] = array(
  41.                 "$item->id",
  42.                 "$item->titleRO",
  43.                 "https://rafidecor.md/ro/catalog/".$item->cat_uri."/" . $item->uriRO . "",
  44.                 "https://rafidecor.md/public/products/$lastwo/$item->img",
  45.                 "$ttl",
  46.                 "$dsc",
  47.                 "$price MDL",
  48.                 "$sale_price",
  49.                 "$item->cat_title",
  50.                 "$item->cat_title",
  51.             );
  52.  
  53.         }
  54.         $fp = fopen($feed_url, 'w+');
  55.         foreach ($list as $fields) {
  56.             fputcsv($fp, $fields);
  57.         }
  58.         fclose($fp);
  59.  
  60. //        $this->dump($list);
  61.  
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement