function __construct($stats_version, $ebay_profile) { if (!$ebay_profile) { return; } $this->stats_version = $stats_version; $this->id_ebay_profile = (int) $ebay_profile->id; $this->data = array('id' => sha1($this->_getDefaultShopUrl()), 'profile' => $ebay_profile->id, 'ebay_username' => sha1(Configuration::get('EBAY_IDENTIFIER')), 'ebay_site' => $ebay_profile->ebay_site_id, 'is_multishop' => version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive(), 'install_date' => Configuration::get('EBAY_INSTALL_DATE'), 'nb_listings' => EbayProduct::getNbProducts($ebay_profile->id), 'percent_of_catalog' => EbayProduct::getPercentOfCatalog($ebay_profile), 'nb_prestashop_categories' => EbayCategoryConfiguration::getNbPrestashopCategories($ebay_profile->id), 'nb_ebay_categories' => EbayCategoryConfiguration::getNbEbayCategories($ebay_profile->id), 'nb_optional_item_specifics' => EbayCategorySpecific::getNbOptionalItemSpecifics($ebay_profile->id), 'nb_national_shipping_services' => EbayShipping::getNbNationalShippings($ebay_profile->id), 'nb_international_shipping_services' => EbayShipping::getNbInternationalShippings($ebay_profile->id), 'date_add' => date('Y-m-d H:i:s'), 'Configuration' => EbayConfiguration::getAll($ebay_profile->id, array('EBAY_PAYPAL_EMAIL')), 'return_policy' => $ebay_profile->getReturnsPolicyConfiguration()->ebay_returns_description == '' ? 0 : 1, 'ps_version' => _PS_VERSION_); $this->date_add = date('Y-m-d H:i:s'); }
public static function getExistingInternationalCarrier($id_ebay_profile) { $existing_international_carriers = EbayShipping::getInternationalShippings($id_ebay_profile); foreach ($existing_international_carriers as $key => &$carrier) { //get All shipping location associated $carrier['shippingLocation'] = DB::getInstance()->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'ebay_shipping_international_zone WHERE `id_ebay_profile` = ' . (int) $id_ebay_profile . ' AND id_ebay_shipping = \'' . (int) $carrier['id_ebay_shipping'] . '\''); } return $existing_international_carriers; }
public static function getShippingTabConfiguration($id_ebay_profile) { $ebay = new Ebay(); $shipping_national = EbayShipping::getNationalShippings($id_ebay_profile); if (!is_array($shipping_national) || count($shipping_national) == 0) { return array('indicator' => 'wrong', 'indicatorBig' => 'wrong', 'message' => $ebay->l('You must at least configure one domestic shipping service', 'ebayvalidatortab')); } $shipping_international = EbayShipping::getInternationalShippings($id_ebay_profile); if (!EbayShipping::internationalShippingsHaveZone($shipping_international)) { return array('indicator' => 'wrong', 'indicatorBig' => 'wrong', 'message' => $ebay->l('Your international shipping must at least have one zone configured', 'ebayvalidatortab')); } if (count($shipping_international) == 0) { return array('indicator' => 'success', 'indicatorBig' => 'mind', 'message' => $ebay->l('You could benefit to configure international shipping services', 'ebayvalidatortab')); } return array('indicator' => 'success'); }
private static function _getShippingDetailsForProduct($product, $ebay_profile) { $national_ship = array(); $international_ship = array(); //Get National Informations : service, costs, additional costs, priority $service_priority = 1; foreach (EbayShipping::getNationalShippings($ebay_profile->id, $product->id) as $carrier) { $national_ship[$carrier['ebay_carrier']] = array('servicePriority' => $service_priority, 'serviceAdditionalCosts' => $carrier['extra_fee'], 'serviceCosts' => EbaySynchronizer::_getShippingPriceForProduct($product, $carrier['id_zone'], $carrier['ps_carrier'])); $service_priority++; } //Get International Informations $service_priority = 1; foreach (EbayShipping::getInternationalShippings($ebay_profile->id, $product->id) as $carrier) { $international_ship[$carrier['ebay_carrier']] = array('servicePriority' => $service_priority, 'serviceAdditionalCosts' => $carrier['extra_fee'], 'serviceCosts' => EbaySynchronizer::_getShippingPriceForProduct($product, $carrier['id_zone'], $carrier['ps_carrier']), 'locationsToShip' => EbayShippingInternationalZone::getIdEbayZonesByIdEbayShipping($ebay_profile->id, $carrier['id_ebay_shipping'])); $service_priority++; } return array('excludedZone' => EbayShippingZoneExcluded::getExcluded($ebay_profile->id), 'nationalShip' => $national_ship, 'internationalShip' => $international_ship); }
public function importOrders($orders) { $errors_email = array(); foreach ($orders as $order) { $errors = array(); if (!$order->isCompleted()) { $message = $this->l('Status not complete, amount less than 0.1 or no matching product'); $errors[] = $message; $order->addErrorMessage($message); continue; } if ($order->exists()) { $message = $this->l('Order already imported'); $errors[] = $message; $order->addErrorMessage($message); continue; } // no order in ebay order table with this order_ref if (!$order->hasValidContact()) { $message = $this->l('Invalid e-mail'); $errors[] = $message; $order->addErrorMessage($message); continue; } if (!$order->hasAllProductsWithAttributes()) { $message = $this->l('Could not find the products in database'); $errors[] = $message; $order->addErrorMessage($message); continue; } if ($this->is_multishop) { $shops_data = $order->getProductsAndProfileByShop(); $id_shops = array_keys($shops_data); if (count($id_shops) > 1) { $product_ids = $order->getProductIds(); $first_id_shop = $id_shops[0]; if (version_compare(_PS_VERSION_, '1.5', '>')) { $sql = 'SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_shop` ps WHERE ps.`id_shop` = ' . (int) $first_id_shop . ' AND ps.`active` = 1 AND ps.`id_product` IN (' . implode(',', $product_ids) . ')'; } else { $sql = 'SELECT count(*) FROM `' . _DB_PREFIX_ . 'product` p WHERE p.`active` = 1 AND p.`id_product` IN (' . implode(',', $product_ids) . ')'; } $nb_products_in_shop = Db::getInstance()->getValue($sql); if ($nb_products_in_shop == count($product_ids)) { $id_shops = array($first_id_shop); $has_shared_customers = true; } else { $sql = 'SELECT count(*) FROM `' . _DB_PREFIX_ . 'shop` s INNER JOIN `' . _DB_PREFIX_ . 'shop_group` sg ON s.`id_shop_group` = sg.`id_shop_group` AND sg.`share_customer` = 1'; $nb_shops_sharing = Db::getInstance()->getValue($sql); $has_shared_customers = $nb_shops_sharing == count($id_shops); } } else { $has_shared_customers = true; } } else { $default_shop = Configuration::get('PS_SHOP_DEFAULT') ? Configuration::get('PS_SHOP_DEFAULT') : 1; $id_shops = array($default_shop); $has_shared_customers = true; } $customer_ids = array(); if ($has_shared_customers) { // in case of shared customers in multishop, we take the profile of the first shop if ($this->is_multishop) { $shop_data = reset($shops_data); $ebay_profile = new EbayProfile($shop_data['id_ebay_profiles'][0]); } else { $ebay_profile = EbayProfile::getCurrent(); } $id_customer = $order->getOrAddCustomer($ebay_profile); $id_address = $order->updateOrAddAddress($ebay_profile); $customer_ids[] = $id_customer; // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer); $customer_clear = new Customer(); if (method_exists($customer_clear, 'clearCache')) { $customer_clear->clearCache(true); } } foreach ($id_shops as $id_shop) { if ($this->is_multishop) { $id_ebay_profile = (int) $shops_data[$id_shop]['id_ebay_profiles'][0]; $ebay_profile = new EbayProfile($id_ebay_profile); } else { $ebay_profile = EbayProfile::getCurrent(); } if (!$has_shared_customers) { $id_customer = $order->getOrAddCustomer($ebay_profile); $id_address = $order->updateOrAddAddress($ebay_profile); $customer_ids[] = $id_customer; // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = ' . (int) $id_customer); $customer_clear = new Customer(); if (method_exists($customer_clear, 'clearCache')) { $customer_clear->clearCache(true); } } $cart = $order->addCart($ebay_profile, $this->ebay_country); //Create a Cart for the order if (!$order->updateCartQuantities($ebay_profile)) { $order->deleteCart($ebay_profile->id_shop); $message = $this->l('Could not add product to cart (maybe your stock quantity is 0)'); $errors[] = $message; $order->addErrorMessage($message); continue; } // if the carrier is disabled, we enable it for the order validation and then disable it again $carrier = new Carrier((int) EbayShipping::getPsCarrierByEbayCarrier($ebay_profile->id, $order->shippingService)); if (!$carrier->active) { $carrier->active = true; $carrier->save(); $has_disabled_carrier = true; } else { $has_disabled_carrier = false; } // Validate order $id_order = $order->validate($ebay_profile->id_shop, $this->ebay_profile->id); // we now disable the carrier if required if ($has_disabled_carrier) { $carrier->active = false; $carrier->save(); } // Update price (because of possibility of price impact) $order->updatePrice($ebay_profile); } $order->add($this->ebay_profile->id); if (!version_compare(_PS_VERSION_, '1.5', '>')) { foreach ($order->getProducts() as $product) { $this->hookAddProduct(array('product' => new Product((int) $product['id_product']))); } } foreach ($customer_ids as $id_customer) { // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order->getEmail())), 'UPDATE', '`id_customer` = ' . (int) $id_customer); } } $orders_ar = array(); foreach ($orders as $order) { $orders_ar[] = array('id_order_ref' => $order->getIdOrderRef(), 'id_order_seller' => $order->getIdOrderSeller(), 'amount' => $order->getAmount(), 'status' => $order->getStatus(), 'date' => $order->getDate(), 'email' => $order->getEmail(), 'products' => $order->getProducts(), 'error_messages' => $order->getErrorMessages()); } file_put_contents(dirname(__FILE__) . '/log/orders.php', "<?php\n\n" . '$dateLastImport = ' . '\'' . date('d/m/Y H:i:s') . "';\n\n" . '$orders = ' . var_export($orders_ar, true) . ";\n\n"); if (Configuration::get('EBAY_ACTIVATE_MAILS') && $errors_email) { $data = ''; foreach ($errors_email as $e) { $data .= '<p>Id order : <strong>' . $e['id_order_seller'] . '</strong></p><ul>'; foreach ($e['messages'] as $m) { $data .= '<li>' . $m . '</li>'; } $data .= '</ul><br/>'; } Mail::Send((int) Configuration::get('PS_LANG_DEFAULT'), 'errorsImportEbay', Mail::l('Errors import', (int) Configuration::get('PS_LANG_DEFAULT')), array('{errors_email}' => $data), strval(Configuration::get('PS_SHOP_EMAIL')), null, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), null, null, dirname(__FILE__) . '/views/templates/mails/'); } }
/** * Display form for the shipping screen * **/ private function _displayFormShipping() { $configKeys = array('EBAY_PAYPAL_EMAIL', 'EBAY_CATEGORY_LOADED', 'EBAY_SECURITY_TOKEN', 'EBAY_DELIVERY_TIME', 'EBAY_ZONE_NATIONAL', 'EBAY_ZONE_INTERNATIONAL', 'PS_LANG_DEFAULT'); // Load prestashop ebay's configuration $configs = Configuration::getMultiple($configKeys); // Check if the module is configured if (!isset($configs['EBAY_PAYPAL_EMAIL']) || $configs['EBAY_PAYPAL_EMAIL'] === false) { return $this->display(dirname(__FILE__), '/views/templates/hook/error_paypal_email.tpl'); } $nb_shipping_zones_excluded = DB::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'ebay_shipping_zone_excluded'); if (!$nb_shipping_zones_excluded) { $this->_loadEbayExcludedLocations(); } $module_filters = version_compare(_PS_VERSION_, '1.4.5', '>=') ? Carrier::CARRIERS_MODULE : 2; //INITIALIZE CACHE $psCarrierModule = Carrier::getCarriers($configs['PS_LANG_DEFAULT'], false, false, false, null, $module_filters); $url_vars = array('id_tab' => '3', 'section' => 'shipping'); if (version_compare(_PS_VERSION_, '1.5', '>')) { $url_vars['controller'] = Tools::safeOutput(Tools::getValue('controller')); } else { $url_vars['tab'] = Tools::safeOutput(Tools::getValue('tab')); } $this->smarty->assign(array('eBayCarrier' => $this->_getCarriers(), 'psCarrier' => Carrier::getCarriers($configs['PS_LANG_DEFAULT']), 'psCarrierModule' => $psCarrierModule, 'existingNationalCarrier' => EbayShipping::getNationalShippings(), 'existingInternationalCarrier' => $this->_getExistingInternationalCarrier(), 'deliveryTime' => $configs['EBAY_DELIVERY_TIME'], 'prestashopZone' => Zone::getZones(), 'excludeShippingLocation' => $this->_cacheEbayExcludedLocation(), 'internationalShippingLocations' => $this->_getInternationalShippingLocations(), 'deliveryTimeOptions' => $this->_getDeliveryTimeOptions(), 'formUrl' => $this->_getUrl($url_vars), 'ebayZoneNational' => isset($configs['EBAY_ZONE_NATIONAL']) ? $configs['EBAY_ZONE_NATIONAL'] : false, 'ebayZoneInternational' => isset($configs['EBAY_ZONE_INTERNATIONAL']) ? $configs['EBAY_ZONE_INTERNATIONAL'] : false, 'ebay_token' => $configs['EBAY_SECURITY_TOKEN'])); return $this->display(dirname(__FILE__), '/views/templates/hook/shipping.tpl'); }
public function updatePrice() { $total_price_tax_excl = 0; $total_shipping_tax_incl = 0; $total_shipping_tax_excl = 0; $id_carrier = (int) EbayShipping::getPsCarrierByEbayCarrier($this->shippingService); if (version_compare(_PS_VERSION_, '1.4.0.5', '<')) { $carrier_tax_rate = (double) $this->_getTaxByCarrier((int) $id_carrier); } else { $carrier_tax_rate = (double) Tax::getCarrierTaxRate((int) $id_carrier); } foreach ($this->product_list as $product) { if (version_compare(_PS_VERSION_, '1.4.0.5', '<')) { $tax_rate = (double) $this->_getTaxByProduct((int) $product['id_product']); } else { $tax_rate = (double) Tax::getProductTaxRate((int) $product['id_product']); } $coef_rate = 1 + $tax_rate / 100; $detail_data = array('product_price' => (double) ($product['price'] / $coef_rate), 'unit_price_tax_incl' => (double) $product['price'], 'unit_price_tax_excl' => (double) ($product['price'] / $coef_rate), 'total_price_tax_incl' => (double) ($product['price'] * $product['quantity']), 'total_price_tax_excl' => (double) ($product['price'] / $coef_rate * $product['quantity']), 'reduction_percent' => 0, 'reduction_amount' => 0); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail', $detail_data, 'UPDATE', '`id_order` = ' . (int) $this->id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute']); if (version_compare(_PS_VERSION_, '1.5', '>')) { $detail_tax_data = array('unit_amount' => (double) ($product['price'] - $product['price'] / $coef_rate), 'total_amount' => (double) ($product['price'] - $product['price'] / $coef_rate) * $product['quantity']); DB::getInstance()->autoExecute(_DB_PREFIX_ . 'order_detail_tax', $detail_tax_data, 'UPDATE', '`id_order_detail` = (SELECT `id_order_detail` FROM `' . _DB_PREFIX_ . 'order_detail` WHERE `id_order` = ' . (int) $this->id_order . ' AND `product_id` = ' . (int) $product['id_product'] . ' AND `product_attribute_id` = ' . (int) $product['id_product_attribute'] . ') '); } $total_price_tax_excl += (double) ($product['price'] / $coef_rate * $product['quantity']); // ebay get one shipping cost by product $total_shipping_tax_incl += $this->shippingServiceCost; $total_shipping_tax_excl += $this->shippingServiceCost / (1 + $carrier_tax_rate / 100); } $data = array('total_paid' => (double) $this->amount, 'total_paid_real' => (double) $this->amount, 'total_products' => (double) $total_price_tax_excl, 'total_products_wt' => (double) ($this->amount - $this->shippingServiceCost), 'total_shipping' => (double) $total_shipping_tax_incl, 'total_shipping_tax_incl' => (double) $total_shipping_tax_incl, 'total_shipping_tax_excl' => (double) $total_shipping_tax_excl); if ((double) $this->shippingServiceCost == 0) { $data = array_merge($data, array('total_shipping_tax_excl' => 0, 'total_shipping_tax_incl' => 0)); } if (version_compare(_PS_VERSION_, '1.5', '>')) { $order = new Order((int) $this->id_order); $data_old = $data; $data = array_merge($data, array('total_paid_tax_incl' => (double) $this->amount, 'total_paid_tax_excl' => (double) ($total_price_tax_excl + $order->total_shipping_tax_excl))); // Update Incoice $invoice_data = $data; unset($invoice_data['total_paid'], $invoice_data['total_paid_real'], $invoice_data['total_shipping']); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_invoice', $invoice_data, 'UPDATE', '`id_order` = ' . (int) $this->id_order); // Update payment $payment_data = array('amount' => (double) $this->amount); Db::getInstance()->autoExecute(_DB_PREFIX_ . 'order_payment', $payment_data, 'UPDATE', '`order_reference` = "' . pSQL($order->reference) . '" '); } return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'orders', $data, 'UPDATE', '`id_order` = ' . (int) $this->id_order); }
function postProcess() { //Update excluded location if (Tools::getValue('excludeLocationHidden')) { Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'ebay_shipping_zone_excluded SET excluded = 0 WHERE `id_ebay_profile` = ' . (int) $this->ebay_profile->id); if ($exclude_locations = Tools::getValue('excludeLocation')) { $locations = array_keys($exclude_locations); $where = 'location IN ("' . implode('","', array_map('pSQL', $locations)) . '")'; $where .= ' AND `id_ebay_profile` = ' . (int) $this->ebay_profile->id; if (version_compare(_PS_VERSION_, '1.5', '>')) { DB::getInstance()->update('ebay_shipping_zone_excluded', array('excluded' => 1), $where); } else { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_shipping_zone_excluded', array('excluded' => 1), 'UPDATE', $where); } } } //Update global information about shipping (delivery time, ...) $this->ebay_profile->setConfiguration('EBAY_DELIVERY_TIME', Tools::getValue('deliveryTime')); //Update Shipping Method for National Shipping (Delete And Insert) EbayShipping::truncate($this->ebay_profile->id); if ($ebay_carriers = Tools::getValue('ebayCarrier')) { $ps_carriers = Tools::getValue('psCarrier'); $extra_fees = Tools::getValue('extrafee'); foreach ($ebay_carriers as $key => $ebay_carrier) { if (!empty($ebay_carrier) && !empty($ps_carriers[$key])) { //Get id_carrier and id_zone from ps_carrier $infos = explode('-', $ps_carriers[$key]); EbayShipping::insert($this->ebay_profile->id, $ebay_carrier, $infos[0], $extra_fees[$key], $infos[1]); } } } Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'ebay_shipping_international_zone WHERE `id_ebay_profile` = ' . (int) $this->ebay_profile->id); if ($ebay_carriers_international = Tools::getValue('ebayCarrier_international')) { $ps_carriers_international = Tools::getValue('psCarrier_international'); $extra_fees_international = Tools::getValue('extrafee_international'); $international_shipping_locations = Tools::getValue('internationalShippingLocation'); $international_excluded_shipping_locations = Tools::getValue('internationalExcludedShippingLocation'); foreach ($ebay_carriers_international as $key => $ebay_carrier_international) { if (!empty($ebay_carrier_international) && !empty($ps_carriers_international[$key]) && isset($international_shipping_locations[$key])) { $infos = explode('-', $ps_carriers_international[$key]); EbayShipping::insert($this->ebay_profile->id, $ebay_carrier_international, $infos[0], $extra_fees_international[$key], $infos[1], true); $last_id = EbayShipping::getLastShippingId($this->ebay_profile->id); foreach (array_keys($international_shipping_locations[$key]) as $id_ebay_zone) { EbayShippingInternationalZone::insert($this->ebay_profile->id, $last_id, $id_ebay_zone); } } } } }