示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Carrier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Carrier'])) {
         $model->attributes = $_POST['Carrier'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
/**
 * @param ShopGate $module
 *
 * @return bool
 */
function upgrade_module_2_9_52($module)
{
    $shopgateCarrierId = Configuration::get('SG_CARRIER_ID');
    /**
     * set current shopgate carrier as deleted
     */
    if ($shopgateCarrierId) {
        /** @var CarrierCore $carrier */
        $carrier = new Carrier($shopgateCarrierId);
        $carrier->deleted = true;
        $carrier->save();
    }
    $shopgateShippingModel = new ShopgateShipping($module);
    $shopgateShippingModel->createShopgateCarrier();
    $module->updateTables();
    return true;
}
    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        if (extension_loaded('curl') == false) {
            $this->_errors[] = $this->l('You have to enable the cURL extension on your server to install this module');
            return false;
        }
        include dirname(__FILE__) . '/sql/install.php';
        $carriers = Carrier::getCarriers($this->context->language->id);
        foreach ($carriers as $carrier) {
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'hf_free_shipping_pro_carriers`
					SET `id_carrier` = ' . $carrier['id_carrier'] . ',
						`show_not_free` = 1,
						`show_free` = 1';
            if (!Db::getInstance()->execute($sql)) {
                return false;
            }
            $carrier_to_update = new Carrier($carrier['id_carrier']);
            $carrier_to_update->need_range = 1;
            $carrier_to_update->shipping_external = true;
            $carrier_to_update->external_module_name = $this->name;
            $carrier_to_update->save();
        }
        return parent::install() && $this->registerHook('header') && $this->registerHook('backOfficeHeader') && $this->registerHook('updateCarrier') && $this->registerHook('displayAdminProductsExtra') && $this->registerHook('actionProductSave') && $this->registerHook('displayBackOfficeCategory') && $this->registerHook('displayBackOfficeFooter') && $this->registerHook('shoppingCart') && $this->registerHook('displayShoppingCartFooter');
    }
示例#4
0
 private function createCarriers()
 {
     $history_table = SeurLib::getLastSeurCarriers();
     if (empty($history_table) == false) {
         return $this->updateCarriers($history_table);
     }
     $carriers = array(array('name' => 'SEUR', 'active' => 1, 'type' => 'SEN', 'delay' => array('es' => 'Envío Urgente', 'fr' => 'Livraison Express', 'default' => 'Express Delivery')), array('name' => 'SEUR Puntos de Venta', 'active' => 0, 'type' => 'SEP', 'delay' => array('es' => 'Recogida en punto de venta', 'fr' => 'Retrait au point de venta', 'default' => 'Point of sale pickup')), array('name' => 'SEUR Canarias (M)', 'active' => 1, 'type' => 'SCN', 'delay' => array('es' => 'Envío a Islas Canarias', 'fr' => 'Livraison a Canary Islands', 'default' => 'Delivery to Canary Islands')), array('name' => 'SEUR Canarias (48/72)', 'active' => 1, 'type' => 'SCE', 'delay' => array('es' => 'Envío Urgente a Islas Canarias', 'fr' => 'Livraison Express a Canary Islands', 'default' => 'Express Delivery to Canary Islands')));
     foreach ($carriers as &$values) {
         $carrier = new Carrier();
         $carrier->name = $values['name'];
         $carrier->id_tax_rules_group = 1;
         $carrier->need_range = true;
         $carrier->is_module = true;
         $carrier->external_module_name = $this->name;
         $carrier->url = 'http://www.seur.com';
         $carrier->active = $values['active'];
         $languages = Language::getLanguages();
         foreach ($languages as $language) {
             if (isset($values['delay'][$language['iso_code']])) {
                 $carrier->delay[(int) $language['id_lang']] = $values['delay'][$language['iso_code']];
             } else {
                 $carrier->delay[(int) $language['id_lang']] = $values['delay']['default'];
             }
         }
         if ($carrier->save() == false) {
             return false;
         }
         $values['id'] = (int) $carrier->id;
         @copy(dirname(__FILE__) . '/img/logoSEUR.jpg', _PS_SHIP_IMG_DIR_ . (int) $carrier->id . '.jpg');
         $groups = array();
         foreach (Group::getGroups((int) Context::getContext()->language->id) as $group) {
             $groups[] = (int) $group['id_group'];
         }
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             if (!$this->setGroups14((int) $carrier->id, $groups)) {
                 return false;
             }
         } else {
             if (!$carrier->setGroups($groups)) {
                 return false;
             }
         }
     }
     SeurLib::updateSeurCarriers($carriers);
     return true;
 }
示例#5
0
    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/');
        }
    }
示例#6
0
 public function importOrders($orders)
 {
     foreach ($orders as $order) {
         if (!$order->isCompleted()) {
             $order->addErrorMessage($this->l('Status not complete, amount less than 0.1 or no matching product'));
             continue;
         }
         if ($order->exists()) {
             $order->addErrorMessage($this->l('Order already imported'));
             continue;
         }
         // no order in ebay order table with this order_ref
         if (!$order->hasValidContact()) {
             $order->addErrorMessage($this->l('Invalid e-mail'));
             continue;
         }
         $id_customer = $order->getOrAddCustomer();
         $id_address = $order->updateOrAddAddress();
         if (!$order->hasAllProductsWithAttributes()) {
             $order->addErrorMessage($this->l('Could not find the products in database'));
             continue;
         }
         $order->addCart($this->ebay_country);
         //Create a Cart for the order
         if (!$order->updateCartQuantities()) {
             $order->deleteCart();
             $order->addErrorMessage($this->l('Could not add product to cart (maybe your stock quantity is 0)'));
             continue;
         }
         // 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);
         }
         // if the carrier is disabled, we enable it for the order validation and then disable it again
         $carrier = new Carrier((int) EbayShipping::getPsCarrierByEbayCarrier($order->shippingService));
         if (!$carrier->active) {
             $carrier->active = true;
             $carrier->save();
             $has_disabled_carrier = true;
         }
         // Validate order
         $id_order = $order->validate();
         // we now disable the carrier if required
         if (isset($has_disabled_carrier) && $has_disabled_carrier) {
             $carrier->active = false;
             $carrier->save();
         }
         // Fix on sending e-mail
         Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($order->getEmail())), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
         // Update price (because of possibility of price impact)
         $order->updatePrice();
         $order->add();
         if (!version_compare(_PS_VERSION_, '1.5', '>')) {
             foreach ($order->getProducts() as $product) {
                 $this->hookAddProduct(array('product' => new Product((int) $product['id_product'])));
             }
         }
     }
     $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");
 }
 public static function install()
 {
     $id_carrier = (int) Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_ID);
     $carrier = self::getCarrierByReference((int) $id_carrier);
     if ($id_carrier && Validate::isLoadedObject($carrier)) {
         if (!$carrier->deleted) {
             return true;
         } else {
             $carrier->deleted = 0;
             return (bool) $carrier->save();
         }
     }
     $carrier_standard = new DpdPolandCarrierStandardService();
     $carrier = new Carrier();
     $carrier->name = $carrier_standard->module_instance->l('DPD domestic shipment - Standard', self::FILENAME);
     $carrier->active = 1;
     $carrier->is_free = 0;
     $carrier->shipping_handling = 1;
     $carrier->shipping_external = 1;
     $carrier->shipping_method = 1;
     $carrier->max_width = 0;
     $carrier->max_height = 0;
     $carrier->max_depth = 0;
     $carrier->max_weight = 0;
     $carrier->grade = 0;
     $carrier->is_module = 1;
     $carrier->need_range = 1;
     $carrier->range_behavior = 1;
     $carrier->external_module_name = $carrier_standard->module_instance->name;
     $carrier->url = _DPDPOLAND_TRACKING_URL_;
     $delay = array();
     foreach (Language::getLanguages(false) as $language) {
         $delay[$language['id_lang']] = $carrier_standard->module_instance->l('DPD domestic shipment - Standard', self::FILENAME);
     }
     $carrier->delay = $delay;
     if (!$carrier->save()) {
         return false;
     }
     $dpdpoland_carrier = new DpdPolandCarrier();
     $dpdpoland_carrier->id_carrier = (int) $carrier->id;
     $dpdpoland_carrier->id_reference = (int) $carrier->id;
     if (!$dpdpoland_carrier->save()) {
         return false;
     }
     if (!copy(_DPDPOLAND_IMG_DIR_ . DpdPolandCarrierStandardService::IMG_DIR . '/' . _DPDPOLAND_STANDARD_ID_ . '.' . DpdPolandCarrierStandardService::IMG_EXTENTION, _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
         return false;
     }
     $range_obj = $carrier->getRangeObject();
     $range_obj->id_carrier = (int) $carrier->id;
     $range_obj->delimiter1 = 0;
     $range_obj->delimiter2 = 1;
     if (!$range_obj->save()) {
         return false;
     }
     if (!self::assignCustomerGroupsForCarrier($carrier)) {
         return false;
     }
     if (!Configuration::updateValue(DpdPolandConfiguration::CARRIER_STANDARD_ID, (int) $carrier->id)) {
         return false;
     }
     return true;
 }
示例#8
0
 public function carrierSignUp()
 {
     if (Input::exists("key") || Input::exists("cname") || Input::exists("fname") || Input::exists("lname") || Input::exists("email") || Input::exists("mob")) {
         $key = Input::get("key");
         $cname = Input::get("cname");
         $fname = Input::get("fname");
         $lname = Input::get("lname");
         $email = Input::get("email");
         $mob = Input::get("mob");
         if (empty($key) || empty($cname) || empty($fname) || empty($lname) || empty($email) || empty($mob)) {
             textMsg("All fields are required", "error");
             Redirect::url("home/register");
             exit;
         } else {
             if ($key == $_SESSION['key']) {
                 $check = Carrier::all(['email' => $email]);
                 if (count($check) > 0) {
                     textMsg("This email id already exists try again", "error");
                     Redirect::url("home/register");
                     exit;
                 } else {
                     $user = new Carrier();
                     $user->company_name = $cname;
                     $user->first_name = $fname;
                     $user->last_name = $lname;
                     $user->email = $email;
                     $user->mobile = $mob;
                     $user->status = 1;
                     $user->join_date = time();
                     if ($user->save()) {
                         textMsg("You have been ragistered succesfully", "success");
                         Redirect::url("home/register");
                         exit;
                     } else {
                         textMsg("somethis went wrong try again", "error");
                         Redirect::url("home/register");
                         exit;
                     }
                 }
             } else {
                 textMsg("Unable to do this action", "error");
                 Redirect::url("home/register");
                 exit;
             }
         }
     } else {
         textMsg("somethis went wrong try again", "error");
         Redirect::url("home/register");
         exit;
     }
 }
示例#9
0
 public static function install($carrier_type, $carrier_name)
 {
     $id_carrier = (int) Configuration::get($carrier_type);
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $id_carrier = (int) DpdGroupCarrier::getIdCarrierByReference((int) $id_carrier);
         $carrier = new Carrier((int) $id_carrier);
     } else {
         $carrier = Carrier::getCarrierByReference($id_carrier);
     }
     if ($id_carrier && Validate::isLoadedObject($carrier)) {
         if (!$carrier->deleted) {
             return true;
         } else {
             $carrier->deleted = 0;
             return (bool) $carrier->save();
         }
     }
     $service = new DpdGroupService();
     $carrier = new Carrier();
     $carrier->name = $carrier_name;
     $carrier->active = 1;
     $carrier->is_free = 0;
     $carrier->shipping_handling = 1;
     $carrier->shipping_external = 1;
     $carrier->shipping_method = 1;
     $carrier->max_width = 0;
     $carrier->max_height = 0;
     $carrier->max_weight = 0;
     $carrier->grade = 0;
     $carrier->is_module = 1;
     $carrier->need_range = 1;
     $carrier->range_behavior = 1;
     $carrier->external_module_name = $service->module_instance->name;
     $carrier->url = _DPDGROUP_TRACKING_URL_;
     $delay = array();
     foreach (Language::getLanguages(false) as $language) {
         $delay[$language['id_lang']] = $carrier_name;
     }
     $carrier->delay = $delay;
     if (!$carrier->save()) {
         return false;
     }
     $dpdgroup_carrier = new DpdGroupCarrier();
     $dpdgroup_carrier->id_carrier = (int) $carrier->id;
     $dpdgroup_carrier->id_reference = (int) $carrier->id;
     if (!$dpdgroup_carrier->save()) {
         return false;
     }
     foreach ($service->continents as $continent => $value) {
         if ($value && !$carrier->addZone($continent)) {
             return false;
         }
     }
     $groups = array();
     foreach (Group::getGroups((int) Context::getContext()->language->id) as $group) {
         $groups[] = $group['id_group'];
     }
     if (version_compare(_PS_VERSION_, '1.5.5', '<')) {
         if (!self::setGroups14((int) $carrier->id, $groups)) {
             return false;
         }
     } else {
         if (!$carrier->setGroups($groups)) {
             return false;
         }
     }
     if (!Configuration::updateValue($carrier_type, (int) $carrier->id)) {
         return false;
     }
     return true;
 }