protected function generateProductsData()
    {
        $delimiter = ';';
        $titles = array();
        $id_lang = $this->use_lang;
        $new_path = new Sampledatainstall();
        $f = fopen($new_path->sendPath() . 'output/products.vsc', 'w');
        foreach ($this->product_fields as $field => $array) {
            $titles[] = $array['label'];
        }
        fputcsv($f, $titles, $delimiter, '"');
        $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true);
        foreach ($products as $product) {
            $line = array();
            $p = new Product($product['id_product'], true, $id_lang, 1);
            foreach ($this->product_fields as $field => $array) {
                $line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : '';
            }
            $cats = $p->getProductCategoriesFull($p->id, 1);
            $cat_array = array();
            foreach ($cats as $cat) {
                $cat_array[] = $cat['id_category'];
            }
            $line['categories'] = implode(',', $cat_array);
            $line['price_tex'] = $p->getPrice(false);
            $line['price_tin'] = $p->getPrice(true);
            $line['upc'] = $p->upc ? $p->upc : '';
            $line['features'] = '';
            $features = $p->getFrontFeatures($id_lang);
            $position = 1;
            $devider = '';
            foreach ($features as $feature) {
                $sql = 'SELECT `id_feature`
						FROM ' . _DB_PREFIX_ . 'feature_lang
						WHERE `name` = "' . pSql($feature['name']) . '"';
                $sql1 = 'SELECT `id_feature_value`
						FROM ' . _DB_PREFIX_ . 'feature_value_lang
						WHERE `value` = "' . pSql($feature['value']) . '"';
                $id_feature = Db::getInstance()->getValue($sql);
                $id_feature_value = Db::getInstance()->getValue($sql1);
                $line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position;
                $devider = ',';
                $position++;
            }
            $specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0);
            $line['reduction_price'] = '';
            $line['reduction_percent'] = '';
            $line['reduction_from'] = '';
            $line['reduction_to'] = '';
            if ($specificPrice) {
                if ($specificPrice['reduction_type'] == 'amount') {
                    $line['reduction_price'] = $specificPrice['reduction'];
                } elseif ($specificPrice['reduction_type'] == 'percent') {
                    $line['reduction_percent'] = $specificPrice['reduction'];
                }
                if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
                    $line['reduction_from'] = $specificPrice['from'];
                    $line['reduction_to'] = $specificPrice['to'];
                }
            }
            $tags = $p->getTags($id_lang);
            $line['tags'] = $tags;
            $link = new Link();
            $imagelinks = array();
            $images = $p->getImages($id_lang);
            foreach ($images as $image) {
                $imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
                $this->copyConverFileName($imagelink);
                $imagelinks[] = $imagelink;
            }
            $line['image'] = implode(',', $imagelinks);
            $line['delete_existing_images'] = 0;
            $line['shop'] = 1;
            $warehouses = Warehouse::getWarehousesByProductId($p->id);
            $line['warehouse'] = '';
            if (!empty($warehouses)) {
                $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
            }
            $values = array();
            $accesories = $p->getAccessories($id_lang);
            if (isset($accesories) && $accesories && count($accesories)) {
                foreach ($accesories as $accesorie) {
                    $values[] = $accesorie['id_product'];
                }
            }
            $line['accessories'] = $values ? implode(',', $values) : '';
            $values = array();
            $carriers = $p->getCarriers();
            if (isset($carriers) && $carriers && count($carriers)) {
                foreach ($carriers as $carrier) {
                    $values[] = $carrier['id_carrier'];
                }
            }
            $line['carriers'] = $values ? implode(',', $values) : '';
            $values = array();
            $customization_fields_ids = $p->getCustomizationFieldIds();
            if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) {
                foreach ($customization_fields_ids as $customization_field_id) {
                    $cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang);
                    $values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name;
                }
            }
            $line['customization_fields_ids'] = $values ? implode(',', $values) : '';
            $values = array();
            $attachments = $p->getAttachments($this->use_lang);
            if (isset($attachments) && $attachments && count($attachments)) {
                foreach ($attachments as $attachment) {
                    $values[] = $attachment['id_attachment'];
                }
            }
            $line['attachments'] = $values ? implode(',', $values) : '';
            if (!property_exists('Product', 'base_price')) {
                // for versions < 1.6.0.13
                $line['base_price'] = !is_array($p->base_price) && !Tools::isEmpty($p->base_price) ? $p->base_price : '';
            }
            if (!$line[$field]) {
                $line[$field] = '';
            }
            fputcsv($f, $line, $delimiter, '"');
        }
        fclose($f);
    }
Exemplo n.º 2
0
function decode_content()
{
    // CMS_LANG
    $sql = 'SELECT `id_cms`, `content`, `id_lang` FROM `' . _DB_PREFIX_ . 'cms_lang`';
    $result = Db::getInstance()->ExecuteS($sql);
    foreach ($result as $cms) {
        Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'cms_lang`
									SET `content` = \'' . pSql(Tools::htmlentitiesDecodeUTF8($cms['content']), true) . '\'
									WHERE  `id_cms`= ' . intval($cms['id_cms']) . ' AND `id_lang` = ' . intval($cms['id_lang']));
    }
    // MANUFACTURER_LANG
    $sql = 'SELECT `id_manufacturer`, `description`, `short_description`, `id_lang` FROM `' . _DB_PREFIX_ . 'manufacturer_lang`';
    $result = Db::getInstance()->ExecuteS($sql);
    foreach ($result as $manu) {
        Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'manufacturer_lang`
									SET `description` = \'' . pSql(Tools::htmlentitiesDecodeUTF8($manu['description']), true) . '\', 
										`short_description` = \'' . pSql(Tools::htmlentitiesDecodeUTF8($manu['short_description']), true) . '\'
									WHERE `id_manufacturer`= ' . intval($manu['id_manufacturer']) . ' AND `id_lang` = ' . intval($manu['id_lang']));
    }
    // PRODUCT_LANG
    $sql = 'SELECT `id_product`, `description`, `description_short`, `id_lang` FROM `' . _DB_PREFIX_ . 'product_lang`';
    $result = Db::getInstance()->ExecuteS($sql);
    foreach ($result as $prod) {
        Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'product_lang`
									SET `description` = \'' . pSql(Tools::htmlentitiesDecodeUTF8($prod['description']), true) . '\', 
										`description_short` = \'' . pSql(Tools::htmlentitiesDecodeUTF8($prod['description_short']), true) . '\'
									WHERE `id_product`= ' . intval($prod['id_product']) . ' AND `id_lang` = ' . intval($prod['id_lang']));
    }
}
Exemplo n.º 3
0
    public function getVendorsForPostcode($id_country, $postcode, $id_products, $id_vendor_default)
    {
        // Okay, here we go: Select all vendors
        // supporting the product that services an
        // area covering the delivery postcode. This
        // is basically a Pythagoras
        // Espen Lyngaas added line to remove spaces in postcodes
        $postcode = str_replace(" ", "", $postcode);
        $products_sql = '"' . $id_products[0] . '"';
        foreach ($id_products as $id_product) {
            $product_sql .= ', "' . $id_product . '"';
        }
        $query = '
			select
			 vendor_support.id_product,
			 vendor.id_vendor,
			 vendor.title,
			 postcode_vendor.name as postcode,
			 sqrt(  power(abs(postcode_vendor.latitude - postcode_customer.latitude),2)
			      + power(abs(postcode_vendor.longitude - postcode_customer.longitude),2)) as distance
			from
			 PREFIX_vendor_support,
			 PREFIX_vendor,
			 PREFIX_postcode as postcode_vendor,
			 PREFIX_postcode as postcode_customer
			where
			 vendor_support.id_product in (' . $products_sql . ')
			 and postcode_customer.name = "' . pSql($postcode) . '"
			 and postcode_customer.id_country = "' . pSql($id_country) . '"

			 and vendor_support.id_vendor = vendor.id_vendor
			 and vendor.id_postcode = postcode_vendor.id_postcode

			 and postcode_vendor.id_country = "' . pSql($id_country) . '"
			 and sqrt(  power(abs(postcode_vendor.latitude - postcode_customer.latitude),2)
				  + power(abs(postcode_vendor.longitude - postcode_customer.longitude),2)) <= vendor.distance
                        order by
				vendor.distance';
        /*                         abs(vendor.id_vendor - "' . pSql($id_vendor_default) . '")
        			 ';*/
        $query = str_replace('PREFIX_', _DB_PREFIX_, $query);
        $result = Db::getInstance()->ExecuteS($query);
        $vendors = array();
        if ($result) {
            foreach ($result as $supporting_vendor) {
                $vendors[] = $supporting_vendor;
            }
        }
        return $vendors;
    }
Exemplo n.º 4
0
 function install()
 {
     if (!file_exists(dirname(__FILE__) . '/install.sql')) {
         return false;
     } else {
         if (!($sql = file_get_contents(dirname(__FILE__) . '/install.sql'))) {
             return false;
         }
     }
     $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql);
     $sql = preg_split("/;\\s*[\r\n]+/", $sql);
     foreach ($sql as $query) {
         if (trim($query)) {
             Db::getInstance()->Execute(trim($query));
         }
     }
     $sql = "ALTER TABLE `PREFIX_cart_product` ADD COLUMN (`id_vendor` int(10) unsigned NOT NULL, FOREIGN KEY (`id_vendor`) REFERENCES `PREFIX_vendor`(`id_vendor`))";
     $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql);
     try {
         Db::getInstance()->Execute(trim($sql));
     } catch (Exception $e) {
     }
     $sql = "DELETE FROM `PREFIX_postcode`";
     $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql);
     Db::getInstance()->Execute(trim($sql));
     foreach (glob(dirname(__FILE__) . '/postcode_coordinates.*.csv') as $filename) {
         $parts = explode('.', $filename);
         $iso_code = $parts[count($parts) - 2];
         $query = 'select `id_country` from PREFIX_country where iso_code = "' . pSql($iso_code) . '"';
         $query = str_replace('PREFIX_', _DB_PREFIX_, $query);
         $result = Db::getInstance()->GetRow($query);
         $id_country = $result['id_country'];
         $file = fopen($filename, "r");
         $header = fgetcsv($file, 0, "\t");
         while ($line = fgetcsv($file, 0, "\t")) {
             echo "TRALALA<br>";
             $line = array_combine($header, $line);
             $query = 'INSERT INTO `PREFIX_postcode` (`id_country`, `name`, `longitude`, `latitude`) VALUES (' . pSql($id_country) . ', ' . '"' . pSql($line['Postcode']) . '", "' . pSql($line['Longitude']) . '", "' . pSql($line['Latitude']) . '")';
             $query = str_replace('PREFIX_', _DB_PREFIX_, $query);
             Db::getInstance()->Execute($query);
         }
     }
     if (parent::install() == false) {
         return false;
     }
     return true;
 }
function update_order_detail_taxes()
{
    $order_detail_taxes = Db::getInstance()->executeS('
	SELECT `id_order_detail`, `tax_name`, `tax_rate` FROM `' . _DB_PREFIX_ . 'order_detail`
	');
    $id_lang_list = Db::getInstance()->executeS('SELECT id_lang FROM `' . _DB_PREFIX_ . 'lang`');
    foreach ($order_detail_taxes as $order_detail_tax) {
        if ($order_detail_tax['tax_rate'] == '0.000') {
            continue;
        }
        $alternative_tax_name = 'Tax ' . $order_detail_tax['tax_rate'];
        $create_tax = true;
        $id_tax = (int) Db::getInstance()->getValue('SELECT t.`id_tax`
			FROM `' . _DB_PREFIX_ . 'tax` t
			LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (tl.id_tax = t.id_tax)
			WHERE tl.`name` = \'' . pSQL($order_detail_tax['tax_name']) . '\' ');
        $id_tax_alt = (int) Db::getInstance()->getValue('SELECT t.`id_tax`
			FROM `' . _DB_PREFIX_ . 'tax` t
			LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (tl.id_tax = t.id_tax)
			WHERE tl.`name` = \'' . pSQL($alternative_tax_name) . '\' ');
        if ($id_tax || $id_tax_alt) {
            $create_tax = !(bool) Db::getInstance()->getValue('SELECT count(*) 
				FROM `' . _DB_PREFIX_ . 'tax` 
				WHERE id_tax = ' . (int) $id_tax . ' 
					AND rate = "' . pSql($order_detail_tax['tax_rate']) . '"
			');
        }
        if ($create_tax) {
            $tax_name = isset($order_detail_tax['tax_name']) ? $order_detail_tax['tax_name'] : $alternative_tax_name;
            Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'tax` (`rate`, `active`, `deleted`)
			VALUES (\'' . (double) $order_detail_tax['tax_rate'] . '\', 0, 1)');
            $id_tax = Db::getInstance()->Insert_ID();
            foreach ($id_lang_list as $id_lang) {
                Db::getInstance()->execute('
				INSERT INTO `' . _DB_PREFIX_ . 'tax_lang` (`id_tax`, `id_lang`, `name`)
				VALUES (' . (int) $id_tax . ',' . (int) $id_lang['id_lang'] . ',\'' . pSQL($tax_name) . '\')
				');
            }
        }
        Db::getInstance()->execute('
		INSERT INTO `' . _DB_PREFIX_ . 'order_detail_tax` (`id_order_detail`, `id_tax`)
		VALUES (' . (int) $order_detail_tax['id_order_detail'] . ',' . $id_tax . ')
		');
    }
}
Exemplo n.º 6
0
    /**
     * Process changes on an address
     */
    protected function processSubmitAddress()
    {
        $address = new Address();
        $this->errors = $address->validateController();
        $address->id_customer = (int) $this->context->customer->id;
        // Check page token
        if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
            $this->errors[] = Tools::displayError('Invalid token.');
        }
        // Check phone
        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
            $this->errors[] = Tools::displayError('You must register at least one phone number.');
        }
        if ($address->id_country) {
            // Check country
            if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
                throw new PrestaShopException('Country cannot be loaded with address->id_country');
            }
            if ((int) $country->contains_states && !(int) $address->id_state) {
                $this->errors[] = Tools::displayError('This country requires you to chose a State.');
            }
            // US customer: normalize the address
            if ($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')) {
                include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
                $normalize = new AddressStandardizationSolution();
                $address->address1 = $normalize->AddressLineStandardization($address->address1);
                $address->address2 = $normalize->AddressLineStandardization($address->address2);
            }
            $postcode = Tools::getValue('postcode');
            /* Check zip code format */
            if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
                $this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
            } elseif (empty($postcode) && $country->need_zip_code) {
                $this->errors[] = Tools::displayError('A Zip / Postal code is required.');
            } elseif ($postcode && !Validate::isPostCode($postcode)) {
                $this->errors[] = Tools::displayError('The Zip / Postal code is invalid.');
            }
            // Check country DNI nox fix
            /*if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
            			$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
            		else if (!$country->isNeedDni())
            			$address->dni = null;*/
            if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
                $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
            } elseif (!$country->need_identification_number) {
                ${$addresses_type}->dni = null;
            }
        }
        // Check if the alias exists
        if (!$this->context->customer->is_guest && !empty($_POST['alias']) && (int) $this->context->customer->id > 0) {
            $id_address = Tools::getValue('id_address');
            if (Configuration::get('PS_ORDER_PROCESS_TYPE') && (int) Tools::getValue('opc_id_address_' . Tools::getValue('type')) > 0) {
                $id_address = Tools::getValue('opc_id_address_' . Tools::getValue('type'));
            }
            if (Db::getInstance()->getValue('
				SELECT count(*)
				FROM ' . _DB_PREFIX_ . 'address
				WHERE `alias` = \'' . pSql($_POST['alias']) . '\'
				AND id_address != ' . (int) $id_address . '
				AND id_customer = ' . (int) $this->context->customer->id . '
				AND deleted = 0') > 0) {
                $this->errors[] = sprintf(Tools::displayError('The alias "%s" has already been used. Please select another one.'), Tools::safeOutput($_POST['alias']));
            }
        }
        // Check the requires fields which are settings in the BO
        $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
        // Don't continue this process if we have errors !
        if ($this->errors && !$this->ajax) {
            return;
        }
        // If we edit this address, delete old address and create a new one
        if (Validate::isLoadedObject($this->_address)) {
            if (Validate::isLoadedObject($country) && !$country->contains_states) {
                $address->id_state = 0;
            }
            $address_old = $this->_address;
            if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
                if ($address_old->isUsed()) {
                    $address_old->delete();
                } else {
                    $address->id = (int) $address_old->id;
                    $address->date_add = $address_old->date_add;
                }
            }
        }
        if ($this->ajax && Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
            $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
            if (count($this->errors)) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors);
                die(Tools::jsonEncode($return));
            }
        }
        // Save address
        if ($result = $address->save()) {
            // Update id address of the current cart if necessary
            if (isset($address_old) && $address_old->isUsed()) {
                $this->context->cart->updateAddressId($address_old->id, $address->id);
            } else {
                // Update cart address
                $this->context->cart->autosetProductAddress();
            }
            if ((bool) Tools::getValue('select_address', false) == true or Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                $this->context->cart->id_address_invoice = (int) $address->id;
            } elseif (Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                $this->context->cart->id_address_invoice = (int) $this->context->cart->id_address_delivery;
            }
            $this->context->cart->update();
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => (int) $this->context->cart->id_address_delivery, 'id_address_invoice' => (int) $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            }
            // Redirect to old page or current page
            if ($back = Tools::getValue('back')) {
                if ($back == Tools::secureReferrer(Tools::getValue('back'))) {
                    Tools::redirect(html_entity_decode($back));
                }
                $mod = Tools::getValue('mod');
                Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
            } else {
                Tools::redirect('index.php?controller=addresses');
            }
        }
        $this->errors[] = Tools::displayError('An error occurred while updating your address.');
    }
Exemplo n.º 7
0
    /**
     * Update product quantity
     *
     * @param integer $quantity Quantity to add (or substract)
     * @param integer $id_product Product ID
     * @param integer $id_product_attribute Attribute ID if needed
     * @param string $operator Indicate if quantity must be increased or decreased
     */
    public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up')
    {
        self::$_nbProducts = 0;
        if (intval($quantity) <= 0) {
            return $this->deleteProduct(intval($id_product), intval($id_product_attribute), intval($id_customization));
        } else {
            /* Check if the product is already in the cart */
            $result = $this->containsProduct($id_product, $id_product_attribute, $id_customization);
            /* Update quantity if product already exist */
            if (Db::getInstance()->NumRows()) {
                if ($operator == 'up') {
                    $result2 = Db::getInstance()->getRow('
						SELECT ' . ($id_product_attribute ? 'pa' : 'p') . '.`quantity`, p.`out_of_stock`
						FROM `' . _DB_PREFIX_ . 'product` p
						' . ($id_product_attribute ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON p.`id_product` = pa.`id_product`' : '') . '
						WHERE p.`id_product` = ' . intval($id_product) . ($id_product_attribute != NULL ? ' AND `id_product_attribute` = ' . intval($id_product_attribute) : ''));
                    $productQty = intval($result2['quantity']);
                    $newQty = $result['quantity'] + intval($quantity);
                    $qty = '`quantity` + ' . intval($quantity);
                    if ((intval($result2['out_of_stock']) == 0 or intval($result2['out_of_stock']) == 2 and !Configuration::get('PS_ORDER_OUT_OF_STOCK')) and $newQty > $productQty) {
                        return false;
                    }
                } elseif ($operator == 'down') {
                    $qty = '`quantity` - ' . intval($quantity);
                    $newQty = $result['quantity'] - intval($quantity);
                } else {
                    return false;
                }
                /* Delete product from cart */
                if ($newQty <= 0) {
                    return $this->deleteProduct(intval($id_product), intval($id_product_attribute), intval($id_customization));
                } else {
                    Db::getInstance()->Execute('
					UPDATE `' . _DB_PREFIX_ . 'cart_product`
					SET `quantity` = ' . $qty . '
					' . ($operator == 'up' ? ', `date_add` = \'' . pSql(date('Y-m-d H:i:s')) . '\'' : '') . '
					WHERE `id_product` = ' . intval($id_product) . ($id_product_attribute != NULL ? ' AND `id_product_attribute` = ' . intval($id_product_attribute) : '') . '
					AND `id_cart` = ' . intval($this->id));
                }
            } else {
                $result2 = Db::getInstance()->getRow('
					SELECT ' . ($id_product_attribute ? 'pa' : 'p') . '.`quantity`, p.`out_of_stock`
					FROM `' . _DB_PREFIX_ . 'product` p
					' . ($id_product_attribute ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON p.`id_product` = pa.`id_product`' : '') . '
					WHERE p.`id_product` = ' . intval($id_product) . ($id_product_attribute != NULL ? ' AND `id_product_attribute` = ' . intval($id_product_attribute) : ''));
                $productQty = intval($result2['quantity']);
                if (intval($quantity) > $productQty and (intval($result2['out_of_stock']) == 0 or intval($result2['out_of_stock']) == 2 and !Configuration::get('PS_ORDER_OUT_OF_STOCK'))) {
                    return false;
                }
                if (!Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'cart_product', array('id_product' => intval($id_product), 'id_product_attribute' => intval($id_product_attribute), 'id_cart' => intval($this->id), 'quantity' => intval($quantity), 'date_add' => pSql(date('Y-m-d H:i:s'))), 'INSERT')) {
                    return false;
                }
            }
        }
        return $this->_updateCustomizationQuantity(intval($quantity), intval($id_customization), intval($id_product), intval($id_product_attribute), $operator);
    }
Exemplo n.º 8
0
    /**
     * Add customization item to database
     *
     * @param int $id_product
     * @param int $id_product_attribute
     * @param int $index
     * @param int $type
     * @param string $field
     * @param int $quantity
     * @return boolean success
     */
    public function _addCustomization($id_product, $id_product_attribute, $index, $type, $field, $quantity)
    {
        $exising_customization = Db::getInstance()->executeS('
			SELECT cu.`id_customization`, cd.`index`, cd.`value`, cd.`type` FROM `' . _DB_PREFIX_ . 'customization` cu
			LEFT JOIN `' . _DB_PREFIX_ . 'customized_data` cd
			ON cu.`id_customization` = cd.`id_customization`
			WHERE cu.id_cart = ' . (int) $this->id . '
			AND cu.id_product = ' . (int) $id_product . '
			AND in_cart = 0');
        if ($exising_customization) {
            // If the customization field is alreay filled, delete it
            foreach ($exising_customization as $customization) {
                if ($customization['type'] == $type && $customization['index'] == $index) {
                    Db::getInstance()->execute('
						DELETE FROM `' . _DB_PREFIX_ . 'customized_data`
						WHERE id_customization = ' . (int) $customization['id_customization'] . '
						AND type = ' . (int) $customization['type'] . '
						AND `index` = ' . (int) $customization['index']);
                    if ($type == Product::CUSTOMIZE_FILE) {
                        @unlink(_PS_UPLOAD_DIR_ . $customization['value']);
                        @unlink(_PS_UPLOAD_DIR_ . $customization['value'] . '_small');
                    }
                    break;
                }
            }
            $id_customization = $exising_customization[0]['id_customization'];
        } else {
            Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customization` (`id_cart`, `id_product`, `id_product_attribute`, `quantity`)
				VALUES (' . (int) $this->id . ', ' . (int) $id_product . ', ' . (int) $id_product_attribute . ', ' . (int) $quantity . ')');
            $id_customization = Db::getInstance()->Insert_ID();
        }
        $query = 'INSERT INTO `' . _DB_PREFIX_ . 'customized_data` (`id_customization`, `type`, `index`, `value`)
			VALUES (' . (int) $id_customization . ', ' . (int) $type . ', ' . (int) $index . ', \'' . pSql($field) . '\')';
        if (!Db::getInstance()->execute($query)) {
            return false;
        }
        return true;
    }
Exemplo n.º 9
0
 protected function call_GAA($prefijo, $connector)
 {
     $answerKey = Tools::getValue('Answer');
     $cartId = Tools::getValue('cart');
     if ($this->_tranEstado($cartId) == 3) {
         throw new Exception("second_step ya realizado");
     }
     if ($answerKey == "error") {
         $options = $this->_getRequestOptionsPasoDos($prefijo, $cartId, $answerKey);
         $this->module->log->info('params GAA - ' . json_encode($options));
         $this->module->log->info("GAA - NO SE HACE POR SER FORMULARIO HIBRIDO");
         $respuesta = array("StatusCode" => Tools::getValue("Code"), "StatusMessage" => Tools::getValue("Message"));
     } else {
         $options = $this->_getRequestOptionsPasoDos($prefijo, $cartId, $answerKey);
         $this->module->log->info('params GAA - ' . json_encode($options));
         $respuesta = $connector->getAuthorizeAnswer($options);
         $this->module->log->info('response GAA - ' . json_encode($respuesta));
     }
     $now = new DateTime();
     $this->_tranUpdate($cartId, array("second_step" => $now->format('Y-m-d H:i:s'), "params_GAA" => pSql(json_encode($options)), "response_GAA" => json_encode($respuesta), "answer_key" => $answerKey));
     return $respuesta;
 }
Exemplo n.º 10
0
    /**
     * Process changes on an address
     */
    protected function processSubmitAddress()
    {
        /*if ($this->context->customer->is_guest)
        		Tools::redirect('index.php?controller=addresses');*/
        $address = new Address();
        $this->errors = $address->validateController();
        $address->id_customer = (int) $this->context->customer->id;
        // Check page token
        if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
            $this->errors[] = Tools::displayError('Invalid token');
        }
        // Check phone
        if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
            $this->errors[] = Tools::displayError('You must register at least one phone number');
        }
        if ($address->id_country) {
            // Check country
            if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
                throw new PrestaShopException('Country cannot be loaded with address->id_country');
            }
            if ((int) $country->contains_states && !(int) $address->id_state) {
                $this->errors[] = Tools::displayError('This country requires a state selection.');
            }
            // US customer: normalize the address
            if ($address->id_country == Country::getByIso('US')) {
                include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
                $normalize = new AddressStandardizationSolution();
                $address->address1 = $normalize->AddressLineStandardization($address->address1);
                $address->address2 = $normalize->AddressLineStandardization($address->address2);
            }
            // Check country zip code
            $zip_code_format = $country->zip_code_format;
            if ($country->need_zip_code) {
                if (($postcode = Tools::getValue('postcode')) && $zip_code_format) {
                    if (!$country->checkZipCode($postcode)) {
                        $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                    }
                } else {
                    if ($zip_code_format) {
                        $this->errors[] = Tools::displayError('Zip/Postal code is required.');
                    } else {
                        if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                            $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                        }
                    }
                }
            }
            // Check country DNI
            if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
                $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
            } else {
                if (!$country->isNeedDni()) {
                    $address->dni = null;
                }
            }
        }
        // Check if the alias exists
        if (!empty($_POST['alias']) && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
				SELECT count(*)
				FROM ' . _DB_PREFIX_ . 'address
				WHERE `alias` = \'' . pSql($_POST['alias']) . '\'
				AND id_address != ' . (int) Tools::getValue('id_address') . '
				AND id_customer = ' . (int) $this->context->customer->id . '
				AND deleted = 0') > 0) {
            $this->errors[] = sprintf(Tools::displayError('The alias "%s" is already used, please chose another one.'), Tools::safeOutput($_POST['alias']));
        }
        // Check the requires fields which are settings in the BO
        $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
        // Don't continue this process if we have errors !
        if ($this->errors && !$this->ajax) {
            return;
        }
        // If we edit this address, delete old address and create a new one
        if (Validate::isLoadedObject($this->_address)) {
            if (Validate::isLoadedObject($country) && !$country->contains_states) {
                $address->id_state = 0;
            }
            $address_old = $this->_address;
            if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
                if ($address_old->isUsed()) {
                    $address_old->delete();
                } else {
                    $address->id = (int) $address_old->id;
                    $address->date_add = $address_old->date_add;
                }
            }
        }
        // Save address
        if ($result = $address->save()) {
            // Update id address of the current cart if necessary
            if (isset($address_old) && $address_old->isUsed()) {
                $this->context->cart->updateAddressId($address_old->id, $address->id);
            } else {
                // Update cart address
                $this->context->cart->autosetProductAddress();
            }
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            }
            // Redirect to old page or current page
            if ($back = Tools::getValue('back')) {
                $mod = Tools::getValue('mod');
                Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
            } else {
                Tools::redirect('index.php?controller=addresses');
            }
        }
        $this->errors[] = Tools::displayError('An error occurred while updating your address.');
    }
Exemplo n.º 11
0
    private function setIdConfigurationGroup($languages = null, $i = 0)
    {
        if (empty($languages)) {
            return;
        }
        reset($languages);
        $id_langue_curent = key($languages);
        $lang = $languages[$id_langue_curent];
        $id_website_current = Tools::getValue('avisverifies_idwebsite_' . $lang['iso_code']);
        $cle_secrete_current = Tools::getValue('avisverifies_clesecrete_' . $lang['iso_code']);
        if (empty($id_website_current) && empty($cle_secrete_current)) {
            unset($languages[$id_langue_curent]);
            return $this->setIdConfigurationGroup($languages, $i);
        } else {
            $sql = 'SELECT name
			FROM ' . _DB_PREFIX_ . "configuration\n\t\t\tWHERE value = '" . pSql($id_website_current) . "'\n\t\t\tAND name like 'AV_IDWEBSITE_%'";
            if ($row = Db::getInstance()->getRow($sql)) {
                if (Configuration::get('AV_CLESECRETE_' . Tools::substr($row['name'], 13)) != $cle_secrete_current) {
                    $this->context->controller->errors[] = sprintf($this->l('PARAM ERROR: please check your multilingual configuration for the id_website "%s" at language "%s"'), $id_website_current, $lang['name']);
                    unset($languages[$id_langue_curent]);
                    return $this->setIdConfigurationGroup($languages, $i);
                }
            }
            $group = array();
            array_push($group, $lang['iso_code']);
            unset($languages[$id_langue_curent]);
            foreach ($languages as $id1 => $lang1) {
                if ($id_website_current == Tools::getValue('avisverifies_idwebsite_' . $lang1['iso_code']) && $cle_secrete_current == Tools::getValue('avisverifies_clesecrete_' . $lang1['iso_code'])) {
                    array_push($group, $lang1['iso_code']);
                    unset($languages[$id1]);
                }
            }
            // Create PS configuration variable
            if (!Configuration::get('AV_IDWEBSITE_' . $i)) {
                Configuration::updateValue('AV_IDWEBSITE_' . $i, Tools::getValue('avisverifies_idwebsite_' . $lang['iso_code']));
            }
            if (!Configuration::get('AV_CLESECRETE_' . $i)) {
                Configuration::updateValue('AV_CLESECRETE_' . $i, Tools::getValue('avisverifies_clesecrete_' . $lang['iso_code']));
            }
            if (!Configuration::get('AV_GROUP_CONF_' . $i)) {
                Configuration::updateValue('AV_GROUP_CONF_' . $i, serialize($group));
            }
            if (!Configuration::get('AV_LIGHTWIDGET_' . $i)) {
                Configuration::updateValue('AV_LIGHTWIDGET_' . $i, '0');
            }
            if (!Configuration::get('AV_PROCESSINIT_' . $i)) {
                Configuration::updateValue('AV_PROCESSINIT_' . $i, '');
            }
            if (!Configuration::get('AV_ORDERSTATESCHOOSEN_' . $i)) {
                Configuration::updateValue('AV_ORDERSTATESCHOOSEN_' . $i, '');
            }
            if (!Configuration::get('AV_DELAY_' . $i)) {
                Configuration::updateValue('AV_DELAY_' . $i, '');
            }
            if (!Configuration::get('AV_GETPRODREVIEWS_' . $i)) {
                Configuration::updateValue('AV_GETPRODREVIEWS_' . $i, '');
            }
            if (!Configuration::get('AV_DISPLAYPRODREVIEWS_' . $i)) {
                Configuration::updateValue('AV_DISPLAYPRODREVIEWS_' . $i, '');
            }
            if (!Configuration::get('AV_SCRIPTFLOAT_' . $i)) {
                Configuration::updateValue('AV_SCRIPTFLOAT_' . $i, '');
            }
            if (!Configuration::get('AV_SCRIPTFLOAT_ALLOWED_' . $i)) {
                Configuration::updateValue('AV_SCRIPTFLOAT_ALLOWED_' . $i, '');
            }
            if (!Configuration::get('AV_SCRIPTFIXE_' . $i)) {
                Configuration::updateValue('AV_SCRIPTFIXE_' . $i, '');
            }
            if (!Configuration::get('AV_SCRIPTFIXE_ALLOWED_' . $i)) {
                Configuration::updateValue('AV_SCRIPTFIXE_ALLOWED_' . $i, '');
            }
            if (!Configuration::get('AV_URLCERTIFICAT_' . $i)) {
                Configuration::updateValue('AV_URLCERTIFICAT_' . $i, '');
            }
            if (!Configuration::get('AV_FORBIDDEN_EMAIL_' . $i)) {
                Configuration::updateValue('AV_FORBIDDEN_EMAIL_' . $i, '');
            }
            if (!Configuration::get('AV_CODE_LANG_' . $i)) {
                Configuration::updateValue('AV_CODE_LANG_' . $i, '');
            }
            $i++;
            return $this->setIdConfigurationGroup($languages, $i);
        }
    }
function saveOrderShippingDetails($idCart, $idCustomer, $soParams, $so_object)
{
    $deliveryMode = array('DOM' => 'Livraison à domicile', 'BPR' => 'Livraison en Bureau de Poste', 'A2P' => 'Livraison Commerce de proximité', 'MRL' => 'Livraison Commerce de proximité', 'CMT' => 'Livraison Commerce', 'CIT' => 'Livraison en Cityssimo', 'ACP' => 'Agence ColiPoste', 'CDI' => 'Centre de distribution', 'RDV' => 'Livraison sur Rendez-vous');
    if (isset($soParams['CEPAYS'])) {
        $countryCode = $soParams['CEPAYS'];
    } else {
        $countryCode = 'FR';
    }
    $db = Db::getInstance();
    $db->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'socolissimo_delivery_info WHERE id_cart = ' . intval($idCart) . ' AND id_customer =' . intval($idCustomer));
    $numRows = intval($db->NumRows());
    if ($numRows == 0) {
        $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'socolissimo_delivery_info
			( `id_cart`, `id_customer`, `delivery_mode`, `prid`, `prname`, `prfirstname`, `prcompladress`,
			`pradress1`, `pradress2`, `pradress3`, `pradress4`, `przipcode`, `prtown`,`cecountry`, `cephonenumber`, `ceemail` ,
			`cecompanyname`, `cedeliveryinformation`, `cedoorcode1`, `cedoorcode2`)
			VALUES (' . (int) $idCart . ',' . (int) $idCustomer . ',';
        if ($so_object->delivery_mode == SCFields::RELAY_POINT) {
            $sql .= '\'' . pSQL($soParams['DELIVERYMODE']) . '\'' . ',
					' . (isset($soParams['PRID']) ? '\'' . pSQL($soParams['PRID']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRNAME']) ? '\'' . pSQL($soParams['PRNAME']) . '\'' : '\'\'') . ',
					' . (isset($deliveryMode[$soParams['DELIVERYMODE']]) ? '\'' . pSql($deliveryMode[$soParams['DELIVERYMODE']]) . '\'' : '\'So Colissimo\'') . ',
					' . (isset($soParams['PRCOMPLADRESS']) ? '\'' . pSQL($soParams['PRCOMPLADRESS']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRADRESS1']) ? '\'' . pSQL($soParams['PRADRESS1']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRADRESS2']) ? '\'' . pSQL($soParams['PRADRESS2']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRADRESS3']) ? '\'' . pSQL($soParams['PRADRESS3']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRADRESS4']) ? '\'' . pSQL($soParams['PRADRESS4']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRZIPCODE']) ? '\'' . pSQL($soParams['PRZIPCODE']) . '\'' : '\'\'') . ',
					' . (isset($soParams['PRTOWN']) ? '\'' . pSQL($soParams['PRTOWN']) . '\'' : '\'\'') . ',
					' . (isset($countryCode) ? '\'' . pSQL($countryCode) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEPHONENUMBER']) ? '\'' . pSQL($soParams['CEPHONENUMBER']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEEMAIL']) ? '\'' . pSQL($soParams['CEEMAIL']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CECOMPANYNAME']) ? '\'' . pSQL($soParams['CECOMPANYNAME']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDELIVERYINFORMATION']) ? '\'' . pSQL($soParams['CEDELIVERYINFORMATION']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDOORCODE1']) ? '\'' . pSQL($soParams['CEDOORCODE1']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDOORCODE2']) ? '\'' . pSQL($soParams['CEDOORCODE2']) . '\'' : '\'\'') . ')';
        } else {
            $sql .= '\'' . pSQL($soParams['DELIVERYMODE']) . '\',\'\',
					' . (isset($soParams['CENAME']) ? '\'' . ucfirst(pSQL($soParams['CENAME'])) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEFIRSTNAME']) ? '\'' . ucfirst(pSQL($soParams['CEFIRSTNAME'])) . '\'' : '\'\'') . ',
					' . (isset($soParams['CECOMPLADRESS']) ? '\'' . pSQL($soParams['CECOMPLADRESS']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEADRESS1']) ? '\'' . pSQL($soParams['CEADRESS1']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEADRESS2']) ? '\'' . pSQL($soParams['CEADRESS2']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEADRESS3']) ? '\'' . pSQL($soParams['CEADRESS3']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEADRESS4']) ? '\'' . pSQL($soParams['CEADRESS4']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEZIPCODE']) ? '\'' . pSQL($soParams['CEZIPCODE']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CETOWN']) ? '\'' . pSQL($soParams['CETOWN']) . '\'' : '\'\'') . ',
					' . (isset($countryCode) ? '\'' . pSQL($countryCode) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEPHONENUMBER']) ? '\'' . pSQL($soParams['CEPHONENUMBER']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEEMAIL']) ? '\'' . pSQL($soParams['CEEMAIL']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CECOMPANYNAME']) ? '\'' . pSQL($soParams['CECOMPANYNAME']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDELIVERYINFORMATION']) ? '\'' . pSQL($soParams['CEDELIVERYINFORMATION']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDOORCODE1']) ? '\'' . pSQL($soParams['CEDOORCODE1']) . '\'' : '\'\'') . ',
					' . (isset($soParams['CEDOORCODE2']) ? '\'' . pSQL($soParams['CEDOORCODE2']) . '\'' : '\'\'') . ')';
        }
        if (Db::getInstance()->execute($sql)) {
            return true;
        }
    } else {
        $table = _DB_PREFIX_ . 'socolissimo_delivery_info';
        $values = array();
        $values['delivery_mode'] = pSQL($soParams['DELIVERYMODE']);
        if ($so_object->delivery_mode == SCFields::RELAY_POINT) {
            isset($soParams['PRID']) ? $values['prid'] = pSQL($soParams['PRID']) : '';
            isset($soParams['PRNAME']) ? $values['prname'] = ucfirst(pSQL($soParams['PRNAME'])) : '';
            isset($deliveryMode[$soParams['DELIVERYMODE']]) ? $values['prfirstname'] = pSql($deliveryMode[$soParams['DELIVERYMODE']]) : ($values['prfirstname'] = 'So Colissimo');
            isset($soParams['PRCOMPLADRESS']) ? $values['prcompladress'] = pSQL($soParams['PRCOMPLADRESS']) : '';
            isset($soParams['PRADRESS1']) ? $values['pradress1'] = pSQL($soParams['PRADRESS1']) : '';
            isset($soParams['PRADRESS2']) ? $values['pradress2'] = pSQL($soParams['PRADRESS2']) : '';
            isset($soParams['PRADRESS3']) ? $values['pradress3'] = pSQL($soParams['PRADRESS3']) : '';
            isset($soParams['PRADRESS4']) ? $values['pradress4'] = pSQL($soParams['PRADRESS4']) : '';
            isset($soParams['PRZIPCODE']) ? $values['przipcode'] = pSQL($soParams['PRZIPCODE']) : '';
            isset($soParams['PRTOWN']) ? $values['prtown'] = pSQL($soParams['PRTOWN']) : '';
            isset($countryCode) ? $values['cecountry'] = pSQL($countryCode) : '';
            isset($soParams['CEPHONENUMBER']) ? $values['cephonenumber'] = pSQL($soParams['CEPHONENUMBER']) : '';
            isset($soParams['CEEMAIL']) ? $values['ceemail'] = pSQL($soParams['CEEMAIL']) : '';
            isset($soParams['CEDELIVERYINFORMATION']) ? $values['cedeliveryinformation'] = pSQL($soParams['CEDELIVERYINFORMATION']) : '';
            isset($soParams['CEDOORCODE1']) ? $values['cedoorcode1'] = pSQL($soParams['CEDOORCODE1']) : '';
            isset($soParams['CEDOORCODE2']) ? $values['cedoorcode2'] = pSQL($soParams['CEDOORCODE2']) : '';
            isset($soParams['CECOMPANYNAME']) ? $values['cecompanyname'] = pSQL($soParams['CECOMPANYNAME']) : '';
        } else {
            isset($soParams['PRID']) ? $values['prid'] = pSQL($soParams['PRID']) : ($values['prid'] = '');
            isset($soParams['CENAME']) ? $values['prname'] = ucfirst(pSQL($soParams['CENAME'])) : '';
            isset($soParams['CEFIRSTNAME']) ? $values['prfirstname'] = ucfirst(pSQL($soParams['CEFIRSTNAME'])) : '';
            isset($soParams['CECOMPLADRESS']) ? $values['prcompladress'] = pSQL($soParams['CECOMPLADRESS']) : '';
            isset($soParams['CEADRESS1']) ? $values['pradress1'] = pSQL($soParams['CEADRESS1']) : '';
            isset($soParams['CEADRESS2']) ? $values['pradress2'] = pSQL($soParams['CEADRESS2']) : '';
            isset($soParams['CEADRESS3']) ? $values['pradress3'] = pSQL($soParams['CEADRESS3']) : '';
            isset($soParams['CEADRESS4']) ? $values['pradress4'] = pSQL($soParams['CEADRESS4']) : '';
            isset($soParams['CEZIPCODE']) ? $values['przipcode'] = pSQL($soParams['CEZIPCODE']) : '';
            isset($soParams['CETOWN']) ? $values['prtown'] = pSQL($soParams['CETOWN']) : '';
            isset($countryCode) ? $values['cecountry'] = pSQL($countryCode) : '';
            isset($soParams['CEEMAIL']) ? $values['ceemail'] = pSQL($soParams['CEEMAIL']) : '';
            isset($soParams['CEPHONENUMBER']) ? $values['cephonenumber'] = pSQL($soParams['CEPHONENUMBER']) : '';
            isset($soParams['CEDELIVERYINFORMATION']) ? $values['cedeliveryinformation'] = pSQL($soParams['CEDELIVERYINFORMATION']) : '';
            isset($soParams['CEDOORCODE1']) ? $values['cedoorcode1'] = pSQL($soParams['CEDOORCODE1']) : '';
            isset($soParams['CEDOORCODE2']) ? $values['cedoorcode2'] = pSQL($soParams['CEDOORCODE2']) : '';
            isset($soParams['CECOMPANYNAME']) ? $values['cecompanyname'] = pSQL($soParams['CECOMPANYNAME']) : '';
        }
        $where = ' `id_cart` =\'' . (int) $idCart . '\' AND `id_customer` =\'' . (int) $idCustomer . '\'';
        if (Db::getInstance()->autoExecute($table, $values, 'UPDATE', $where)) {
            return true;
        }
    }
}
Exemplo n.º 13
0
    protected function _processSubmitAddress($id_address, $type)
    {
        if (isset($id_address) && $id_address > 0) {
            $address = new Address($id_address);
        } else {
            $address = new Address();
        }
        $this->errors = $address->validateController();
        $fields_to_check = array("address2", "company", "vat_number", "phone", "phone_mobile", "other");
        foreach ($fields_to_check as $field1) {
            if (Tools::getValue($field1) && trim(Tools::getValue($field1)) == "") {
                $address->{$field1} = "";
            }
        }
        if (empty($this->errors)) {
            // So that dummyvalue address doesn't get customer id assigned
            $address->id_customer = (int) $this->context->customer->id;
        }
        if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
            $this->errors[] = Tools::displayError('Invalid token');
        }
        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') && !Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && $type == 'delivery') {
            $this->errors[] = Tools::displayError('You must register at least one phone number');
        }
        if ($address->id_country) {
            if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
                throw new PrestaShopException('Country cannot be loaded with address->id_country');
            }
            if ((int) $country->contains_states && !(int) $address->id_state) {
                $this->errors[] = Tools::displayError('This country requires a state selection.');
            }
            if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
                include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
                $normalize = new AddressStandardizationSolution();
                $address->address1 = $normalize->AddressLineStandardization($address->address1);
                $address->address2 = $normalize->AddressLineStandardization($address->address2);
            }
            $zip_code_format = $country->zip_code_format;
            if ($country->need_zip_code) {
                if (($postcode = trim(Tools::getValue('postcode'))) && $zip_code_format) {
                    if (!$country->checkZipCode($postcode)) {
                        $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                    }
                } else {
                    if ($zip_code_format && !$this->context->cart->isVirtualCart()) {
                        $this->errors[] = Tools::displayError('Zip/Postal code is required.');
                    } else {
                        if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                            $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                        }
                    }
                }
            }
        }
        if (isset($id_address) && $id_address > 0) {
            $alias_id_address = $id_address;
        } else {
            $alias_id_address = (int) Tools::getValue('id_address');
        }
        if (!$this->context->customer->is_guest && Tools::getValue('alias') && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
				SELECT count(*)
				FROM ' . _DB_PREFIX_ . 'address
				WHERE `alias` = \'' . pSql(Tools::getValue('alias')) . '\'
				AND id_address != ' . $alias_id_address . '
				AND id_customer = ' . (int) $this->context->customer->id . '
				AND deleted = 0') > 0) {
            $address->alias .= '_' . $alias_id_address;
        }
        $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
        if ($this->errors) {
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            } else {
                return;
            }
        }
        $this->context->cart->setNoMultishipping();
        // As the cart is no multishipping, set each delivery address lines with the main delivery address
        $address->alias = preg_replace('/[!<>?=+@{}_$%]/', '', $address->alias);
        if ($result = $address->save()) {
            if (isset($address_old) && $address_old->isUsed()) {
                $this->context->cart->updateAddressId($address_old->id, $address->id);
            } else {
                // Update cart address
                $this->context->cart->autosetProductAddress();
            }
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            }
            if ($back = Tools::getValue('back')) {
                $mod = Tools::getValue('mod');
                Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
            } else {
                Tools::redirect('index.php?controller=addresses');
            }
        }
        $this->errors[] = Tools::displayError('An error occurred while updating your address.');
    }
Exemplo n.º 14
0
    protected function _processSubmitAddress($id_address, $type)
    {
        /*if ($this->context->customer->is_guest)
          Tools::redirect('index.php?controller=addresses');*/
        if (isset($id_address) && $id_address > 0) {
            $address = new Address($id_address);
        } else {
            $address = new Address();
        }
        $this->errors = $address->validateController();
        // Update address2 and company if they're empty (non mandatory fields) - default validateController ignores them
        $fields_to_check = array("address2", "company", "vat_number", "phone", "phone_mobile", "other");
        foreach ($fields_to_check as $field1) {
            if (Tools::getValue($field1) && trim(Tools::getValue($field1)) == "") {
                $address->{$field1} = "";
            }
        }
        if (empty($this->errors)) {
            // So that dummyvalue address doesn't get customer id assigned
            $address->id_customer = (int) $this->context->customer->id;
        }
        // Check page token
        if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
            $this->errors[] = Tools::displayError('Invalid token');
        }
        // Check phone
        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') && !Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && $type == 'delivery') {
            $this->errors[] = Tools::displayError('You must register at least one phone number');
        }
        if ($address->id_country) {
            // Check country
            if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
                throw new PrestaShopException('Country cannot be loaded with address->id_country');
            }
            if ((int) $country->contains_states && !(int) $address->id_state) {
                $this->errors[] = Tools::displayError('This country requires a state selection.');
            }
            // US customer: normalize the address
            if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
                include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
                $normalize = new AddressStandardizationSolution();
                $address->address1 = $normalize->AddressLineStandardization($address->address1);
                $address->address2 = $normalize->AddressLineStandardization($address->address2);
            }
            // Check country zip code
            $zip_code_format = $country->zip_code_format;
            if ($country->need_zip_code) {
                if (($postcode = trim(Tools::getValue('postcode'))) && $zip_code_format) {
                    if (!$country->checkZipCode($postcode)) {
                        $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                    }
                } else {
                    if ($zip_code_format && !$this->context->cart->isVirtualCart()) {
                        $this->errors[] = Tools::displayError('Zip/Postal code is required.');
                    } else {
                        if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                            $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                        }
                    }
                }
            }
            // Check country DNI
            /*if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
                        $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
                    else if (!$country->isNeedDni())
              $address->dni = null;*/
        }
        if (isset($id_address) && $id_address > 0) {
            $alias_id_address = $id_address;
        } else {
            $alias_id_address = (int) Tools::getValue('id_address');
        }
        // Check if the alias exists
        if (!$this->context->customer->is_guest && Tools::getValue('alias') && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
				SELECT count(*)
				FROM ' . _DB_PREFIX_ . 'address
				WHERE `alias` = \'' . pSql(Tools::getValue('alias')) . '\'
				AND id_address != ' . $alias_id_address . '
				AND id_customer = ' . (int) $this->context->customer->id . '
				AND deleted = 0') > 0) {
            $address->alias .= '_' . $alias_id_address;
        }
        //$this->errors[] = sprintf(Tools::displayError('The alias "%s" is already used, please chose another one.'), Tools::safeOutput(Tools::getValue('alias')));
        // Check the requires fields which are settings in the BO
        $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
        // Don't continue this process if we have errors !
        if ($this->errors) {
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            } else {
                return;
            }
        }
        // If we edit this address, delete old address and create a new one
        /*if (Validate::isLoadedObject($this->_address))
          {
              if (Validate::isLoadedObject($country) && !$country->contains_states)
                  $address->id_state = 0;
              $address_old = $this->_address;
              if (Customer::customerHasAddress($this->context->customer->id, (int)$address_old->id))
              {
                  // OPCKT update - never delete existing address!
                  if (false && $address_old->isUsed())
                      $address_old->delete();
                  else
                  {
                      $address->id = (int)($address_old->id);
                      $address->date_add = $address_old->date_add;
                  }
              }
          }*/
        $this->context->cart->setNoMultishipping();
        // As the cart is no multishipping, set each delivery address lines with the main delivery address
        // Fix alias
        $address->alias = preg_replace('/[!<>?=+@{}_$%]/', '', $address->alias);
        // Save address
        if ($result = $address->save()) {
            // Update id address of the current cart if necessary
            if (isset($address_old) && $address_old->isUsed()) {
                $this->context->cart->updateAddressId($address_old->id, $address->id);
            } else {
                // Update cart address
                $this->context->cart->autosetProductAddress();
            }
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            }
            // Redirect to old page or current page
            if ($back = Tools::getValue('back')) {
                $mod = Tools::getValue('mod');
                Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
            } else {
                Tools::redirect('index.php?controller=addresses');
            }
        }
        $this->errors[] = Tools::displayError('An error occurred while updating your address.');
    }