2016-02-15 1 views
0

Je voudrais que le module d'alimentation de base de google Opencart ne prendre que des produits avec le prix sur 80. De cette façon, les propriétaires de OpenCart ne pouvaient promouvoir les produits qui sont des valeurs plus élevées et des margesalimentation Opencart - ne prendre que des produits à prix plus de 80

Comment pourrais-je le faire? Je pense que cette question pourrait être bénéfique pour plus d'utilisateurs opencart.

apprécierais toute l'aide :)

<?php 
class ControllerFeedGoogleBase extends Controller { 
    public function index() { 
     if ($this->config->get('google_base_status')) { 
      $output = '<?xml version="1.0" encoding="UTF-8" ?>'; 
      // $output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">'; 
      $output .= '<SHOP>'; 
      //$output .= '<title>' . $this->config->get('config_name') . '</title>'; 
      //$output .= '<description>' . $this->config->get('config_meta_description') . '</description>'; 
      //$output .= '<link>' . HTTP_SERVER . '</link>'; 

      $this->load->model('catalog/category'); 

      $this->load->model('catalog/product'); 

      $this->load->model('tool/image'); 

      $products = $this->model_catalog_product->getProducts(); 

      foreach ($products as $product) { 
       if ($product['description']) { 
        $output .= '<SHOPITEM>'; 
        $output .= '<ITEM_ID>' . $product['product_id'] . '</ITEM_ID>'; 
        $output .= '<PRODUCTNAME>' . $product['name'] . '</PRODUCTNAME>>'; 
        $output .= '<PRODUCT>' . $product['name'] . '</PRODUCT>'; 
        $output .= '<DESCRIPTION>' . '</DESCRIPTION>'; 
        $output .= '<URL>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</URL>'; 
        // $output .= '<description>' . $product['description'] . '</description>'; 
        // $output .= '<g:brand>' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . '</g:brand>'; 
        //$output .= '<g:condition>new</g:condition>'; 

        if ($product['image']) { 
         $output .= '<IMGURL>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</IMGURL>'; 
        } else { 
         $output .= '<IMGURL>' . $this->model_tool_image->resize('no_image.jpg', 500, 500) . '</IMGURL>'; 
        } 

        $output .= '<IMGURL_ALTERNATIVE>' . '</IMGURL_ALTERNATIVE>'; 
        $output .= '<VIDEO_URL>' . '</VIDEO_URL>'; 



        $supported_currencies = array('USD', 'EUR', 'GBP'); 

        if (in_array($this->currency->getCode(), $supported_currencies)) { 
         $currency = $this->currency->getCode(); 
        } else { 
         $currency = ($this->config->get('google_base_status')) ? $this->config->get('google_base_status') : 'USD'; 
        } 

        if ((float)$product['special']) { 
         $output .= '<PRICE_VAT>' . $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency, false, false) . '</PRICE_VAT>'; 
        } else { 
         $output .= '<PRICE_VAT>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency, false, false) . '</PRICE_VAT>'; 
        } 

        $output .= '<HEUREKA_CPC>0.01' . '</HEUREKA_CPC>'; 
        $output .= '<MANUFACTURER>' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . '</MANUFACTURER>'; 

        $categories = $this->model_catalog_product->getCategories($product['product_id']); 

        foreach ($categories as $category) { 
         $path = $this->getPath($category['category_id']); 

         if ($path) { 
          $string = ''; 

          foreach (explode('_', $path) as $path_id) { 
           $category_info = $this->model_catalog_category->getCategory($path_id); 

           if ($category_info) { 
            if (!$string) { 
             $string = $category_info['name']; 
            } else { 
             $string .= ' | ' . $category_info['name']; 
            } 
           } 
          } 

          $output .= '<CATEGORYTEXT>Hobby | Rybárčenie | ' . $string . '</CATEGORYTEXT>'; 
         } 
        } 

        $output .= '<EAN>' . $product['ean'] . '</EAN>'; 
        $output .= '<PRODUCTNO>' . $product['model'] . '</PRODUCTNO>'; 
        $output .= '<DELIVERY_DATE>0</DELIVERY_DATE> 
           <DELIVERY> 
            <DELIVERY_ID>UPS</DELIVERY_ID>'; 
            if ((float)$product['special']) { 
             if($product['special']<65){ 
              $output .= '<DELIVERY_PRICE>3</DELIVERY_PRICE>' . '<DELIVERY_PRICE_COD>3</DELIVERY_PRICE_COD>'; 
             } 
             else{ 
              $output .= '<DELIVERY_PRICE>0</DELIVERY_PRICE>' . '<DELIVERY_PRICE_COD>0</DELIVERY_PRICE_COD>'; 
             } 
            } 
            else{ 
             if($product['price']<65){ 
              $output .= '<DELIVERY_PRICE>3</DELIVERY_PRICE>' . '<DELIVERY_PRICE_COD>3</DELIVERY_PRICE_COD>'; 
             } 
             else{ 
              $output .= '<DELIVERY_PRICE>0</DELIVERY_PRICE>' . '<DELIVERY_PRICE_COD>0</DELIVERY_PRICE_COD>'; 
             } 
            } 
            $output .= '</DELIVERY>'; 

        // $output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>'; 
        //$output .= '<g:upc>' . $product['ean'] . '</g:upc>'; 
        // $output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>'; 
        // $output .= '<g:availability>' . ($product['quantity'] ? 'in stock' : 'out of stock') . '</g:availability>'; 
        $output .= '</SHOPITEM>'; 
       } 
      } 

      $output .= '</SHOP>'; 
      // $output .= '</rss>';  

      //$this->response->addHeader('Content-Type: application/rss+xml'); 
      $this->response->setOutput($output); 
     } 
    } 

    protected function getPath($parent_id, $current_path = '') { 
     $category_info = $this->model_catalog_category->getCategory($parent_id); 

     if ($category_info) { 
      if (!$current_path) { 
       $new_path = $category_info['category_id']; 
      } else { 
       $new_path = $category_info['category_id'] . '_' . $current_path; 
      } 

      $path = $this->getPath($category_info['parent_id'], $new_path); 

      if ($path) { 
       return $path; 
      } else { 
       return $new_path; 
      } 
     } 
    }  
} 
?> 
+0

dans votre requête? ... where priceColumn> minPriceValue (c'est-à-dire 80) – user2267175

+0

Je ne suis pas tout à fait sûr de la façon dont vous le pensez, pourriez-vous préciser. Le code ci-dessus exporte le XML pour cela – Tom

+0

Je suppose que vous obtenez des produits à partir d'une base de données, limitez la requête pour inclure uniquement les produits dont le prix est supérieur ou égal à 80 – user2267175

Répondre

0

D'accord, donc, puisque vous ne pouvez pas modifier la requête elle-même .. c'est une façon de le gérer ..

.... 
foreach ($products as $product) { 
    //Calculate the product's price, including tax. 
    $priceCalc = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency, false, false); 

    //Check if the price, (in the current currency), is higher or equal to 80. 
    if ($product['description'] && $priceCalc >= 80) { 
     //continue if true.. 
     $output .= '<SHOPITEM>'; 
     $output .= '<ITEM_ID>' . $product['product_id'] . '</ITEM_ID>'; 
....