/** * 2007-2015 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <*****@*****.**> * @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ function upgrade_module_1_8($module) { include dirname(__FILE__) . '/sql/sql-upgrade-1-8.php'; if (!empty($sql) && is_array($sql)) { foreach ($sql as $request) { if (!Db::getInstance()->execute($request)) { return false; } } } // upgrade existing profiles $profiles = EbayProfile::getProfilesByIdShop(); foreach ($profiles as $profile) { $ebay_profile = new EbayProfile($profile['id_ebay_profile']); // set id_lang if not set if (!$profile['id_lang']) { $ebay_profile->id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $ebay_profile->save(); } if ($ebay_profile->ebay_site_id) { $ebay_shop_country = EbayCountrySpec::getIsoCodeBySiteId($ebay_profile->ebay_site_id); $ebay_site_id = $ebay_profile->ebay_site_id; } else { if ($ebay_profile->getConfiguration('EBAY_COUNTRY_DEFAULT')) { $ebay_shop_country = $ebay_profile->getConfiguration('EBAY_COUNTRY_DEFAULT'); } else { $ebay_shop_country = 'fr'; $ebay_profile->setConfiguration('EBAY_COUNTRY_DEFAULT', $ebay_shop_country); } $ebay_profile->ebay_site_id = EbayCountrySpec::getSiteIdByIsoCode($ebay_shop_country); $ebay_profile->save(); $ebay_site_id = $ebay_profile->ebay_site_id; } // we set EBAY_SHOP_COUNTRY $ebay_profile->setConfiguration('EBAY_SHOP_COUNTRY', $ebay_shop_country); // update ebay_category Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_category', array('id_country' => $ebay_site_id), 'UPDATE'); if (Configuration::get('EBAY_CATEGORY_LOADED')) { Configuration::updateValue('EBAY_CATEGORY_LOADED_' . $ebay_site_id, 1, false, 0, 0); } // update ebay_category_specific Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_category_specific', array('ebay_site_id' => $ebay_site_id), 'UPDATE'); // update ebay_product_configuration $ebay_profile = EbayProfile::getCurrent(); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_product_configuration', array('id_ebay_profile' => $ebay_profile->id), 'UPDATE'); } return true; }
public static function getByLangShopSiteAndUsername($id_lang, $id_shop, $ebay_country, $ebay_user_identifier, $template_content) { $ebay_country_spec = EbayCountrySpec::getInstanceByKey($ebay_country); $ebay_site_id = $ebay_country_spec->getSiteID(); $sql = 'SELECT `id_ebay_profile` FROM `' . _DB_PREFIX_ . 'ebay_profile` ep WHERE ep.`id_lang` = ' . (int) $id_lang . ' AND ep.`id_shop` = ' . (int) $id_shop . ' AND ep.`ebay_site_id` = ' . (int) $ebay_site_id . ' AND ep.`ebay_user_identifier` = \'' . pSQL($ebay_user_identifier) . '\''; if ($id_profile = Db::getInstance()->getValue($sql)) { return new EbayProfile($id_profile); } // otherwise create the eBay profile $ebay_profile = new EbayProfile(); $ebay_profile->id_lang = $id_lang; $ebay_profile->id_shop = $id_shop; $ebay_profile->ebay_site_id = $ebay_site_id; $ebay_profile->ebay_user_identifier = $ebay_user_identifier; $returns_policy_configuration = new EbayReturnsPolicyConfiguration(); $returns_policy_configuration->save(); $ebay_profile->id_ebay_returns_policy_configuration = $returns_policy_configuration->id; $ebay_profile->save(); $ebay_profile->setConfiguration('EBAY_COUNTRY_DEFAULT', $ebay_country); $ebay_profile->setPicturesSettings(); $ebay_profile->setDefaultConfig($template_content); return $ebay_profile; }
public static function syncProducts($products, $context, $id_lang, $request_context = null, $log_type = false) { if (!$products) { return; } $date = date('Y-m-d H:i:s'); // Get errors back if (file_exists(dirname(__FILE__) . '/../log/syncError.php')) { include dirname(__FILE__) . '/../log/syncError.php'; } $tab_error = array(); // Up the time limit @set_time_limit(3600); $product_ids = array_map(array('EbaySynchronizer', 'getIdProduct'), $products); if (method_exists('Cache', 'clean')) { Cache::clean('StockAvailable::getQuantityAvailableByProduct_*'); } foreach ($products as $p) { $product = new Product((int) $p['id_product'], true, $id_lang); $product_configuration = EbayProductConfiguration::getByProductIdAndProfile($p['id_product'], $p['id_ebay_profile']); // make sure that product exists in the db and has a default category if (!Validate::isLoadedObject($product) || !$product->id_category_default) { continue; } $quantity_product = EbaySynchronizer::_getProductQuantity($product, (int) $p['id_product']); $ebay_profile = new EbayProfile((int) $p['id_ebay_profile']); if (!$ebay_profile->getConfiguration('EBAY_HAS_SYNCED_PRODUCTS')) { } $ebay_profile->setConfiguration('EBAY_HAS_SYNCED_PRODUCTS', 1); $ebay_category = EbaySynchronizer::_getEbayCategory($product->id_category_default, $ebay_profile); $variations = EbaySynchronizer::_loadVariations($product, $ebay_profile, $context, $ebay_category); $ebay = new EbayRequest((int) $p['id_ebay_profile'], $request_context); if (!$product->active || $product_configuration && $product_configuration['blacklisted']) { // try to stop sale on eBay $ebay = EbaySynchronizer::endProductOnEbay($ebay, $ebay_profile, $context, $id_lang, null, $product->id); if (!empty($ebay->error)) { $tab_error = EbaySynchronizer::_updateTabError($ebay->error, str_replace('&', '&', $product->name)); if ($log_type) { EbayLog::write('Error: ' . $ebay->error, $log_type); } } continue; } $pictures = EbaySynchronizer::_getPictures($product, $ebay_profile, $id_lang, $context, $variations); // Load basic price list($price, $price_original) = EbaySynchronizer::_getPrices($product->id, $ebay_category->getPercent(), $ebay_profile); $conditions = $ebay_category->getConditionsValues($p['id_ebay_profile']); $ebay_store_category_id = pSQL(EbayStoreCategoryConfiguration::getEbayStoreCategoryIdByIdProfileAndIdCategory($ebay_profile->id, $product->id_category_default)); // Generate array and try insert in database $data = array('price' => $price, 'quantity' => $quantity_product, 'categoryId' => $ebay_category->getIdCategoryRef(), 'variations' => $variations, 'pictures' => $pictures['general'], 'picturesMedium' => $pictures['medium'], 'picturesLarge' => $pictures['large'], 'condition' => $conditions[$product->condition], 'shipping' => EbaySynchronizer::_getShippingDetailsForProduct($product, $ebay_profile), 'id_lang' => $id_lang, 'real_id_product' => (int) $p['id_product'], 'ebay_store_category_id' => $ebay_store_category_id); $data = array_merge($data, EbaySynchronizer::_getProductData($product, $ebay_profile)); // Fix hook update product if (Tools::getValue('id_product_attribute')) { $id_product_attribute_fix = (int) Tools::getValue('id_product_attribute'); $key = $product_id . '-' . $id_product_attribute_fix . '_' . $ebay_profile->id; if (isset($data['variations'][$key]['quantity'])) { $data['variations'][$key]['quantity'] = EbaySynchronizer::_fixHookUpdateProduct($context, $product_id, $data['variations'][$key]['quantity']); } } // Price Update if (isset($p['noPriceUpdate'])) { $data['noPriceUpdate'] = $p['noPriceUpdate']; } $clean_percent = $ebay_category->getCleanPercent(); // Save percent and price discount if ($clean_percent < 0) { $data['price_original'] = round($price_original, 2); // $data['price_percent'] = round($clean_percent); } elseif ($price_original > $price) { $data['price_original'] = round($price_original, 2); } if (isset($data['price_original'])) { $data['price_percent'] = round(($price_original - $price) / $price_original * 100.0); } $data['description'] = EbaySynchronizer::_getEbayDescription($product, $ebay_profile, $id_lang); // Export to eBay $ebay = EbaySynchronizer::_exportProductToEbay($product, $data, $p['id_ebay_profile'], $ebay_category, $ebay, $date, $context, $id_lang); if (!empty($ebay->error)) { $tab_error = EbaySynchronizer::_updateTabError($ebay->error, $data['name']); if ($log_type) { EbayLog::write('Error: ' . $ebay->error, $log_type); } } elseif ($log_type) { EbayLog::write('Success', $log_type); } if ($request_context == 'CRON') { Configuration::updateValue('NB_PRODUCTS_LAST', (int) Configuration::get('NB_PRODUCTS_LAST') + 1); } } if (count($tab_error)) { if (isset($all_error)) { foreach ($all_error as $key => $value) { if (isset($tab_error[$key])) { $tab_error[$key]['products'] = array_merge($all_error[$key]['products'], $tab_error[$key]['products']); } else { $tab_error[$key] = $all_error[$key]; } } } file_put_contents(dirname(__FILE__) . '/../log/syncError.php', '<?php $all_error = ' . var_export($tab_error, true) . '; ' . ($ebay->itemConditionError ? '$itemConditionError = true; ' : '$itemConditionError = false;') . ' ?>'); } }
/** * Updates the template image links since the image files have moved * */ function upgrade_module_1_7($module) { include dirname(__FILE__) . '/sql/sql-upgrade-1-7.php'; if (!empty($sql) && is_array($sql)) { foreach ($sql as $request) { if (!Db::getInstance()->execute($request)) { return false; } } } Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'ebay_shipping SET id_zone = ' . (int) Configuration::get('EBAY_ZONE_NATIONAL') . ' WHERE international = 0'); Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'ebay_shipping SET id_zone = ' . (int) Configuration::get('EBAY_ZONE_INTERNATIONAL') . ' WHERE international = 1'); // create default profile(s) $is_multishop = version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive(); $id_shop_default = (int) Configuration::get('PS_SHOP_DEFAULT') ? (int) Configuration::get('PS_SHOP_DEFAULT') : 1; // handle default returns policy if (!($id_returns_policy_configuration = EbayReturnsPolicyConfiguration::getDefaultObjectId())) { $id_returns_policy_configuration = EbayReturnsPolicyConfiguration::createPreviousDefaultConfiguration(); } // handle default profile if (version_compare(_PS_VERSION_, '1.5', '<')) { $id_shops = array('1' => '1'); } else { $id_shops = Shop::getShops(false, null, false); } foreach (array_keys($id_shops) as $id_shop) { if (!($profile = EbayProfile::getOneByIdShop($id_shop))) { $profile = new EbayProfile(); $profile->id_shop = $id_shop; } $profile->ebay_user_identifier = Configuration::get('EBAY_IDENTIFIER'); $ebay_country = EbayCountrySpec::getInstanceByKey(Configuration::get('EBAY_COUNTRY_DEFAULT')); $profile->ebay_site = $ebay_country->getSiteExtension(); if ($id_shop_default == $id_shop) { $profile->id_ebay_returns_policy_configuration = $id_returns_policy_configuration; } else { $profile->id_ebay_returns_policy_configuration = EbayReturnsPolicyConfiguration::createPreviousDefaultConfiguration(); } $profile->save(); if ($id_shop_default == $id_shop) { $id_default_ebay_profile = $profile->id; } $configurations_to_update = array('EBAY_COUNTRY_DEFAULT', 'EBAY_ORDER_LAST_UPDATE', 'EBAY_DELIVERY_TIME', 'EBAY_PICTURE_SIZE_DEFAULT', 'EBAY_PICTURE_SIZE_SMALL', 'EBAY_PICTURE_SIZE_BIG', 'EBAY_LISTING_DURATION', 'EBAY_AUTOMATICALLY_RELIST', 'EBAY_LAST_RELIST', 'EBAY_SYNC_PRODUCTS_MODE', 'EBAY_ZONE_NATIONAL', 'EBAY_ZONE_INTERNATIONAL', 'EBAY_SHOP', 'EBAY_SHOP_POSTALCODE', 'EBAY_SYNC_OPTION_RESYNC', 'EBAY_SYNC_MODE', 'EBAY_SYNC_LAST_PRODUCT', 'EBAY_SPECIFICS_LAST_UPDATE', 'EBAY_PAYPAL_EMAIL'); $configuration_to_update_html = array('EBAY_PRODUCT_TEMPLATE'); EbayConfiguration::PSConfigurationsToEbayConfigurations($profile->id, $configurations_to_update, $configuration_to_update_html); $profile->setConfiguration('EBAY_PRODUCT_TEMPLATE_TITLE', '{TITLE}'); } $configurations_to_delete = array_merge($configurations_to_update, array('EBAY_RETURNS_DESCRIPTION', 'EBAY_RETURNS_ACCEPTED_OPTION', 'EBAY_RETURNS_WITHIN', 'EBAY_RETURNS_WHO_PAYS')); foreach ($configurations_to_delete as $name) { Configuration::deleteByName($name); } // ebay_category_configuration table $tables = array('ebay_category_configuration', 'ebay_shipping_zone_excluded', 'ebay_shipping_international_zone', 'ebay_category_condition', 'ebay_category_condition_configuration', 'ebay_shipping', 'ebay_product'); if (version_compare(_PS_VERSION_, '1.5', '<')) { foreach ($tables as $table) { Db::getInstance()->autoExecute(_DB_PREFIX_ . $table, array('id_ebay_profile' => $id_default_ebay_profile), 'UPDATE'); } } else { foreach ($tables as $table) { Db::getInstance()->update($table, array('id_ebay_profile' => $id_default_ebay_profile)); } } $sql = 'SELECT `id_ebay_order`, `id_order` FROM `' . _DB_PREFIX_ . 'ebay_order`'; $res = Db::getInstance()->executeS($sql); foreach ($res as $row) { $data = array('id_ebay_order' => $row['id_ebay_order'], 'id_order' => $row['id_order']); if (version_compare(_PS_VERSION_, '1.5', '<')) { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_order_order', $data, 'INSERT'); } else { Db::getInstance()->insert('ebay_order_order', $data, false, true, Db::REPLACE); } } $module->setConfiguration('EBAY_VERSION', $module->version); // TODO: at some point we need to remove the id_order column of ebay_order which becomes useless // but we cannot do it before the data have moved return true; }
} $id_ebay_profile = (int) Tools::getValue('profile'); $ebay_profile = new EbayProfile($id_ebay_profile); function loadItemsMap($row) { return $row['id']; } /* Fix for limit db sql request in time */ sleep(1); $category = new EbayCategory($ebay_profile, (int) Tools::getValue('ebay_category')); if (!$ebay_profile->getConfiguration('EBAY_SPECIFICS_LAST_UPDATE') || $ebay_profile->getConfiguration('EBAY_SPECIFICS_LAST_UPDATE') < date('Y-m-d\\TH:i:s', strtotime('-3 days')) . '.000Z') { $time = time(); $res = EbayCategorySpecific::loadCategorySpecifics($id_ebay_profile); $res &= EbayCategoryCondition::loadCategoryConditions($id_ebay_profile); if ($res) { $ebay_profile->setConfiguration('EBAY_SPECIFICS_LAST_UPDATE', date('Y-m-d\\TH:i:s.000\\Z'), false); } } $item_specifics = $category->getItemsSpecifics(); $item_specifics_ids = array_map('loadItemsMap', $item_specifics); if (count($item_specifics_ids)) { $sql = 'SELECT `id_ebay_category_specific_value` as id, `id_ebay_category_specific` as specific_id, `value` FROM `' . _DB_PREFIX_ . 'ebay_category_specific_value` WHERE `id_ebay_category_specific` in (' . implode(',', $item_specifics_ids) . ')'; $item_specifics_values = DB::getInstance()->executeS($sql); } else { $item_specifics_values = array(); } foreach ($item_specifics as &$item_specific) { foreach ($item_specifics_values as $value) { if ($item_specific['id'] == $value['specific_id']) {