Exemple #1
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     /**
      * find selected currency code
      */
     /*
     		if (isset($_POST['client']['customer']['currency_code'])) {
     			$currency_code = $_POST['client']['customer']['currency_code'];
     		} else if (isset($_SESSION['client']['customer']['currency_code'])) {
     			$currency_code = $_SESSION['client']['customer']['currency_code'];
     		} else {
     			$currency_code = $Price->conf['default_currency'];
     		}*/
     $currency_code = GLOBAL_LOCALE_CURRENCY;
     /**
      * get latest price for selected currency code
      */
     $price_common = $Price->getLastPriceForVariety($this->GET['product_variety_id'], $currency_code, 'common');
     $pt = array();
     $pt['common'] = $price_common;
     $pt['discount'] = array();
     /**
      * Display
      */
     $this->tpl->assign("PRICE", $pt);
     if ($pt['discount']['value'] > 0) {
         $this->tpl->parse('content.price_discount');
     } else {
         $this->tpl->parse('content.price_common');
     }
     return true;
 }
Exemple #2
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     // type
     $types = $Price->getTypes();
     foreach ($types as $type) {
         $this->tpl->assign('TYPE', $type);
         if ($type == $_POST['price']['type'] || $type == $this->GET['type']) {
             $this->tpl->assign('SELECTED', "selected='selected'");
         } else {
             $this->tpl->assign('SELECTED', "");
         }
         $this->tpl->parse('content.type');
     }
     if ($_POST['save']) {
         $price_data = $_POST['price'];
         // FIXME: form_currency_inline hack
         $price_data['currency_code'] = $_POST['client']['customer']['currency_code'];
         if ($id = $Price->priceInsert($price_data)) {
             msg("Price added.");
             require_once 'models/ecommerce/ecommerce_product_variety.php';
             $Product_variety = new ecommerce_product_variety();
             $pd = $Product_variety->detail($price_data['product_variety_id']);
         } else {
             return false;
         }
     }
     $this->tpl->assign('PRICE', $_POST['price']);
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     $price_list = $Price->getPriceList($this->GET['product_variety_id']);
     $this->tpl->assign('CONTENT', json_encode($price_list));
     return true;
 }
Exemple #4
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     $price_list = $Price->getPriceList($this->GET['product_variety_id']);
     foreach ($price_list as $item) {
         $item['usage'] = $Price->getAddedToBasketCount($item['id']);
         $this->tpl->assign('ITEM', $item);
         $this->tpl->parse('content.item');
     }
     return true;
 }
 /**
  * init price configuration constants
  */
 public function initPrice()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $price_conf = ecommerce_price::initConfiguration();
     if ($price_conf['backoffice_with_vat']) {
         $this->tpl->assign('VAT_NOTE', I18N_PRICE_INC_VAT);
     } else {
         $this->tpl->assign('VAT_NOTE', I18N_PRICE_EX_VAT);
     }
     return true;
 }
 /**
  * insertOffer
  */
 public function insertOffer($offer)
 {
     if (!is_numeric($offer['product_variety_id'])) {
         msg("Special offer has not been saved, because no product was selected.", "error");
         return false;
     }
     if (!is_numeric($offer['offer_group_id'])) {
         msg("Special offer has not been saved, because no group was selected.", "error");
         return false;
     }
     if ($offer['price_id'] > 0) {
         require_once 'models/ecommerce/ecommerce_price.php';
         $Price = new ecommerce_price();
         $price = $Price->detail($offer['price_id']);
         if ($price['product_variety_id'] != $offer['product_variety_id']) {
             msg("Special offer price does not to belong to given product variety.", "error");
             return false;
         }
     }
     $detail = array('product_variety_id' => $offer['product_variety_id'], 'offer_group_id' => $offer['offer_group_id'] > 0 ? $offer['offer_group_id'] : null, 'campaign_category_id' => $offer['campaign_category_id'] > 0 ? $offer['campaign_category_id'] : null, 'roundel_category_id' => $offer['roundel_category_id'] > 0 ? $offer['roundel_category_id'] : null, 'description' => $offer['description'], 'price_id' => $offer['price_id'] > 0 ? $offer['price_id'] : null, 'quantity' => $offer['quantity'] > 0 ? $offer['quantity'] : null, 'saving' => $offer['saving'] > 0 ? $offer['saving'] : null, 'created' => date("c"), 'modified' => date("c"));
     return $this->insert($detail);
 }
 /**
  * apply discount code
  * requires basket full detail with calculated sub totals
  */
 public function calculateBasketDiscount(&$basket, $code, $check_code = true)
 {
     $promotion_data = false;
     $basket['face_value_voucher'] = 0;
     $basket['face_value_voucher_claim'] = 0;
     $basket['discount'] = 0;
     $basket['discount_fixed_claim'] = 0;
     $basket['discount_percentage_claim'] = 0;
     foreach ($basket['items'] as &$item) {
         $item['discount'] = 0;
     }
     if ($code) {
         require_once 'models/ecommerce/ecommerce_promotion.php';
         $Promotion = new ecommerce_promotion();
         $Promotion->setCacheable(false);
         if ($check_code) {
             $promotion_data = $Promotion->checkCodeBeforeApply($code, $basket['customer_id'], $basket);
         } else {
             $promotion_data = $Promotion->checkCodeMatch($code);
         }
         if ($promotion_data) {
             $promotion_data['discount_fixed_value'] = ecommerce_price::convertCurrency($promotion_data['discount_fixed_value'], GLOBAL_DEFAULT_CURRENCY, $basket['currency']);
             if ($promotion_data['type']['taxable']) {
                 $this->calculateVoucherDiscount($basket, $promotion_data);
             } else {
                 $this->calculateCouponDiscount($basket, $promotion_data);
             }
         }
     }
     return $promotion_data;
 }
Exemple #8
0
 /**
  * get or create custom price_id
  */
 protected function getCustomPriceId($product_variety_id, $multiplicator)
 {
     if (!is_numeric($product_variety_id)) {
         return false;
     }
     if (!is_numeric($multiplicator)) {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     $Price->setCacheable(false);
     $price_id = $Price->getCustomPriceIdByMultiplicator($product_variety_id, $multiplicator);
     if (is_numeric($price_id)) {
         return $price_id;
     } else {
         return false;
     }
 }
 /**
  * insert full product
  */
 public function insertFullVariety($data)
 {
     /**
      * check input values
      */
     if (!is_numeric($data['product_id'])) {
         msg('product_id is not numeric', 'error');
         return false;
     }
     if (!is_numeric($data['product_type_id'])) {
         msg('Product type id is not numeric', 'error');
         return false;
     }
     if (trim($data['name']) == "") {
         msg('Variety name is empty', 'error');
         return false;
     }
     if (trim($data['sku']) == "") {
         msg('Variety SKU is empty', 'error');
         return false;
     }
     if (!is_numeric($data['weight_gross'])) {
         msg('weight_gross is not numeric', 'error');
         return false;
     }
     if (!is_numeric($data['stock'])) {
         msg('Stock value is not numeric', 'error');
         return false;
     }
     if (trim($data['price']['currency_code']) == "") {
         msg('Currency code is empty', 'error');
         return false;
     }
     if (trim($data['price']['type']) == "") {
         msg('Price type', 'error');
         return false;
     }
     if (!is_numeric($data['price']['value'])) {
         msg('Price value is not numeric', 'error');
         return false;
     }
     /**
      * set net weight same as gross if not provided
      */
     if (!is_numeric($data['weight'])) {
         $data['weight'] = $data['weight_gross'];
     }
     /**
      * prepare core variety data
      */
     $variety_data = array();
     $variety_data['product_id'] = $data['product_id'];
     $variety_data['name'] = $data['name'];
     $variety_data['sku'] = $data['sku'];
     $variety_data['weight_gross'] = $data['weight_gross'];
     $variety_data['weight'] = $data['weight'];
     $variety_data['stock'] = $data['stock'];
     $variety_data['product_type_id'] = $data['product_type_id'];
     /**
      * insert
      */
     if ($product_variety_id = $this->insertVariety($variety_data)) {
         require_once 'models/ecommerce/ecommerce_price.php';
         $Price = new ecommerce_price();
         $price_data = $data['price'];
         $price_data['product_variety_id'] = $product_variety_id;
         if ($price_id = $Price->priceInsert($price_data)) {
             return $product_variety_id;
         } else {
             msg("Adding of price failed", "error");
             //it's still quite positive result :)
             return true;
         }
     } else {
         msg("Can't add product variety. Are you sure SKU is not used by other product?", "error");
         return false;
     }
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * TODO:
      * implement general updateSingleAttribute()
      */
     //print_r($_POST);
     $model = $this->GET['model'];
     $attribute = $this->GET['attribute'];
     $update_value = trim($_POST['update_value']);
     $original_value = trim($_POST['original_html']);
     // currently implemented for product_variety.name and price.value
     switch ($model) {
         case 'common_node':
             require_once 'models/common/common_node.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $ModelObj = new common_node();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) {
                 msg('Failed', 'error');
             }
             break;
         case 'ecommerce_product_variety':
             require_once 'models/ecommerce/ecommerce_product_variety.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $ModelObj = new ecommerce_product_variety();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) {
                 msg('Failed', 'error');
             }
             break;
         case 'ecommerce_price':
             require_once 'models/ecommerce/ecommerce_price.php';
             $ModelObj = new ecommerce_price();
             $element_id_parts = explode('-', $_POST['element_id']);
             $variety_id = $element_id_parts[3];
             $last_price = $ModelObj->getLastPriceForVariety($variety_id);
             //remove anything else than number and decimal point
             $update_value = preg_replace("/[^0-9\\.]*/", '', $update_value);
             //update only when the new price is different than old price
             if (round($last_price['value'], 2) != round($update_value, 2)) {
                 if (!$ModelObj->updateSingleAttribute('value', $update_value, $last_price['id'])) {
                     msg('Failed', 'error');
                 }
             }
             break;
         case 'international_translation':
             require_once 'models/international/international_translation.php';
             $element_id_parts = explode('-', $_POST['element_id']);
             $updated_id = $element_id_parts[3];
             $ModelObj = new international_translation();
             if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $updated_id)) {
                 msg('Failed', 'error');
             }
             break;
         default:
             return false;
             break;
     }
     if ($update_value != $original_value) {
         $value = $update_value;
     } else {
         $value = $original_value;
     }
     $this->tpl->assign('VALUE', $value);
     return true;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     return false;
     set_time_limit(0);
     $process = $this->GET['process'];
     $process = 0;
     require_once 'models/ecommerce/ecommerce_product.php';
     require_once 'models/ecommerce/ecommerce_product_variety.php';
     require_once 'models/ecommerce/ecommerce_price.php';
     require_once 'models/common/common_node.php';
     $Product = new ecommerce_product();
     $Product_variety = new ecommerce_product_variety();
     $Price = new ecommerce_price();
     $Node = new common_node();
     //START THE TRANSACTION
     $Product->db->beginTransaction();
     //get data file
     if ($this->GET['data_file'] != '') {
         $data_file = ONXSHOP_PROJECT_DIR . $this->GET['data_file'];
         if (file_exists($data_file)) {
             $google_base = $this->convertCSVtoAssocMArray($data_file, ";");
         } else {
             msg("Datafile {$data_file} does not exists", 'error');
         }
     }
     foreach ($google_base as $gb) {
         $onxshop_product['name'] = ucwords(strtolower(trim($gb['title'])));
         //check if the product name has been changed, if not, it's only new variety
         if ($watch_name != $onxshop_product['name']) {
             $watch_name = $onxshop_product['name'];
             $onxshop_product['teaser'] = $gb['teaser'];
             if ($gb['description'] != '') {
                 $onxshop_product['description'] = $gb['description'];
             } else {
                 $onxshop_product['description'] = $onxshop_product['name'];
             }
             $onxshop_product['priority'] = 0;
             $onxshop_product['brand_id'] = 1;
             $onxshop_product['publish'] = 1;
             //Food
             //if ($gb['tax_percent'] == 19) $onxshop_product['product_type_id'] = 7;
             //Food-Bio
             //else if ($gb['tax_percent'] == 5) $onxshop_product['product_type_id'] = 8;
             /*
             if ($gb['vat_group'] == 'tea') $onxshop_product['product_type_id'] = 9;
             else if ($gb['vat_group'] == 'tea ware') $onxshop_product['product_type_id'] = 10;
             else msg("Unknown vat group (product_type_id) {$gb['vat_group']}", 'error');
             */
             $onxshop_product['product_type_id'] = 9;
             //other data
             unset($onxshop_product['other_data']);
             if ($gb['other_data-taste'] != '') {
                 $onxshop_product['other_data']['taste'] = $gb['other_data-taste'];
             }
             if ($gb['other_data-infuse'] != '') {
                 $onxshop_product['other_data']['infuse'] = $gb['other_data-infuse'];
             }
             if ($gb['other_data-drink'] != '') {
                 $onxshop_product['other_data']['drink'] = $gb['other_data-drink'];
             }
             $onxshop_product['other_data'] = serialize($onxshop_product['other_data']);
             //taxonomy
             $_POST['product']['rt'][] = '';
             /*
             				switch (strtolower($gb['taxonomy-region'])) {
             					case 'china':
             						$_POST['product']['rt'][] =  18;
             					break;
             					case 'india':
             						$_POST['product']['rt'][] =  19;
             					break;
             					case 'japan':
             						$_POST['product']['rt'][] =  20;
             					break;
             					case 'sri lanka':
             						$_POST['product']['rt'][] =  21;
             					break;
             					case 'taiwan':
             						$_POST['product']['rt'][] =  34;
             					break;
             				}*/
             switch (trim($gb['brand'])) {
                 case 'Aqualeader':
                     $_POST['product']['rt'][] = 6;
                     break;
                 case 'Atlantic':
                     $_POST['product']['rt'][] = 14;
                     break;
                 case 'Bosta':
                     $_POST['product']['rt'][] = 19;
                     break;
                 case 'Catalina':
                     $_POST['product']['rt'][] = 16;
                     break;
                 case 'Doughboy':
                     $_POST['product']['rt'][] = 8;
                     break;
                 case 'Easy Cove':
                     $_POST['product']['rt'][] = 22;
                     break;
                 case 'Equinox':
                     $_POST['product']['rt'][] = 7;
                     break;
                 case 'Esther Williams':
                     $_POST['product']['rt'][] = 4;
                     break;
                 case 'Folkpool':
                     $_POST['product']['rt'][] = 9;
                     break;
                 case 'Freedom':
                     $_POST['product']['rt'][] = 11;
                     break;
                 case 'Garden Leisure':
                     $_POST['product']['rt'][] = 10;
                     break;
                 case 'Hayward':
                     $_POST['product']['rt'][] = 23;
                     break;
                 case 'Insta':
                     $_POST['product']['rt'][] = 17;
                     break;
                 case 'Kafko':
                     $_POST['product']['rt'][] = 15;
                     break;
                 case 'Kreepy Krauly':
                     $_POST['product']['rt'][] = 25;
                     break;
                 case 'Plastica':
                     $_POST['product']['rt'][] = 21;
                     break;
                 case 'Polaris':
                     $_POST['product']['rt'][] = 24;
                     break;
                 case 'Pomaz':
                     $_POST['product']['rt'][] = 12;
                     break;
                 case 'Spaform':
                     $_POST['product']['rt'][] = 13;
                     break;
                 case 'Sta-Rite':
                     $_POST['product']['rt'][] = 26;
                     break;
                 case 'Vogue':
                     $_POST['product']['rt'][] = 5;
                     break;
                 case 'Voyager':
                     $_POST['product']['rt'][] = 18;
                     break;
                 case 'Waterpik':
                     $_POST['product']['rt'][] = 20;
                     break;
             }
             $_Onxshop_Request = new Onxshop_Request("bo/component/relation_taxonomy~relation=product:id={$product_id}~");
             //print_r($onxshop_product);
             $product_id = $Product->insert($onxshop_product);
             if (is_numeric($product_id)) {
                 //image add
                 if ($gb['image_link'] != '') {
                     $_POST['file']['title'] = $onxshop_product['name'];
                     $_POST['file']['src'] = "var/files/products/{$gb['image_link']}.jpg";
                     $_POST['file']['priority'] = 0;
                     $_POST['file']['role'] = 'main';
                     $_POST['file']['node_id'] = $product_id;
                     $_POST['add'] = 'add';
                     $file = ONXSHOP_PROJECT_DIR . $_POST['file']['src'];
                     if (file_exists($file)) {
                         $_Onxshop_Request = new Onxshop_Request("bo/component/form_file~relation=product~");
                     } else {
                         msg("File {$file} does not exists", 'error');
                     }
                     unset($_POST['file']);
                 }
                 //add to node
                 $_POST['product']['name'] = $onxshop_product['name'];
                 $_POST['product']['publish'] = 1;
                 $_POST['product']['pin'][] = '';
                 $_POST['product']['pin'][] = $gb['page_id'];
                 $_Onxshop_Request = new Onxshop_Request("bo/component/ecommerce/relation_product_in_nodes~id={$product_id}~");
                 unset($_POST['product']);
             }
         }
         if (is_numeric($product_id)) {
             $onxshop_product_variety['name'] = $gb['variety_name'];
             $onxshop_product_variety['product_id'] = $product_id;
             $onxshop_product_variety['sku'] = $gb['sku'];
             if (is_numeric($gb['weight'])) {
                 $onxshop_product_variety['weight'] = $gb['weight'];
             } else {
                 $onxshop_product_variety['weight'] = -1;
             }
             $onxshop_product_variety['stock'] = $gb['stock'];
             $onxshop_product_variety['priority'] = 0;
             $onxshop_product_variety['description'] = '';
             $product_variety_id = $Product_variety->insert($onxshop_product_variety);
             //print_r($onxshop_product_variety);
             if (is_numeric($product_variety_id)) {
                 $onxshop_price['product_variety_id'] = $product_variety_id;
                 $onxshop_price['currency_code'] = $GLOBALS['onxshop_conf']['global']['default_currency'];
                 $onxshop_price['value'] = $gb['price'];
                 //$onxshop_price['value'] = $gb['price'] / 117.5 * 100;
                 $onxshop_price['type'] = 'common';
                 $onxshop_price['date'] = date('c');
                 $price_id = $Price->insert($onxshop_price);
             }
         }
     }
     // COMPLETE THE TRANSACTION
     if ($process) {
         if ($Product->db->commit()) {
             msg('CompleteTrans');
         } else {
             msg('Some error in the import, try debug.');
         }
     } else {
         msg("Some errors in import has occurred", 'error');
         msg('RollbackTrans');
         //$this->tpl->parse();
         $Product->db->rollBack();
     }
 }