Beispiel #1
0
 function prepare_price($price)
 {
     return pmwi_prepare_price($price, $this->options['disable_prepare_price'], $this->options['prepare_price_to_woo_format'], $this->options['convert_decimal_separator']);
 }
Beispiel #2
0
 /**
  * Preview prices based on current template and tag (called with ajax from `template` step)
  */
 public function preview_prices()
 {
     if (!PMXI_Plugin::getInstance()->getAdminCurrentScreen()->is_ajax) {
         // call is only valid when send with ajax
         exit('Nice try!');
     }
     if (!check_ajax_referer('wp_all_import_preview', 'security', false)) {
         $this->errors->add('form-validation', __('Security check', 'wp_all_import_plugin'));
     }
     if (!$this->errors->get_error_codes()) {
         $post = $this->data['post'] = $this->input->post(array('single_product_regular_price' => '', 'single_product_sale_price' => '', 'disable_prepare_price' => 0, 'single_product_regular_price_adjust' => '', 'single_product_regular_price_adjust_type' => '%', 'single_product_sale_price_adjust' => '', 'single_product_sale_price_adjust_type' => '%', 'import_encoding' => 'UTF-8', 'tagno' => 0));
         $this->data['tagno'] = $tagno = min(max(intval($this->input->getpost('tagno', 1)), 1), PMXI_Plugin::$session->count);
         $xml = '';
         $local_paths = !empty(PMXI_Plugin::$session->local_paths) ? PMXI_Plugin::$session->local_paths : array(PMXI_Plugin::$session->filePath);
         $loop = 1;
         foreach ($local_paths as $key => $path) {
             if (PMXI_Plugin::$session->encoding != $post['import_encoding'] and !empty(PMXI_Plugin::$session->csv_paths[$key])) {
                 // conver CSV to XML with selected encoding
                 include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                 $csv = new PMXI_CsvParser(array('filename' => PMXI_Plugin::$session->csv_paths[$key], 'xpath' => '', 'delimiter' => PMXI_Plugin::$is_csv, 'encoding' => $post['import_encoding'], 'xml_path' => $path));
             }
             $file = new PMXI_Chunk($path, array('element' => !empty($this->data['update_previous']->root_element) ? $this->data['update_previous']->root_element : PMXI_Plugin::$session->source['root_element'], 'encoding' => $post['import_encoding']));
             // loop through the file until all lines are read
             while ($xml = $file->read()) {
                 if (!empty($xml)) {
                     PMXI_Import_Record::preprocessXml($xml);
                     $xml = "<?xml version=\"1.0\" encoding=\"" . $post['import_encoding'] . "\"?>" . "\n" . $xml;
                     $dom = new DOMDocument('1.0', $post['import_encoding']);
                     $old = libxml_use_internal_errors(true);
                     $dom->loadXML($xml);
                     // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
                     libxml_use_internal_errors($old);
                     $xpath = new DOMXPath($dom);
                     if ($this->data['elements'] = $elements = @$xpath->query(PMXI_Plugin::$session->xpath) and $elements->length) {
                         if ($loop == $tagno) {
                             /* Merge nested XML/CSV files */
                             /*$nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true);
                             		if ( ! empty($nested_files) ){										
                             			$merger = new PMXI_Nested($dom, $nested_files, $xml, PMXI_Plugin::$session->xpath);
                             			$merger->merge();
                             			$xml = $merger->get_xml();	
                             			unset($merger);
                             		}	*/
                             unset($dom, $xpath, $elements);
                             break 2;
                         }
                         unset($dom, $xpath, $elements);
                         $loop++;
                     }
                 }
             }
             unset($file);
         }
         //$this->data['tagno'] = $tagno = 1;
         $xpath = "(" . PMXI_Plugin::$session->xpath . ")[1]";
         PMXI_Plugin::$session->set('encoding', $post['import_encoding']);
         PMXI_Plugin::$session->save_data();
         // validate
         try {
             if (empty($xml)) {
                 $this->errors->add('form-validation', __('Error parsing: String could not be parsed as XML', 'wp_all_import_plugin'));
             } else {
                 $data_to_preview = false;
                 if ("" != $post['single_product_regular_price']) {
                     list($this->data['product_regular_price']) = XmlImportParser::factory($xml, $xpath, $post['single_product_regular_price'], $file)->parse();
                     unlink($file);
                     $this->data['product_regular_price'] = pmwi_adjust_price(pmwi_prepare_price($this->data['product_regular_price'], $post['disable_prepare_price']), 'regular_price', $post);
                     $data_to_preview = true;
                 }
                 if ("" != $post['single_product_sale_price']) {
                     list($this->data['product_sale_price']) = XmlImportParser::factory($xml, $xpath, $post['single_product_sale_price'], $file)->parse();
                     unlink($file);
                     $this->data['product_sale_price'] = pmwi_adjust_price(pmwi_prepare_price($this->data['product_sale_price'], $post['disable_prepare_price']), 'sale_price', $post);
                     $data_to_preview = true;
                 }
                 if (!$data_to_preview) {
                     $this->errors->add('form-validation', __('There is no data to preview', 'wp_all_import_plugin'));
                 }
             }
         } catch (XmlImportException $e) {
             $this->errors->add('form-validation', sprintf(__('Error parsing: %s', 'wp_all_import_plugin'), $e->getMessage()));
         }
     }
     ob_start();
     $this->render();
     exit(json_encode(array('html' => ob_get_clean())));
 }
Beispiel #3
0
 function prepare_price($price)
 {
     return pmwi_prepare_price($price, $this->options['disable_prepare_price'], $this->options['prepare_price_to_woo_format']);
 }