Jump to content
mtom75

Árukereső csv export

Recommended Posts

Sziasztok!

 

Árukereső, árgép, olcsó mely táblákból kell adatokat ki exportálni?

Hogy kell összefűzni a táblákat?

 

 

Share this post


Link to post
Share on other sites

Mivel más megoldást nem tudok ezért magam kell megcsináljam.

Vagy van kész script? Árukeresőhöz?

Share this post


Link to post
Share on other sites

Árukereső PS feedje:

<?php
/*
** Arukereso.hu
** CSV exportáló PrestaShop webáruházhoz
**
** Ezt a fájlt a webshop főkönyvtárába kell elhelyezni, és már működik is.
**
*/

define ('AK_VERSION', '2.1.7');
define ('AK_CHECK_STOCK', 1);
define ('ENGINE_NAME', 'PrestaShop');
define ('MANUFACTURER_FIELD','manufacturer');

// define('_USER_ID_LANG_',1);

set_time_limit(0);

if (!file_exists('init.php') || !file_exists('config/config.inc.php')) {
  ak_error('An include file not found. Check the path.');
}
include('config/config.inc.php');
require_once('init.php');

if (isset($_GET['ak_check_stock']) && ($_GET['ak_check_stock'] == 0 || $_GET['ak_check_stock'] == 'true')) {
  define ('AK_CHECK_STOCK_CONST', 0);
} else {
  define ('AK_CHECK_STOCK_CONST', AK_CHECK_STOCK);
}

try {
  $query = Db::getInstance()->ExecuteS('SELECT p.id_product FROM ' . _DB_PREFIX_ . 'product p WHERE p.active = 1 '); // "AND quantity > 0"
  if (!$query) {
    ak_error('SQL error: ' . mysql_error());
  }

  $lang = (int)Configuration::get('PS_LANG_DEFAULT');

  $data = array();
  $curreny = Currency::getCurrent();
  $cat = new Category();
  $root = $cat->getRootCategory();
  $categories = array();

  $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
  $id_zone = (int)$defaultCountry->id_zone;
  $id_carrier = (int)(Configuration::get('PS_CARRIER_DEFAULT'));
  $carrierTax = Tax::getCarrierTaxRate((int)$id_carrier);
  $carrier = new Carrier((int)($id_carrier), Configuration::get('PS_LANG_DEFAULT'));

  foreach ($query as $i => $v) {

    $product = new Product(intval($v['id_product']),true, $lang);
    $productCategories = $product->getCategories();
    $parents = "";
    $category = "";
    foreach ($productCategories as $productCategory) {
      $temp = ak_get_category($productCategory);
      if ($temp['parents'] > $parents) {
        $category = $temp['name'];
        $parents = $temp['parents'];
      }
    }


    $url = $product->getLink();

    $img = $product->getCover($product->id);
    if ($img['id_image'] > 0) {
      $image = $link->getImageLink($product->link_rewrite,$product->id . '-' . $img['id_image'],'large');
    } else {
      $image = "";
    }

    $price = Product::getPriceStatic($product->id, true, NULL, 6);

    if (isset(Product::$_taxCalculationMethod) && Product::$_taxCalculationMethod == PS_TAX_INC) {
      $price = Tools::ps_round($price,2);
    } else {
      $price = round($price,2);
    }
    $line['manufacturer'] = ak_clean($product->manufacturer_name);
    $line['name'] = ak_clean($product->name);
    $line['category'] =  ak_clean($category);
    $line['product_url'] =  ak_clean($url);
    $line['price'] =  $price;
    $line['image_url'] =  ak_clean($image);
    $line['description'] = ak_clean($product->description,false);
    $line['ean13'] = ak_clean($product->ean13,false);
    $line['upc'] = ak_clean($product->upc,false);
    $line['reference'] = ak_clean($product->reference,false);
    $line['supplier_reference'] = ak_clean($product->supplier_reference,false);
    $line['currency'] = $currency->iso_code;
    $line['stock'] = $product->quantity;
    $line['delivery_price'] = ak_get_delivery_price($price, $product->weight, $id_zone, $id_carrier, $carrierTax, $carrier);
    $line['weight'] = $product->weight;

    if (!AK_CHECK_STOCK_CONST || ((Configuration::get('PS_STOCK_MANAGEMENT') || $product->quantity > 0) && $product->available_for_order)) {
      $data[] = $line;
    }
  }

  ak_csv_export($data);
} catch (Exception $e) {
  ak_error("Caught exception: " . $e->getMessage());
}


function ak_get_delivery_price($price, $weight, $id_zone, $id_carrier, $carrierTax, $carrier) {
  $shipping_cost = 984.25;
  $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
  if (isset($configuration['PS_SHIPPING_FREE_PRICE']) && $price >= $configuration['PS_SHIPPING_FREE_PRICE']) {
    return "FREE";
  }
  if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $weight >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) && (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) {
    return "FREE";
  }

  if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
    if ($weight > 0) {
      $shipping_cost += $carrier->getDeliveryPriceByWeight($weight, $id_zone);
    } else {
      return "";
    }
  } else {// by price
    $shipping_cost += $carrier->getDeliveryPriceByPrice($price, $id_zone);
  }
  if (isset($configuration['PS_SHIPPING_HANDLING']) AND $carrier->shipping_handling)
    $shipping_cost += (float)($configuration['PS_SHIPPING_HANDLING']);

  if (isset($carrierTax))
    $shipping_cost *= 1 + ($carrierTax / 100);

  return (float)(Tools::ps_round((float)($shipping_cost), 2));
}

function ak_get_category($categoryId) {
  global $categories, $root, $lang;
  if (!isset($categories[$categoryId])) {
    $name = "";
    $cntParents = 0;
    if ($categoryId != $root->id_category) {
      $cat = new Category($categoryId, $lang);
      $parents = $cat->getParentsCategories();
      $cntParents = count($parents);
      if ($cntParents > 0) {
        $category = array();
        foreach ($parents as $p) {
          $category[] = $p['name'];
        }
        $name = implode(' > ',array_reverse($category));
      }
    }

    $categories[$categoryId] = array('parents' => $cntParents, 'name' => $name);
  }
  return $categories[$categoryId];
}

function ak_clean($field,$filter_html = true) {
  if ($filter_html) {
    $pattern = array();
    $replacement = array();
    $pattern[] = "/<[^>]+>/"; $replacement[] = " ";
    $pattern[] = "/  +/"; $replacement[] = " ";
    $field = preg_replace($pattern,$replacement,$field);
  }
  $from = array('"',"\r","\n","\\");
  $to =   array('""',""," ","");
  return str_replace($from,$to,$field);
}

function ak_csv_export($data) {
  ob_start();
  $header = '"' . ENGINE_NAME . ' ' . _PS_VERSION_ . ' (v' . AK_VERSION . ') manufacturer";"name";"category";"product_url";"price";"image_url";"description";"ean13";"upc";"reference";"supplier_reference";"currency";"stock";"delivery_price";"weight"';
  echo "$header\n";
  foreach ($data as $line) {
    foreach ($line as $k => $field) {
      if (!empty($field)) {
        echo '"';
        echo $field;
        echo '"';
      }
      if ($k == 'weight') {
        echo "\n";
      } else {
        echo ';';
      }
    }
  }
  $filename = basename($_SERVER['SCRIPT_NAME'],'.php');
  $length = ob_get_length();
  header('HTTP/1.0 200 OK');
  header('Cache-Control: no-cache');
  header('Content-Type: text/csv');
  header("Content-Disposition: attachment; filename={$filename}.csv");
  header('Content-Encoding: identity');
  header("Content-Length: $length");
  ob_end_flush();
  exit;
}

function ak_error($msg) {
  header('Cache-Control: no-cache');
  header('Content-Type: text/html; charset=utf-8');
  echo "<html><head><title>Export error (" . VERSION . ")</title></head><body>";
  echo "<p style=\"padding:0;margin:50px;text-align:center;font-weight:bold;\">$msg</p>";
  echo "</body></html>";
  flush();
  exit;
}

?>
Edited by slates (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

ez nagyon jó lenne, de a kép elérhetőség valamiért nem jó.

Share this post


Link to post
Share on other sites

Az arukereso.hu honlapnak minek kell adat a termék raktárkészlet mennyiségéről?

Én kitöröltem a darabra vonatkozó lekérdezést.

Share this post


Link to post
Share on other sites

Az arukereso.hu honlapnak minek kell adat a termék raktárkészlet mennyiségéről?

Én kitöröltem a darabra vonatkozó lekérdezést.

 

Azért mondjuk, hogy olyan termékedre ne érkezzen kattintás, amelyik nincs raktáron, nincs belőle készleted.

  • Like 1

Share this post


Link to post
Share on other sites

Most megnéztem, mert úgy gondoltam át lehet adni azt "is", hogy raktáron van-e vagy sem (elkerülvén ezzel a fenti problémát a darabszám privát körben való megtartása mellett) de nem látok most hirtelen ilyen változót.

Share this post


Link to post
Share on other sites

Sziasztok!

 

Rég nem frissült ez a téma. Én az 1.5 ös árukereső php kódot próbáltam 1.6 hoz , de csak egy terméket dob ki. Valaki tud bármelyik árösszehasonlító oldalhoz scriptet? 

Fizetnék is érte ha jó. Jelenleg csak a shopmania-t tudom használni. Az SQL lekérdezéssel próbálkoztam adminban, de valamiért üres sorokkal telerakja.

 

Köszi

Share this post


Link to post
Share on other sites

Az arukereső modult használja valaki?

Kérdés az lenne mennyire jó? Működik szépen?

Edited by Fecka (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More