Пример #1
0
//	We quit with error message
if ($error == 1) {
    die('ko');
} else {
    if ($error > 1) {
        die('Error->' . $module->l('Please choose correct values', 'ajax'));
    }
}
//	Specific action
if (isset($params['action'])) {
    switch ($params['action']) {
        case 'checkCart':
            $return = Db::getInstance()->getValue('SELECT aimd_dpq FROM ' . _DB_PREFIX_ . 'product WHERE id_product = ' . (int) $params['product']);
            break;
        case 'checkWeight':
            $weight = get_combinationWeight((int) $params['product'], (int) $params['combination']);
            $return = 'ok|' . str_replace('.', ',', number_format($weight, 2));
            break;
        case 'copyFile':
            $order_id = (int) $params['order'];
            $product_id = (int) $params['product'];
            $combination_id = (int) $params['combination'];
            $name = $params['name'];
            $sub_directory = $order_id . '_' . $product_id . '_' . $combination_id;
            //  Check if directory exists or create it
            $directory = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . Configuration::get('AIMD_UPLOAD_DIR') . $module->name . DIRECTORY_SEPARATOR . $sub_directory;
            if (!file_exists($directory)) {
                mkdir($directory, 0777);
                copy('index.php', $directory . '/index.php');
            } else {
                //    Check count
Пример #2
0
 /**
  * \brief	Save a grid data
  * \param	integer Grid id
  * \param	string File to save
  * \retval 	boolean Result of the operation
  */
 private function _save_defaultDimension($product_id, $default_values)
 {
     global $cookie;
     //	Unset key = 0
     ksort($default_values);
     $default_values = array_slice($default_values, 1, 5, true);
     //	Test if combination exists, else create it
     $values = array();
     foreach ($default_values as $value) {
         $values[] = $value[0];
     }
     $combination_count = (int) Db::getInstance()->getValue('SELECT COUNT(*) AS count FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_attribute IN (' . implode(',', $values) . ') HAVING count = ' . count($values));
     if (!$combination_count) {
         //	Get product combinations
         $combinations = Db::getInstance()->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product = ' . $product_id);
         //	Get product data
         $product_data = Db::getInstance()->getRow('SELECT price, wholesale_price, weight FROM ' . _DB_PREFIX_ . 'product WHERE id_product = ' . $product_id);
         foreach ($combinations as $combination) {
             //	Check if combination is the default one
             $default = 0;
             if ($combination['default_on'] == '1') {
                 $default = 1;
             }
             //	Set combination data
             $price = floatval($product_data['price']) + floatval($combination['price']);
             $weight = get_combinationWeight($product_id, (int) $combination['id_product_attribute']);
             $wholesale_price = floatval($product_data['wholesale_price']) + floatval($combination['wholesale_price']);
             //	Set available date for Prestashop 1.5 and above
             $add = '';
             $value_add = '';
             if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                 $add = ', available_date';
                 $value_add = ', "0000-00-00"';
             }
             //	Create the new one
             if (Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute (id_product, quantity, price, wholesale_price, aimd_value, weight, default_on' . $add . ') VALUES (' . $product_id . ', 1, ' . $price . ', ' . $wholesale_price . ', 1, ' . $weight . ', ' . $default . $value_add . ')')) {
                 $product_attribute_id = Db::getInstance()->Insert_ID();
                 //	Add quantity to product stock
                 Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET quantity = quantity + 1 WHERE id_product = ' . $product_id);
                 //	Get active attributs
                 $attributes = getActiveAttributes();
                 //	Save combination elements
                 $elements = Db::getInstance()->ExecuteS('SELECT pac.id_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination AS pac LEFT JOIN ' . _DB_PREFIX_ . 'attribute AS a ON ' . 'pac.id_attribute = a.id_attribute WHERE pac.id_product_attribute = ' . $combination['id_product_attribute'] . ' AND a.id_attribute_group NOT IN (' . implode(',', $attributes) . ')');
                 foreach ($elements as $element) {
                     Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . $element['id_attribute'] . ', ' . $product_attribute_id . ')');
                 }
                 //	Save combination default dimensions elements
                 $tmp_price = 1;
                 $tmp_weight = 1;
                 $tmp_wholesale_price = 1;
                 foreach ($default_values as $key => $value) {
                     Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . $value[0] . ', ' . $product_attribute_id . ')');
                     $default_dimension = (int) Db::getInstance()->getValue('SELECT al.name FROM ' . _DB_PREFIX_ . 'attribute_lang AS al LEFT JOIN ' . _DB_PREFIX_ . 'attribute AS a ON a.id_attribute = al.id_attribute ' . 'WHERE al.id_lang = ' . (int) $cookie->id_lang . ' AND a.id_attribute_group = ' . $key);
                     $tmp_price = $tmp_price * $value[1] / $default_dimension;
                     $tmp_weight = $tmp_weight * $value[1] / $default_dimension;
                     $tmp_wholesale_price = $tmp_wholesale_price * $value[1] / $default_dimension;
                 }
                 $price = $price * $tmp_price - floatval($product_data['price']);
                 $weight = $weight * $tmp_weight - $weight;
                 $wholesale_price = $wholesale_price * $tmp_wholesale_price - $wholesale_price;
                 //	Update product attribute data
                 Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute SET price = ' . $price . ', wholesale_price = ' . $wholesale_price . ', weight = ' . $weight . ' WHERE id_product = ' . $product_id . ' AND id_product_attribute = ' . $product_attribute_id);
                 //	If image, add it
                 $image = Db::getInstance()->getValue('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $combination['id_product_attribute']);
                 if ($image) {
                     Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_image (id_product_attribute, id_image) VALUES (' . $product_attribute_id . ', ' . $image . ')');
                 }
                 //	Add for Prestashop 1.5 version and above
                 if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                     //	Insert in shops
                     if ((int) Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1 && (Tools::getIsset('shop_linked') && Tools::getValue('shop_linked'))) {
                         $shops_id = array('id_shop' => (int) Tools::getValue('shop_linked'));
                     } else {
                         $shops_id = Db::getInstance()->ExecuteS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop WHERE active = 1');
                     }
                     if (isset($shops_id)) {
                         foreach ($shops_id as $shop_id) {
                             //	Add product attribute shop
                             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_shop (id_product_attribute, id_shop, price, wholesale_price, weight, minimal_quantity, default_on, available_date) VALUES (' . $product_attribute_id . ', ' . (int) $shop_id['id_shop'] . ', ' . $price . ', ' . $wholesale_price . ', ' . $weight . ', ' . $combination['minimal_quantity'] . ', ' . $default . ', "0000-00-00")');
                             //	Add stock availability
                             $product_tmp = new Product($product_id);
                             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'stock_available (id_product, id_product_attribute, id_shop, id_shop_group, quantity, out_of_stock) VALUES (' . $product_id . ', ' . $product_attribute_id . ', ' . (int) $shop_id['id_shop'] . ', 0, 1, ' . $product_tmp->out_of_stock . ')');
                             //	Update stock for base product
                             Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'stock_available SET quantity = quantity + 1 WHERE id_product = ' . $product_id . ' AND id_product_attribute = 0 AND id_shop = ' . (int) $shop_id['id_shop']);
                         }
                     }
                 }
             }
             //	Unset the default combination if needed
             if ($default == 1) {
                 Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute SET default_on = 0 WHERE id_product = ' . $product_id . ' AND id_product_attribute = ' . $combination['id_product_attribute']);
                 if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                     Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute_shop SET default_on = 0 WHERE id_product_attribute = ' . $combination['id_product_attribute']);
                 }
             }
         }
     }
 }