Beispiel #1
0
 function writeNumber($row, $col, $value, $lastOne)
 {
     if ($this->format == 1) {
         $this->currLine = $row;
         $this->buffer .= pack("sssss", 0x203, 14, $row, $col, 0x0);
         $this->buffer .= pack("d", $value);
     } else {
         if ($this->currLine < $row) {
             $this->newLine();
         }
         $this->currLine = $row;
         $floatValue = (double) hikashop_toFloat($value);
         if ($floatValue == (int) $floatValue) {
             $this->buffer .= (int) $value;
         } else {
             $this->buffer .= number_format($floatValue, 5, $this->decimal_separator, '');
         }
         if (!$lastOne) {
             $this->buffer .= $this->separator;
         }
     }
 }
Beispiel #2
0
 public function saveForm($task = '')
 {
     $do = false;
     $forbidden = array();
     $order_id = hikashop_getCID('order_id');
     $addressClass = hikashop_get('class.address');
     $fieldsClass = hikashop_get('class.field');
     jimport('joomla.filter.filterinput');
     $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
     $oldOrder = $this->get($order_id);
     $order = clone $oldOrder;
     $order->history = new stdClass();
     $data = JRequest::getVar('data', array(), '', 'array');
     if (empty($order_id) || empty($order->order_id)) {
         $this->sendEmailAfterOrderCreation = false;
     } else {
         $order->history->history_notified = false;
     }
     $currentTask = 'billing_address';
     if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask])) {
         $oldAddress = null;
         if (!empty($oldOrder->order_billing_address_id)) {
             $oldAddress = $addressClass->get($oldOrder->order_billing_address_id);
         }
         $billing_address = $fieldsClass->getInput(array($currentTask, 'address'), $oldAddress);
         if (!empty($billing_address) && !empty($order_id)) {
             $result = $addressClass->save($billing_address, $order_id, 'billing');
             if ($result) {
                 $order->order_billing_address_id = (int) $result;
                 $do = true;
             }
         }
     }
     $currentTask = 'shipping_address';
     if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask])) {
         $oldAddress = null;
         if (!empty($oldOrder->order_shipping_address_id)) {
             $oldAddress = $addressClass->get($oldOrder->order_shipping_address_id);
         }
         $shipping_address = $fieldsClass->getInput(array($currentTask, 'address'), $oldAddress);
         if (!empty($shipping_address) && !empty($order_id)) {
             $result = $addressClass->save($shipping_address, $order_id, 'shipping');
             if ($result) {
                 $order->order_shipping_address_id = (int) $result;
                 $result = $this->save($order);
                 $do = true;
             }
         }
     }
     $currentTask = 'general';
     if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask])) {
         if (!empty($data['order']['order_status'])) {
             $order->order_status = $safeHtmlFilter->clean($data['order']['order_status'], 'string');
             $do = true;
         }
         if (!empty($data['notify'])) {
             if (empty($order->history)) {
                 $order->history = new stdClass();
             }
             $order->history->history_notified = true;
         }
     }
     $currentTask = 'additional';
     if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask]) && !isset($forbidden[$currentTask])) {
         if (isset($data['order']['order_discount_code'])) {
             $order->order_discount_code = $safeHtmlFilter->clean($data['order']['order_discount_code'], 'string');
             $do = true;
         }
         if (isset($data['order']['order_discount_price'])) {
             $order->order_discount_price = (double) hikashop_toFloat($data['order']['order_discount_price']);
             $do = true;
         }
         if (isset($data['order']['order_discount_tax'])) {
             $order->order_discount_tax = (double) hikashop_toFloat($data['order']['order_discount_tax']);
             $do = true;
         }
         if (isset($data['order']['order_discount_tax_namekey'])) {
             $order->order_discount_tax_namekey = $safeHtmlFilter->clean($data['order']['order_discount_tax_namekey'], 'string');
             $do = true;
         }
         if (!empty($data['order']['shipping'])) {
             if (is_string($data['order']['shipping'])) {
                 list($shipping_method, $shipping_id) = explode('_', $data['order']['shipping'], 2);
                 $order->order_shipping_method = $safeHtmlFilter->clean($shipping_method, 'string');
                 $order->order_shipping_id = $safeHtmlFilter->clean($shipping_id, 'string');
                 $do = true;
             }
             if (is_array($data['order']['shipping'])) {
                 $order->order_shipping_method = '';
                 $shippings = array();
                 $order->order_shipping_params->prices = array();
                 foreach ($data['order']['shipping'] as $shipping_group => $shipping_value) {
                     list($shipping_method, $shipping_id) = explode('_', $shipping_value, 2);
                     $n = $safeHtmlFilter->clean($shipping_id, 'string') . '@' . $safeHtmlFilter->clean($shipping_group, 'string');
                     $shippings[] = $n;
                     $order->order_shipping_params->prices[$n] = new stdClass();
                     $order->order_shipping_params->prices[$n]->price_with_tax = @$data['order']['order_shipping_prices'][$shipping_group];
                     $order->order_shipping_params->prices[$n]->tax = @$data['order']['order_shipping_taxs'][$shipping_group];
                 }
                 $order->order_shipping_id = implode(';', $shippings);
                 $do = true;
                 if (!empty($data['order']['warehouses'])) {
                     $orderProductClass = hikashop_get('class.order_product');
                     $db = JFactory::getDBO();
                     $db->setQuery('SELECT * FROM ' . hikashop_table('order_product') . ' WHERE order_id = ' . (int) $order_id);
                     $order_products = $db->loadObjectList('order_product_id');
                     foreach ($data['order']['warehouses'] as $pid => $w) {
                         if (isset($order_products[$pid]) && isset($data['order']['shipping'][$w])) {
                             $p = $order_products[$pid];
                             list($shipping_method, $shipping_id) = explode('_', $data['order']['shipping'][$w], 2);
                             $p->order_product_shipping_id = $safeHtmlFilter->clean($shipping_id, 'string') . '@' . $safeHtmlFilter->clean($w, 'string');
                             $p->order_product_shipping_method = $safeHtmlFilter->clean($shipping_method, 'string');
                             $orderProductClass->update($p);
                         }
                     }
                 }
             }
         }
         if (isset($data['order']['order_shipping_price'])) {
             $order->order_shipping_price = (double) hikashop_toFloat($data['order']['order_shipping_price']);
             $do = true;
         }
         if (isset($data['order']['order_shipping_tax'])) {
             $order->order_shipping_tax = (double) hikashop_toFloat($data['order']['order_shipping_tax']);
             $do = true;
         }
         if (isset($data['order']['order_shipping_tax_namekey'])) {
             $order->order_shipping_tax_namekey = $safeHtmlFilter->clean($data['order']['order_shipping_tax_namekey'], 'string');
             $do = true;
         }
         if (!empty($data['order']['payment'])) {
             list($payment_method, $payment_id) = explode('_', $data['order']['payment'], 2);
             $order->order_payment_method = $safeHtmlFilter->clean($payment_method, 'string');
             $order->order_payment_id = $safeHtmlFilter->clean($payment_id, 'string');
             $do = true;
         }
         if (isset($data['order']['order_payment_price'])) {
             $order->order_payment_price = (double) hikashop_toFloat($data['order']['order_payment_price']);
             $do = true;
         }
         if (isset($data['order']['order_payment_tax'])) {
             $order->order_payment_tax = (double) hikashop_toFloat($data['order']['order_payment_tax']);
             $do = true;
         }
         if (isset($data['order']['order_payment_tax_namekey'])) {
             $order->order_payment_tax_namekey = $safeHtmlFilter->clean($data['order']['order_payment_tax_namekey'], 'string');
             $do = true;
         }
         if (!empty($data['notify'])) {
             if (empty($order->history)) {
                 $order->history = new stdClass();
             }
             $order->history->history_notified = true;
         }
     }
     $currentTask = 'customfields';
     $validTasks = array('customfields', 'additional');
     if ((empty($task) || in_array($task, $validTasks)) && !empty($data[$currentTask])) {
         $old = null;
         $orderFields = $fieldsClass->getInput(array('orderfields', 'order'), $old, true, 'data', false, 'backend');
         if (!empty($orderFields)) {
             $do = true;
             foreach ($orderFields as $key => $value) {
                 if (!empty($value) || count($value) > 0) {
                     $order->{$key} = $value;
                 }
             }
         }
     }
     $currentTask = 'customer';
     if (empty($task) || $task == $currentTask) {
         $order_user_id = (int) $data['order']['order_user_id'];
         if ($order_user_id > 0) {
             $order->order_user_id = $order_user_id;
             $do = true;
             $set_address = JRequest::getInt('set_user_address', 0);
             if ($set_address) {
                 $db = JFactory::getDBO();
                 $db->setQuery('SELECT address_id FROM ' . hikashop_table('address') . ' WHERE address_user_id = ' . (int) $order_user_id . ' AND address_published = 1 ORDER BY address_default DESC, address_id ASC LIMIT 1');
                 $address_id = $db->loadResult();
                 if ($address_id) {
                     $order->order_billing_address_id = (int) $address_id;
                     $order->order_shipping_address_id = (int) $address_id;
                 }
             }
         }
     }
     $currentTask = 'products';
     $config = hikashop_config();
     $createdStatus = $config->get('order_created_status', 'created');
     $noUpdateQty = 0;
     if ($createdStatus == $order->order_status && $config->get('update_stock_after_confirm')) {
         $noUpdateQty = 1;
     }
     if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask])) {
         $orderProductClass = hikashop_get('class.order_product');
         $productData = $data['order']['product'];
         if (isset($productData['many']) && $productData['many'] == true) {
             unset($productData['many']);
             $product = new stdClass();
             $order->product = array();
             foreach ($productData as $singleProduct) {
                 foreach ($singleProduct as $key => $value) {
                     hikashop_secureField($key);
                     $product->{$key} = $safeHtmlFilter->clean($value, 'string');
                 }
                 if ($noUpdateQty) {
                     $product->no_update_qty = true;
                 }
                 $orderProductClass->update($product);
                 $order->product[] = $product;
             }
         } else {
             if (isset($productData['order_id'])) {
                 $product = new stdClass();
                 $fieldClass = hikashop_get('class.field');
                 $oldData = null;
                 $item_fields = $fieldClass->getData('backend', 'item');
                 $ret = $fieldClass->_checkOneInput($item_fields, $productData, $product, 'item', $oldData);
                 foreach ($productData as $key => $value) {
                     hikashop_secureField($key);
                     if (isset($items_fields[$key])) {
                         continue;
                     }
                     $product->{$key} = $safeHtmlFilter->clean($value, 'string');
                 }
                 $product->order_id = (int) $order_id;
                 if ($noUpdateQty) {
                     $product->no_update_qty = true;
                 }
                 $orderProductClass->update($product);
                 $order->product = array($product);
             } else {
                 $order->product = array();
                 foreach ($productData as $data) {
                     $product = new stdClass();
                     foreach ($data as $key => $value) {
                         hikashop_secureField($key);
                         $product->{$key} = $safeHtmlFilter->clean($value, 'string');
                     }
                     $product->order_id = (int) $order_id;
                     if ($noUpdateQty) {
                         $product->no_update_qty = true;
                     }
                     $orderProductClass->update($product);
                     $order->product[] = $product;
                 }
             }
         }
         $this->recalculateFullPrice($order);
         $do = true;
     }
     if (!empty($task) && $task == 'product_delete') {
         $order_product_id = JRequest::getInt('order_product_id', 0);
         if ($order_product_id > 0) {
             $orderProductClass = hikashop_get('class.order_product');
             $order_product = $orderProductClass->get($order_product_id);
             if (!empty($order_product) && $order_product->order_id == $order_id) {
                 $order_product->order_product_quantity = 0;
                 if ($noUpdateQty) {
                     $order_product->no_update_qty = true;
                 }
                 $orderProductClass->update($order_product);
                 $order->product[] = $order_product;
                 $this->recalculateFullPrice($order);
                 $do = true;
             }
         }
     }
     if ($do) {
         if (!empty($data['history']['store_data'])) {
             if (isset($data['history']['msg'])) {
                 $order->history->history_data = $safeHtmlFilter->clean($data['history']['msg'], 'string');
             } else {
                 $order->history->history_data = $safeHtmlFilter->clean(@$data['history']['history_data'], 'string');
             }
         }
         if (!empty($data['history']['usermsg_send'])) {
             if (isset($data['history']['usermsg'])) {
                 $order->usermsg->usermsg = $safeHtmlFilter->clean($data['history']['usermsg'], 'string');
             }
         }
         $result = $this->save($order);
         return $result;
     }
     return false;
 }
Beispiel #3
0
 function getprice()
 {
     $price = JRequest::getVar('price');
     $productClass = hikashop_get('class.product');
     $price = hikashop_toFloat($price);
     $tax_id = JRequest::getInt('tax_id');
     $conversion = JRequest::getInt('conversion');
     $currencyClass = hikashop_get('class.currency');
     $config =& hikashop_config();
     $main_tax_zone = explode(',', $config->get('main_tax_zone', 1346));
     $newprice = $price;
     if (count($main_tax_zone) && !empty($tax_id) && !empty($price) && !empty($main_tax_zone)) {
         $function = 'getTaxedPrice';
         if ($conversion) {
             $function = 'getUntaxedPrice';
         }
         $newprice = $currencyClass->{$function}($price, array_shift($main_tax_zone), $tax_id, 5);
     }
     echo $newprice;
     exit;
 }
Beispiel #4
0
 function onProcessProductMassFiltercsvImport(&$elements, &$query, $filter, $num)
 {
     if (empty($filter['type']) || $filter['type'] == 'all') {
         return;
     }
     if (!isset($this->massaction)) {
         $this->massaction = hikashop_get('class.massaction');
     }
     if (count($elements)) {
         foreach ($elements as $k => $element) {
             if ($element->{$filter}['type'] != $filter['value']) {
                 unset($elements[$k]);
             }
         }
     } else {
         $data = $this->massaction->getFromFile($filter);
         if (empty($data->ids) || is_null($data->ids) || isset($data->error)) {
             $query->where[] = '1=2';
             return false;
         }
         JArrayHelper::toInteger($data->ids);
         $db = JFactory::getDBO();
         $productClass = hikashop_get('class.product');
         $productClass->getProducts($data->ids);
         $pool = array();
         foreach ($data->ids as $i => $id) {
             if (!isset($data->elements[$id]->product_id) || !isset($data->elements[$id]->product_code) || !isset($data->elements[$id]->product_parent_id)) {
                 continue;
             }
             $pool[$data->elements[$id]->product_code] = array();
             $pool[$data->elements[$id]->product_code]['id'] = $data->elements[$id]->product_id;
             $pool[$data->elements[$id]->product_code]['parent_id'] = $data->elements[$id]->product_parent_id;
         }
         $toGet = array();
         foreach ($data->ids as $i => $id) {
             if (isset($data->elements[$id]->product_parent_id) && $data->elements[$id]->product_parent_id != '' && (int) $data->elements[$id]->product_parent_id == 0 && !in_array($data->elements[$id]->product_parent_id, $pool) && !in_array($data->elements[$id]->product_parent_id, $toGet)) {
                 $toGet[] = $data->elements[$id]->product_parent_id;
             }
         }
         $db->setQuery('SELECT * FROM ' . hikashop_table('product') . ' WHERE product_code IN (\'' . implode('\',\'', $toGet) . '\')');
         $gets = $db->loadObjectList();
         foreach ($gets as $get) {
             $pool[$get->product_code]['id'] = $get->product_id;
             $pool[$get->product_code]['parent_id'] = $get->product_parent_id;
         }
         if (!is_array($data->ids)) {
             $data->ids = array($data->ids);
         }
         foreach ($data->ids as $i => $id) {
             if (!isset($data->elements[$id])) {
                 continue;
             }
             $data->elements[$id]->product_id = (int) $data->elements[$id]->product_id;
             if (isset($data->elements[$id]->product_type) && $data->elements[$id]->product_type == 'variant' && (int) $data->elements[$id]->product_parent_id == 0) {
                 if (array_key_exists($data->elements[$id]->product_parent_id, $pool)) {
                     $data->elements[$id]->product_parent_id = $pool[$data->elements[$id]->product_parent_id]['id'];
                 } else {
                     continue;
                 }
             }
             $oldElement = $productClass->all_products[$id];
             if (!empty($data->elements[$id]->price_value_with_tax)) {
                 $currencyHelper = hikashop_get('class.currency');
                 if (empty($data->elements[$id]->product_tax_id)) {
                     if (!empty($oldElement->product_tax_id)) {
                         $data->elements[$id]->product_tax_id = $oldElement->product_tax_id;
                     } else {
                         $data->elements[$id]->product_tax_id = $currencyHelper->getTaxCategory();
                     }
                 }
                 if ($data->elements[$id]->product_tax_id) {
                     if (strpos($data->elements[$id]->price_value_with_tax, '|') === false) {
                         $data->elements[$id]->price_value = $currencyHelper->getUntaxedPrice(hikashop_toFloat($data->elements[$id]->price_value_with_tax), hikashop_getZone(), $data->elements[$id]->product_tax_id);
                     } else {
                         $price_value = explode('|', $data->elements[$id]->price_value_with_tax);
                         foreach ($price_value as $k => $price_value_one) {
                             $price_value[$k] = $currencyHelper->getUntaxedPrice($price_value_one, hikashop_getZone(), $data->elements[$id]->product_tax_id);
                         }
                         $data->elements[$id]->price_value = implode('|', $price_value);
                     }
                 }
                 unset($data->elements[$id]->price_value_with_tax);
             }
             if (!empty($data->elements[$id]->price_value)) {
                 $data->elements[$id]->prices = array();
                 $price_values = explode('|', $data->elements[$id]->price_value);
                 $price_currencies = explode('|', $data->elements[$id]->price_currency_id);
                 $nbPrices = count($price_values) - 1;
                 if (!isset($data->elements[$id]->price_min_quantity)) {
                     $data->elements[$id]->price_min_quantity = '1';
                     if ($nbPrices) {
                         $data->elements[$id]->price_min_quantity = $data->elements[$id]->price_min_quantity . str_repeat('|1', $nbPrices);
                     }
                 }
                 if (!isset($data->elements[$id]->price_access)) {
                     $data->elements[$id]->price_access = 'all';
                     if ($nbPrices) {
                         $data->elements[$id]->price_access = $data->elements[$id]->price_access . str_repeat('|all', $nbPrices);
                     }
                 }
                 $price_min_quantities = explode('|', $data->elements[$id]->price_min_quantity);
                 $price_accesses = explode('|', $data->elements[$id]->price_access);
                 foreach ($price_values as $k => $price_value) {
                     $data->elements[$id]->prices[$k] = new stdClass();
                     $data->elements[$id]->prices[$k]->price_value = $price_value;
                 }
                 foreach ($price_currencies as $k => $price_currency) {
                     if (!is_int($price_currency)) {
                         $db->setQuery('SELECT currency_id FROM ' . hikashop_table('currency') . ' WHERE currency_code LIKE ' . $db->quote($price_currency));
                         $price_currency_id = $db->loadResult();
                     }
                     $data->elements[$id]->prices[$k]->price_currency_id = $price_currency_id;
                 }
                 foreach ($price_min_quantities as $k => $price_min_quantity) {
                     $data->elements[$id]->prices[$k]->price_min_quantity = $price_min_quantity;
                 }
                 foreach ($price_accesses as $k => $price_access) {
                     $data->elements[$id]->prices[$k]->price_access = $price_access;
                 }
             }
             unset($data->elements[$id]->price_value);
             unset($data->elements[$id]->price_currency_id);
             unset($data->elements[$id]->price_min_quantity);
             unset($data->elements[$id]->price_access);
             if (!empty($data->elements[$id]->files)) {
                 $newFiles = explode(';', $data->elements[$id]->files);
                 $data->elements[$id]->files = array();
                 foreach ($newFiles as $k => $newFile) {
                     $same = 0;
                     foreach ($oldElement->files as $oldFile) {
                         if ($oldFile->file_path == $newFile) {
                             $data->elements[$id]->files[] = $oldFile->file_id;
                             $same = 1;
                         }
                     }
                     if (!empty($newFile) && $same == 0) {
                         $db->setQuery('SELECT file_id FROM ' . hikashop_table('file') . ' WHERE file_path LIKE ' . $db->quote($newFile));
                         $newFileId = $db->loadResult();
                         if (!empty($newFileId)) {
                             $data->elements[$id]->files[] = $newFileId;
                         }
                     }
                 }
             }
             if (!empty($data->elements[$id]->images)) {
                 $newImages = explode(';', $data->elements[$id]->images);
                 $data->elements[$id]->images = array();
                 foreach ($newImages as $k => $newImage) {
                     $same = 0;
                     foreach ($oldElement->images as $oldImage) {
                         if (!empty($newImage) && $oldImage->file_path == $newImage) {
                             $data->elements[$id]->images[] = $oldImage->file_id;
                             $same = 1;
                         }
                     }
                     if (!empty($newImage) && $same == 0) {
                         $db->setQuery('SELECT file_id FROM ' . hikashop_table('file') . ' WHERE file_path LIKE ' . $db->quote($newImage));
                         $newImageId = $db->loadResult();
                         if (!empty($newImageId)) {
                             $data->elements[$id]->images[] = $newImageId;
                         }
                     }
                 }
             }
             if (!empty($data->elements[$id]->categories)) {
                 $categories = explode(';', $data->elements[$id]->categories);
                 $data->elements[$id]->categories = array();
                 foreach ($categories as $category) {
                     $db->setQuery('SELECT category_id FROM ' . hikashop_table('category') . ' WHERE category_name LIKE ' . $db->quote($category));
                     $data->elements[$id]->categories[] = $db->loadResult();
                 }
             }
             if (!empty($data->elements[$id]->categories_ordering)) {
                 $data->elements[$id]->categories_ordering = explode(';', $data->elements[$id]->categories_ordering);
                 unset($oldElement->categories_ordering);
             }
             if (!empty($data->elements[$id]->related)) {
                 $relateds = explode(';', $data->elements[$id]->related);
                 $data->elements[$id]->related = array();
                 foreach ($relateds as $k => $related) {
                     $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_code LIKE ' . $db->quote($related));
                     $data->elements[$id]->related[$k]->product_related_id = $db->loadResult();
                     $data->elements[$id]->related[$k]->product_id = $id;
                     $data->elements[$id]->related[$k]->product_related_ordering = $k;
                     $data->elements[$id]->related[$k]->product_related_type = 'related';
                 }
             }
             if (!empty($data->elements[$id]->options)) {
                 $options = explode(';', $data->elements[$id]->options);
                 $data->elements[$id]->options = array();
                 foreach ($options as $option) {
                     $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_code LIKE ' . $db->quote($option));
                     $data->elements[$id]->options[$k]->product_related_id = $db->loadResult();
                     $data->elements[$id]->options[$k]->product_id = $id;
                     $data->elements[$id]->options[$k]->product_related_ordering = $k;
                     $data->elements[$id]->options[$k]->product_related_type = 'related';
                 }
             }
             unset($oldElement->images);
             unset($oldElement->files);
             unset($oldElement->related);
             unset($oldElement->options);
             foreach ($oldElement as $k => $old) {
                 foreach ($data->elements[$id] as $l => $new) {
                     if ($k == $l) {
                         $oldElement->{$k} = $new;
                     }
                 }
             }
             $data->elements[$id] = $oldElement;
             if (isset($filter['save'])) {
                 if (isset($data->elements[$id]->prices)) {
                     $productClass->updatePrices($data->elements[$id], $id);
                 }
                 if ($data->elements[$id]->product_type != 'variant') {
                     $productClass->updateCategories($data->elements[$id], $id);
                 }
                 if (!empty($data->elements[$id]->files)) {
                     $productClass->updateFiles($data->elements[$id], $id, 'files');
                 }
                 if (!empty($data->elements[$id]->images)) {
                     $productClass->updateFiles($data->elements[$id], $id, 'images');
                 }
                 if (!empty($data->elements[$id]->related)) {
                     $productClass->updateRelated($data->elements[$id], $id, 'related');
                 }
                 if (!empty($data->elements[$id]->options)) {
                     $productClass->updateRelated($data->elements[$id], $id, 'options');
                 }
                 unset($oldElement->categories);
                 $db->setQuery('SHOW columns FROM ' . hikashop_table('product'));
                 $cols = $db->loadObjectList();
                 $fields = array();
                 foreach ($cols as $col) {
                     $fields[] = $col->Field;
                 }
                 foreach ($data->elements[$id] as $l => $content) {
                     if (!in_array($l, $fields)) {
                         unset($data->elements[$id]->{$l});
                     }
                 }
                 if (isset($data->elements[$id]->product_created) && (int) $data->elements[$id]->product_created == 0) {
                     unset($data->elements[$id]->product_created);
                 }
                 $data->elements[$id]->product_modified = time();
                 $data->elements[$id]->product_width = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_width);
                 $data->elements[$id]->product_length = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_length);
                 $data->elements[$id]->product_height = str_replace($data->elements[$id]->product_dimension_unit, '', $data->elements[$id]->product_height);
                 $elements = $data->elements;
                 $productClass->save($elements[$id]);
             }
         }
         $elements = $data->elements;
         if ($filter['type'] == 'out') {
             JArrayHelper::toInteger($data->ids);
             $db->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE product_id NOT IN (' . implode(',', $data->ids) . ')');
             $ids = $db->loadResultArray();
             $productClass = hikashop_get('class.product');
             $elements = array();
             foreach ($ids as $id) {
                 $elements[] = $productClass->get($id);
             }
         }
     }
     return 'onProcessProductMassFiltercsvImport called';
 }
Beispiel #5
0
/**
 * @package	HikaShop for Joomla!
 * @version	2.6.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2015 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.tooltip');
$row =& $this->rows;
$config = hikashop_config();
if ($row->vote_enabled != 1) {
    return;
}
$row->hikashop_vote_average_score = (double) hikashop_toFloat($row->hikashop_vote_average_score);
JRequest::setVar("rate_rounded", $row->hikashop_vote_average_score_rounded);
JRequest::setVar("nb_max_star", $row->hikashop_vote_nb_star);
$main_div_name = $row->main_div_name;
$hikashop_vote_user_id = hikashop_loadUser();
if (empty($hikashop_vote_user_id)) {
    $hikashop_vote_user_id = 0;
}
$select_id = "select_id_" . $row->vote_ref_id;
if ($main_div_name != '') {
    $select_id .= "_" . $main_div_name;
} else {
    $select_id .= "_hikashop_main_div_name";
}
if ($config->get('enable_status_vote', 'vote') != 'both') {
    if (empty($main_div_name)) {
Beispiel #6
0
 function calculateTotal(&$rows, &$order, $currency_id)
 {
     $total = new stdClass();
     $total->price_value = 0.0;
     $total->price_value_with_tax = 0.0;
     $total->price_currency_id = $currency_id;
     $total->taxes = array();
     $rounding = $this->getRounding($currency_id, true);
     $quantity = 0;
     foreach ($rows as $k => $row) {
         if (empty($row->prices) || $row->cart_product_quantity <= 0) {
             continue;
         }
         $price = reset($row->prices);
         foreach (get_object_vars($total) as $key => $value) {
             if (!in_array($key, array('price_currency_id', 'price_orig_currency_id', 'price_value_without_discount_with_tax', 'price_value_without_discount', 'taxes')) && isset($price->{$key})) {
                 $total->{$key} = $total->{$key} + (double) hikashop_toFloat($price->{$key});
             }
         }
         if (!isset($price->taxes)) {
             continue;
         }
         foreach ($price->taxes as $tax) {
             if (isset($total->taxes[$tax->tax_namekey])) {
                 $total->taxes[$tax->tax_namekey]->tax_amount += $this->round($tax->tax_amount, $rounding);
             } else {
                 $total->taxes[$tax->tax_namekey] = new stdClass();
                 $total->taxes[$tax->tax_namekey]->tax_namekey = $tax->tax_namekey;
                 $total->taxes[$tax->tax_namekey]->tax_rate = $tax->tax_rate;
                 $total->taxes[$tax->tax_namekey]->tax_amount = $this->round($tax->tax_amount, $rounding);
             }
         }
     }
     if (!empty($total->taxes)) {
         $total_taxes = 0;
         foreach ($total->taxes as $tax) {
             $total_taxes += $tax->tax_amount;
         }
         $total->price_value_with_tax = $total->price_value + $total_taxes;
     }
     if (is_null($order)) {
         $order = new stdClass();
     }
     $order->prices = array($total);
 }
Beispiel #7
0
 function &loadFullCart($additionalInfos = false, $keepEmptyCart = false, $skipChecks = false)
 {
     $app = JFactory::getApplication();
     $database = JFactory::getDBO();
     $config =& hikashop_config();
     $currencyClass = hikashop_get('class.currency');
     $productClass = hikashop_get('class.product');
     $main_currency = (int) $config->get('main_currency', 1);
     $currency_id = hikashop_getCurrency();
     if (!in_array($currency_id, $currencyClass->publishedCurrencies())) {
         $currency_id = $main_currency;
     }
     $zone_id = hikashop_getZone('shipping');
     if ($config->get('tax_zone_type', 'shipping') == 'billing') {
         $tax_zone_id = hikashop_getZone('billing');
     } else {
         $tax_zone_id = $zone_id;
     }
     $discount_before_tax = (int) $config->get('discount_before_tax', 0);
     $cart = new stdClass();
     $cart->products = $this->get(@$this->cart->cart_id, $keepEmptyCart, isset($this->cart->cart_type) ? $this->cart->cart_type : '');
     $cart->cart_id = (int) @$this->cart->cart_id;
     $cart->cart_type = @$this->cart->cart_type;
     $cart->cart_params = @$this->cart->cart_params;
     $cart->coupon = null;
     $cart->shipping = null;
     $cart->total = null;
     $cart->additional = array();
     if (!empty($cart->products)) {
         $ids = array();
         $mainIds = array();
         foreach ($cart->products as $product) {
             $ids[] = $product->product_id;
             if ($product->product_parent_id == '0') {
                 $mainIds[] = (int) $product->product_id;
             } else {
                 $mainIds[] = (int) $product->product_parent_id;
             }
         }
         $query = 'SELECT a.*, b.* FROM ' . hikashop_table('product_category') . ' AS a LEFT JOIN ' . hikashop_table('category') . ' AS b ON a.category_id = b.category_id WHERE a.product_id IN(' . implode(',', $mainIds) . ') ORDER BY a.ordering ASC';
         $database->setQuery($query);
         $categories = $database->loadObjectList();
         $quantityDisplayType = hikashop_get('type.quantitydisplay');
         foreach ($cart->products as $k => $row) {
             if ($row->product_parent_id != 0 && $row->cart_product_parent_id != '0') {
                 $row->product_quantity_layout = $cart->products[$row->cart_product_parent_id]->product_quantity_layout;
                 $row->product_min_per_order = $cart->products[$row->cart_product_parent_id]->product_min_per_order;
                 $row->product_max_per_order = $cart->products[$row->cart_product_parent_id]->product_max_per_order;
             }
             if (empty($row->product_quantity_layout) || $row->product_quantity_layout == 'inherit') {
                 $categoryQuantityLayout = '';
                 if (!empty($categories)) {
                     foreach ($categories as $category) {
                         if ($category->product_id == $row->product_id && !empty($category->category_quantity_layout) && $quantityDisplayType->check($category->category_quantity_layout, $app->getTemplate())) {
                             $categoryQuantityLayout = $category->category_quantity_layout;
                             break;
                         }
                     }
                 }
             }
             if (!empty($row->product_quantity_layout) && $row->product_quantity_layout != 'inherit') {
                 $qLayout = $row->product_quantity_layout;
             } elseif (!empty($categoryQuantityLayout) && $categoryQuantityLayout != 'inherit') {
                 $qLayout = $categoryQuantityLayout;
             } else {
                 $qLayout = $config->get('product_quantity_display', 'show_default');
             }
             $cart->products[$k]->product_quantity_layout = $qLayout;
         }
         JArrayHelper::toInteger($ids);
         $query = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type IN( \'product\',\'file\') ORDER BY file_ref_id ASC, file_ordering ASC';
         $database->setQuery($query);
         $images = $database->loadObjectList();
         if (!empty($images)) {
             foreach ($cart->products as $k => $row) {
                 $productClass->addFiles($cart->products[$k], $images);
             }
         }
         foreach ($cart->products as $k => $row) {
             if ($row->product_type == 'variant') {
                 foreach ($cart->products as $k2 => $row2) {
                     if ($row->product_parent_id == $row2->product_id) {
                         $cart->products[$k2]->variants[] =& $cart->products[$k];
                         break;
                     }
                 }
             }
         }
         $query = 'SELECT a.*,b.* FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ') ORDER BY a.ordering,b.characteristic_value';
         $database->setQuery($query);
         $characteristics = $database->loadObjectList();
         if (!empty($characteristics)) {
             foreach ($cart->products as $key => $product) {
                 if ($product->product_type != 'variant') {
                     $element =& $cart->products[$key];
                     $product_id = $product->product_id;
                     $mainCharacteristics = array();
                     foreach ($characteristics as $characteristic) {
                         if ($product_id == $characteristic->variant_product_id) {
                             $mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic;
                         }
                         if (!empty($element->options)) {
                             foreach ($element->options as $k => $optionElement) {
                                 if ($optionElement->product_id == $characteristic->variant_product_id) {
                                     $mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic;
                                 }
                             }
                         }
                     }
                     JPluginHelper::importPlugin('hikashop');
                     $dispatcher = JDispatcher::getInstance();
                     $dispatcher->trigger('onAfterProductCharacteristicsLoad', array(&$element, &$mainCharacteristics, &$characteristics));
                     if (!empty($element->variants)) {
                         $this->addCharacteristics($element, $mainCharacteristics, $characteristics);
                     }
                     if (!empty($element->options)) {
                         foreach ($element->options as $k => $optionElement) {
                             if (!empty($optionElement->variants)) {
                                 $this->addCharacteristics($element->options[$k], $mainCharacteristics, $characteristics);
                             }
                         }
                     }
                 }
             }
         }
         $product_quantities = array();
         foreach ($cart->products as $row) {
             if (empty($product_quantities[$row->product_id])) {
                 $product_quantities[$row->product_id] = (int) @$row->cart_product_quantity;
             } else {
                 $product_quantities[$row->product_id] += (int) @$row->cart_product_quantity;
             }
             if (empty($product_quantities[$row->product_parent_id])) {
                 $product_quantities[$row->product_parent_id] = (int) @$row->cart_product_quantity;
             } else {
                 $product_quantities[$row->product_parent_id] += (int) @$row->cart_product_quantity;
             }
         }
         foreach ($cart->products as $k => $row) {
             $cart->products[$k]->cart_product_total_quantity = $product_quantities[$row->product_id];
             if ($row->product_parent_id) {
                 $cart->products[$k]->cart_product_total_variants_quantity = $product_quantities[$row->product_parent_id];
             } else {
                 $cart->products[$k]->cart_product_total_variants_quantity = $cart->products[$k]->cart_product_total_quantity;
             }
         }
         $currencyClass->getPrices($cart->products, $ids, $currency_id, $main_currency, $tax_zone_id, $discount_before_tax);
         if ($additionalInfos) {
             $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC';
             $database->setQuery($queryImage);
             $images = $database->loadObjectList();
             foreach ($cart->products as $k => $row) {
                 if (!empty($images)) {
                     foreach ($images as $image) {
                         if ($row->product_id == $image->file_ref_id) {
                             if (!isset($row->file_ref_id)) {
                                 foreach (get_object_vars($image) as $key => $name) {
                                     $cart->products[$k]->{$key} = $name;
                                 }
                             }
                             break;
                         }
                     }
                 }
                 if (!isset($cart->products[$k]->file_name)) {
                     $cart->products[$k]->file_name = $row->product_name;
                 }
             }
         }
         foreach ($cart->products as $k => $row) {
             if (!empty($row->variants)) {
                 foreach ($row->variants as $k2 => $variant) {
                     $productClass->checkVariant($cart->products[$k]->variants[$k2], $row);
                 }
             }
         }
         $notUsable = array();
         $cartData = $this->loadCart($cart->cart_id);
         if (!$skipChecks) {
             $cart->products = array_reverse($cart->products);
             foreach ($cart->products as $k => $product) {
                 if (empty($product->product_id)) {
                     continue;
                 }
                 if (!empty($product->cart_product_quantity)) {
                     $oldQty = $product->cart_product_quantity;
                     if (@$cartData->cart_type != 'wishlist') {
                         $this->_checkQuantity($product, $product->cart_product_quantity, $cart->products, $product->cart_product_id);
                     }
                     if ($oldQty != $product->cart_product_quantity) {
                         $notUsable[$product->cart_product_id] = 0;
                         break;
                     }
                     if (!$config->get('display_add_to_cart_for_free_products', 0) && empty($product->prices)) {
                         $notUsable[$product->cart_product_id] = 0;
                         $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice');
                         continue;
                     }
                     if (empty($product->product_published)) {
                         $notUsable[$product->cart_product_id] = 0;
                         $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice');
                         continue;
                     }
                     if ($product->product_quantity != -1 && $product->product_quantity < $product->cart_product_quantity) {
                         $notUsable[$product->cart_product_id] = 0;
                         $app->enqueueMessage(JText::sprintf('NOT_ENOUGH_STOCK_FOR_PRODUCT', $product->product_name), 'notice');
                         continue;
                     }
                     if ($product->product_sale_start > time()) {
                         $notUsable[$product->cart_product_id] = 0;
                         $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_YET_ON_SALE', $product->product_name), 'notice');
                         continue;
                     }
                     if (!empty($product->product_sale_end) && $product->product_sale_end < time()) {
                         $notUsable[$product->cart_product_id] = 0;
                         $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_SOLD_ANYMORE', $product->product_name), 'notice');
                         continue;
                     }
                 }
             }
             $cart->products = array_reverse($cart->products);
         }
         if (!empty($notUsable)) {
             $this->update($notUsable, 1, 0, 'item');
             return $this->loadFullCart($additionalInfos);
         }
         $cart->number_of_items = 0;
         $group = $config->get('group_options', 0);
         foreach ($cart->products as $k => $row) {
             unset($cart->products[$k]->cart_modified);
             unset($cart->products[$k]->cart_coupon);
             $currencyClass->calculateProductPriceForQuantity($cart->products[$k]);
             if (!$group || !$row->cart_product_option_parent_id) {
                 $cart->number_of_items += $row->cart_product_quantity;
             }
         }
         $currencyClass->calculateTotal($cart->products, $cart->total, $currency_id);
         $cart->full_total =& $cart->total;
         JPluginHelper::importPlugin('hikashop');
         JPluginHelper::importPlugin('hikashoppayment');
         JPluginHelper::importPlugin('hikashopshipping');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterCartProductsLoad', array(&$cart));
         if (!empty($cart->additional)) {
             $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id);
             $cart->full_total =& $cart->additional_total;
         }
         if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') {
             $discountClass = hikashop_get('class.discount');
             $discountData = $discountClass->load($this->cart->cart_coupon);
             if (@$discountData->discount_auto_load) {
                 $current_auto_coupon_key = $this->_generateHash($cart->products, $zone_id);
                 $previous_auto_coupon_key = $app->getUserState(HIKASHOP_COMPONENT . '.auto_coupon_key');
                 if ($current_auto_coupon_key != $previous_auto_coupon_key) {
                     $this->cart->cart_coupon = '';
                 }
             }
         }
         if (hikashop_level(1) && empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') {
             $filters = array('discount_type=\'coupon\'', 'discount_published=1', 'discount_auto_load=1');
             hikashop_addACLFilters($filters, 'discount_access');
             $query = 'SELECT * FROM ' . hikashop_table('discount') . ' WHERE ' . implode(' AND ', $filters) . ' ORDER BY discount_minimum_order DESC, discount_minimum_products DESC';
             $this->database->setQuery($query);
             $coupons = $this->database->loadObjectList();
             if (!empty($coupons)) {
                 $discountClass = hikashop_get('class.discount');
                 $zoneClass = hikashop_get('class.zone');
                 $zones = $zoneClass->getZoneParents($zone_id);
                 foreach ($coupons as $coupon) {
                     $result = $discountClass->check($coupon, $cart->total, $zones, $cart->products, false);
                     if ($result) {
                         $auto_coupon_key = $this->_generateHash($cart->products, $zone_id);
                         $app->setUserState(HIKASHOP_COMPONENT . '.auto_coupon_key', $auto_coupon_key);
                         $app->setUserState(HIKASHOP_COMPONENT . '.coupon_code', '');
                         $this->update($coupon->discount_code, 1, 0, 'coupon', true);
                         if (empty($this->cart)) {
                             $this->cart = new stdClass();
                         }
                         $this->cart->cart_coupon = $coupon->discount_code;
                         static $done = false;
                         if ($done == false) {
                             $done = true;
                             return $this->loadFullCart($additionalInfos);
                         }
                         break;
                     }
                 }
             }
         }
         if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') {
             $zoneClass = hikashop_get('class.zone');
             $zones = $zoneClass->getZoneParents($zone_id);
             $cart->coupon = $discountClass->loadAndCheck($this->cart->cart_coupon, $cart->full_total, $zones, $cart->products, true);
             if (empty($cart->coupon)) {
                 if (!empty($this->cart)) {
                     $this->cart->cart_coupon = '';
                 }
             } else {
                 $cart->full_total =& $cart->coupon->total;
             }
         }
         if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) {
             $cart->full_total->prices[0]->price_value_with_tax = 0;
             $cart->full_total->prices[0]->price_value = 0;
             if (isset($cart->full_total->prices[0]->taxes)) {
                 unset($cart->full_total->prices[0]->taxes);
             }
         }
         $shipping_id = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_id');
         if (!empty($shipping_id)) {
             $cart->shipping = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_data');
             if (!empty($cart->shipping)) {
                 if (!is_array($cart->shipping)) {
                     $cart->shipping = array($cart->shipping);
                 } else {
                     $shippings = array();
                     foreach ($cart->shipping as $method) {
                         $group_key = $method->shipping_id;
                         if (!empty($method->shipping_warehouse_id)) {
                             $group_key .= '_';
                             if (is_array($method->shipping_warehouse_id)) {
                                 foreach ($method->shipping_warehouse_id as $key => $val) {
                                     $group_key .= $key . $val;
                                 }
                             } else {
                                 $group_key .= $method->shipping_warehouse_id;
                             }
                         }
                         $shippings[$group_key] = $method;
                     }
                     $cart->shipping = array_values($shippings);
                 }
                 $currencyClass = hikashop_get('class.currency');
                 $shipping =& $cart->shipping;
                 $currencyClass->processShippings($shipping, $cart);
                 $cart->full_total =& $currencyClass->addShipping($cart->shipping, $cart->full_total);
             }
         }
         $before_additional = !empty($cart->additional);
         $dispatcher->trigger('onAfterCartShippingLoad', array(&$cart));
         if (!$before_additional && !empty($cart->additional)) {
             $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id);
             $cart->full_total =& $cart->additional_total;
         }
         if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) {
             $cart->full_total->prices[0]->price_value_with_tax = 0;
             $cart->full_total->prices[0]->price_value = 0;
             if (isset($cart->full_total->prices[0]->taxes)) {
                 unset($cart->full_total->prices[0]->taxes);
             }
         }
         $payment_id = $app->getUserState(HIKASHOP_COMPONENT . '.payment_id');
         if (!empty($payment_id)) {
             $cart->payment = $app->getUserState(HIKASHOP_COMPONENT . '.payment_data');
             if (!empty($cart->payment)) {
                 $currencyClass = hikashop_get('class.currency');
                 $payment =& $cart->payment;
                 $payments = array(&$payment);
                 $currencyClass->processPayments($payments, $cart);
                 $currencyClass->addPayment($cart->payment, $cart->full_total);
                 $cart->full_total =& $cart->payment->total;
             }
         }
         if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) {
             $cart->full_total->prices[0]->price_value_with_tax = 0;
             $cart->full_total->prices[0]->price_value = 0;
             if (isset($cart->full_total->prices[0]->taxes)) {
                 unset($cart->full_total->prices[0]->taxes);
             }
         }
     }
     if ($additionalInfos) {
         $app = JFactory::getApplication();
         $shipping_address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address', 0);
         if (!empty($shipping_address)) {
             $this->loadAddress($cart, $shipping_address);
         }
         $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address', 0);
         if ($billing_address == $shipping_address) {
             $cart->billing_address =& $cart->shipping_address;
         } else {
             if (!empty($billing_address)) {
                 $this->loadAddress($cart, $billing_address, 'parent', 'billing');
             }
         }
         $this->calculateWeightAndVolume($cart);
     }
     if (!empty($cart->products) && isset($dispatcher)) {
         $dispatcher->trigger('onAfterFullCartLoad', array(&$cart));
     }
     return $cart;
 }
Beispiel #8
0
 function onPaymentNotification(&$statuses)
 {
     header('HTTP/1.0 200 OK');
     flush();
     $filter = JFilterInput::getInstance();
     foreach ($_POST as $key => $val) {
         $key = $filter->clean($key);
         $val = JRequest::getString($key);
         $pfdata[$key] = $val;
     }
     $order_id = (int) @$pfdata['m_payment_id'];
     $dbOrder = $this->getOrder($order_id);
     $this->loadPaymentParams($dbOrder);
     $this->writeToLog('payfast : ' . print_r($this->payment_params, true));
     if (empty($this->payment_params)) {
         return false;
     }
     $this->loadOrderData($dbOrder);
     $pfParamString = array();
     foreach ($pfdata as $key => $val) {
         if (in_array($key, array('m_payment_id', 'pf_payment_id', 'payment_status', 'item_name', 'item_description', 'amount_gross', 'amount_fee', 'amount_net', 'custom_str1', 'custom_str2', 'custom_str3', 'custom_str4', 'custom_str5', 'custom_int1', 'custom_int2', 'custom_int3', 'custom_int4', 'custom_int5', 'name_first', 'name_last', 'email_address', 'merchant_id'))) {
             $pfParamString[] = $key . '=' . urlencode($val);
         }
     }
     $pfTempParamString = implode('&', $pfParamString);
     $pfParamString = implode('&', $pfParamString);
     $signature = md5($pfTempParamString);
     if ($signature != $pfdata['signature']) {
         if ($this->payment_params->debug) {
             echo 'Hash error ' . $pfdata['signature'] . ' - ' . $signature . "\n\n\n";
             echo "\n\n\n Invalid Signature \n\n\n";
             echo "Data receive from PayFast: \n\n\n";
             print_r($pfdata);
             $this->writeToLog(null);
         }
         die('Invalid Signature');
     }
     $validHosts = array('www.payfast.co.za', 'sandbox.payfast.co.za', 'w1w.payfast.co.za', 'w2w.payfast.co.za');
     $validIps = array();
     foreach ($validHosts as $pfHostname) {
         $ips = gethostbynamel($pfHostname);
         if ($ips !== false) {
             $validIps = array_merge($validIps, $ips);
         }
     }
     $validIps = array_unique($validIps);
     if (!in_array($_SERVER['REMOTE_ADDR'], $validIps)) {
         if ($this->payment_params->debug) {
             print_r($_SERVER['REMOTE_ADDR']) . "\n\n\n Source IP not Valid\n\n\n";
             $this->writeToLog(null);
         }
         die('Source IP not Valid');
     }
     $amount = round((double) hikashop_toFloat($dbOrder->order_full_price), 2);
     if (abs(floatval($amount) - floatval($pfdata['amount_gross'])) > 0.01) {
         if ($this->payment_params->debug) {
             $amountmismatch = floatval($amount) - floatval($pfdata['amount_gross']);
             echo "amount - amount form PayFast = " . $amountmismatch . "\n\n\n Amounts Mismatch\n\n\n";
             $this->writeToLog(null);
         }
         die('Amounts Mismatch');
     }
     $pfHost = $this->payment_params->testingMode ? 'sandbox.payfast.co.za' : 'www.payfast.co.za';
     if (in_array('curl', get_loaded_extensions())) {
         $url = 'https://' . $pfHost . '/eng/query/validate';
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $pfParamString);
         if (!empty($pfProxy)) {
             curl_setopt($ch, CURLOPT_PROXY, $proxy);
         }
         $response = curl_exec($ch);
         curl_close($ch);
     } else {
         $header = '';
         $res = '';
         $headerDone = false;
         $header = "POST /eng/query/validate HTTP/1.0\r\n" . "Host: " . $pfHost . "\r\n" . "User-Agent: " . PF_USER_AGENT . "\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($pfParamString) . "\r\n\r\n";
         $socket = fsockopen('ssl://' . $pfHost, 443, $errno, $errstr, 10);
         fputs($socket, $header . $pfParamString);
         $response = '';
         while (!feof($socket)) {
             $line = fgets($socket, 1024);
             if (strcmp($line, "\r\n") == 0) {
                 $headerDone = true;
             } else {
                 if ($headerDone) {
                     if (empty($line)) {
                         $line = '';
                     }
                     $response .= $line;
                 }
             }
         }
     }
     $lines = explode("\r\n", $response);
     $verifyResult = trim($lines[0]);
     if (strcasecmp($verifyResult, 'VALID') != 0) {
         if ($this->payment_params->debug) {
             print_r($verifyResult, true) . "\n\n\n Data not valid\n\n\n";
             $this->writeToLog(null);
         }
         die('Data not valid');
     }
     $pfPaymentId = $pfdata['pf_payment_id'];
     switch ($pfdata['payment_status']) {
         case 'COMPLETE':
             $order_status = $this->payment_params->verified_status;
             $this->modifyOrder($order_id, $order_status, true, true);
             break;
         case 'PENDING':
             $order_status = $this->payment_params->pending_status;
             $this->modifyOrder($order_id, $order_status, true, true);
             break;
         default:
         case 'FAILED':
             $this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true);
             if ($this->payment_params->debug) {
                 echo "Statut from PayFast: " . $pfdata['payment_status'];
             }
             break;
     }
 }
Beispiel #9
0
 function getPointsEarned($order)
 {
     if (empty($this->plugin_params)) {
         return 0;
     }
     if (!empty($this->plugin_params->notgivewhenuse) && (int) $this->plugin_params->notgivewhenuse == 1 && !empty($order->additional['userpoints'])) {
         return 0;
     }
     $points = 0;
     $db = JFactory::getDBO();
     $config =& hikashop_config();
     $this->main_currency = $config->get('main_currency', 1);
     $currencyClass = hikashop_get('class.currency');
     $this->currency = $currencyClass->get($this->main_currency);
     if (isset($order->order_currency_id)) {
         $order_currency_id = $order->order_currency_id;
     } else {
         $order_currency_id = hikashop_getCurrency();
     }
     if ($this->main_currency != $order_currency_id) {
         if (!empty($this->plugin_params->value)) {
             $this->plugin_params->value = $currencyClass->convertUniquePrice($this->plugin_params->value, $this->main_currency, $order_currency_id);
         } else {
             $this->plugin_params->value = 0;
         }
         if (!empty($this->plugin_params->minimumcost)) {
             $this->plugin_params->minimumcost = $currencyClass->convertUniquePrice($this->plugin_params->minimumcost, $this->main_currency, $order_currency_id);
         } else {
             $this->plugin_params->minimumcost = 0;
         }
         if (!empty($this->plugin_params->currency_rate)) {
             $this->plugin_params->currency_rate = $currencyClass->convertUniquePrice($this->plugin_params->currency_rate, $this->main_currency, $order_currency_id);
         } else {
             $this->plugin_params->currency_rate = 0;
         }
     }
     $products = array();
     if (!empty($order->cart->products)) {
         $products = $order->cart->products;
     } elseif (!empty($order->products)) {
         $products = $order->products;
     }
     if (empty($products)) {
         return 0;
     }
     $categories = array();
     if (!empty($this->plugin_params->categories)) {
         $categories = unserialize($this->plugin_params->categories);
     }
     $included_products = array();
     $product_ids = array();
     $category_ids = array();
     $product_categories = array();
     $sub_categories = array();
     if (!empty($categories) || !empty($this->plugin_params->product_categories)) {
         foreach ($products as $product) {
             $product_ids[$product->product_id] = $product->product_id;
         }
         $queryP = 'SELECT product_parent_id FROM ' . hikashop_table('product') . ' WHERE product_id IN (' . implode(',', $product_ids) . ')';
         $db->setQuery($queryP);
         $pids = $db->loadObjectList();
         if (!empty($pids)) {
             foreach ($pids as $pid) {
                 $product_ids[$pid->product_parent_id] = $pid->product_parent_id;
             }
         }
         $query = 'SELECT * FROM ' . hikashop_table('product_category') . ' prod LEFT JOIN ' . hikashop_table('category') . ' cat ON prod.category_id = cat.category_id ' . 'WHERE prod.product_id IN (' . implode(',', $product_ids) . ')';
         $db->setQuery($query);
         $category_ids = $db->loadObjectList();
         if (!empty($category_ids)) {
             $query = 'SELECT * FROM ' . hikashop_table('category') . ' WHERE category_type=\'product\' AND ';
             $conditions = array();
             foreach ($category_ids as $idcat) {
                 $conditions[] = '(category_left <= ' . $idcat->category_left . ' AND category_right >= ' . $idcat->category_right . ')';
                 $product_categories[(int) $idcat->product_id][] = $idcat->category_id;
             }
             $query .= implode(' OR ', $conditions);
         }
         $db->setQuery($query);
         $sub_categories = $db->loadObjectList('category_id');
     }
     if (!empty($categories)) {
         $cats = array();
         foreach ($categories as $k => $category) {
             $cats[$category->category_id] = array('points' => $category->category_points, 'products' => array());
             foreach ($product_categories as $id => $assoc_categories) {
                 if (in_array($category->category_id, $assoc_categories)) {
                     $cats[$category->category_id]['products'][$id] = $id;
                 }
             }
             if (empty($cats[$category->category_id]['products'])) {
                 unset($categories[$k]);
                 unset($cats[$category->category_id]);
             }
         }
         foreach ($product_categories as $product => $assoc_categories) {
             $max = array(0, 0);
             $rem = array();
             foreach ($assoc_categories as $cat) {
                 $cat = (int) $cat;
                 if (isset($cats[$cat]) && $cats[$cat]['points'] > $max[0]) {
                     $max[0] = $cats[$cat]['points'];
                     if ($max[1] > 0) {
                         $rem[] = $max[1];
                     }
                     $max[1] = $cat;
                 } else {
                     $rem[] = $cat;
                 }
             }
             foreach ($rem as $i) {
                 unset($cats[$i]['products'][$product]);
             }
         }
         foreach ($cats as $k => $category) {
             if (!empty($category['products'])) {
                 $points += $category['points'];
             }
         }
     }
     if (hikashop_level(2)) {
         $groups = array();
         if (!empty($this->plugin_params->groups)) {
             $groups = unserialize($this->plugin_params->groups);
         }
         if (!HIKASHOP_J16) {
             $my = JFactory::getUser();
             $gid = $my->gid;
             if (empty($gid)) {
                 $userGroups = array(29);
             } else {
                 $userGroups = array($gid);
             }
         } else {
             if (!empty($order->customer->user_cms_id)) {
                 $user_id = $order->customer->user_cms_id;
             } else {
                 $my = JFactory::getUser();
                 $user_id = $my->id;
             }
             jimport('joomla.access.access');
             $userGroups = JAccess::getGroupsByUser($user_id, true);
             //$my->authorisedLevels();
         }
         foreach ($userGroups as $groupid) {
             if (!empty($groups[$groupid])) {
                 $points += $groups[$groupid];
             }
             if (!empty($groups[$groupid]) && $this->plugin_params->limitegroup == 1) {
                 break;
             }
         }
     }
     $cart = null;
     if (isset($order->cart)) {
         $cart =& $order->cart;
     } else {
         $cart =& $order;
     }
     $calculatedPrice = 0.0;
     if (empty($this->plugin_params->product_categories)) {
         if (!empty($cart->full_total->prices[0]->price_value_with_tax)) {
             if ($this->plugin_params->shippingpoints == 1) {
                 $calculatedPrice = $cart->full_total->prices[0]->price_value_with_tax - @$cart->coupon->discount_value;
             } else {
                 $calculatedPrice = $cart->total->prices[0]->price_value_with_tax - @$cart->coupon->discount_value;
             }
         } else {
             if ($this->plugin_params->shippingpoints == 1) {
                 $calculatedPrice = @$order->order_full_price;
             } else {
                 $calculatedPrice = @$order->order_full_price - @$order->order_shipping_price;
             }
         }
     } else {
         foreach ($category_ids as &$category) {
             $category->parents = array();
             foreach ($sub_categories as $sub_category) {
                 if ($sub_category->category_left <= $category->category_left && $sub_category->category_right >= $category->category_right) {
                     $category->parents[$sub_category->category_id] = $sub_category->category_id;
                 }
             }
         }
         unset($category);
         foreach ($products as $k => $product) {
             foreach ($category_ids as $category) {
                 if ((int) $category->product_id != (int) $product->product_id) {
                     continue;
                 }
                 $product_price = 0.0;
                 if (empty($product->prices) && !empty($product->order_product_price)) {
                     $product_price = (double) hikashop_toFloat(@$product->order_product_price) + (double) hikashop_toFloat(@$product->order_product_tax);
                 } else {
                     if (!empty($product->prices)) {
                         if (isset($product->prices[0]->price_value_with_tax)) {
                             $product_price = $product->prices[0]->price_value_with_tax;
                         } else {
                             $product_price = $product->prices[0]->price_value;
                         }
                     }
                 }
                 if (isset($product->order_product_quantity)) {
                     $product_price *= (int) $product->order_product_quantity;
                 } else {
                     $product_price *= (int) $product->cart_product_quantity;
                 }
                 $found = false;
                 if (in_array($category->category_id, $this->plugin_params->product_categories)) {
                     $calculatedPrice += $product_price;
                     $found = true;
                 } else {
                     $interset = array_intersect($category->parents, $this->plugin_params->product_categories);
                     if (!empty($interset)) {
                         $calculatedPrice += $product_price;
                         $found = true;
                     }
                 }
                 if ($found) {
                     $included_products[$k] = $k;
                     break;
                 }
             }
         }
         if ($this->plugin_params->shippingpoints == 1) {
             $calculatedPrice += (double) @$order->order_shipping_price;
         }
     }
     if (!empty($this->plugin_params->notgivewhenuse) && (int) $this->plugin_params->notgivewhenuse == 2 && !empty($order->additional['userpoints'])) {
         $calculatedPrice += (double) $order->additional['userpoints']->price_value;
     }
     if (!empty($this->plugin_params->notgivewhenuse) && (int) $this->plugin_params->notgivewhenuse == 2 && !empty($order->cart->additional['userpoints'])) {
         $calculatedPrice += (double) $order->cart->additional['userpoints']->price_value;
     }
     unset($cart);
     if ($this->plugin_params->currency_rate != 0) {
         $points += $calculatedPrice / $this->plugin_params->currency_rate;
     }
     if ($this->plugin_params->limittype == 1) {
         foreach ($products as $k => $product) {
             if (empty($this->plugin_params->product_categories) || isset($included_products[$k])) {
                 $points += $this->plugin_params->productpoints;
             }
         }
     } elseif ($this->plugin_params->limittype == 0) {
         foreach ($products as $k => $product) {
             if (empty($this->plugin_params->product_categories) || isset($included_products[$k])) {
                 if (isset($product->order_product_quantity)) {
                     $points += $this->plugin_params->productpoints * $product->order_product_quantity;
                 } else {
                     $points += $this->plugin_params->productpoints * $product->cart_product_quantity;
                 }
             }
         }
     }
     if (!empty($this->plugin_params->rounddown)) {
         return floor($points);
     }
     return round($points, 0);
 }
Beispiel #10
0
 function store($new = false)
 {
     $this->plugin = JRequest::getCmd('name', 'manual');
     $this->plugin_type = JRequest::getCmd('plugin_type', 'shipping');
     if (!in_array($this->plugin_type, array('shipping', 'payment', 'plugin'))) {
         return false;
     }
     if ($this->plugin_type == 'plugin') {
         $data = hikashop_import('hikashop', $this->plugin);
     } else {
         $data = hikashop_import('hikashop' . $this->plugin_type, $this->plugin);
     }
     $element = new stdClass();
     $id = hikashop_getCID($this->plugin_type . '_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     $params_name = $this->plugin_type . '_params';
     if (!empty($formData[$this->plugin_type])) {
         $plugin_id = $this->plugin_type . '_id';
         $element->{$plugin_id} = $id;
         foreach ($formData[$this->plugin_type] as $column => $value) {
             hikashop_secureField($column);
             if (is_array($value)) {
                 if ($column == $params_name) {
                     $element->{$params_name} = new stdClass();
                     foreach ($formData[$this->plugin_type][$column] as $key => $val) {
                         hikashop_secureField($key);
                         if (in_array($key, array('shipping_percentage', 'shipping_min_price', 'shipping_max_price', 'shipping_min_weight', 'shipping_max_weight', 'shipping_min_volume', 'shipping_max_volume'))) {
                             $val = hikashop_toFloat($val);
                         }
                         if (is_array($val) || $key == 'information') {
                             $element->{$params_name}->{$key} = $val;
                         } elseif ($key == 'shipping_override_address_text' && $formData[$this->plugin_type][$column]['shipping_override_address'] == '4') {
                             $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
                             $element->{$params_name}->{$key} = $safeHtmlFilter->clean($val, 'string');
                         } else {
                             $element->{$params_name}->{$key} = strip_tags($val);
                         }
                     }
                 } elseif ($column == 'payment_shipping_methods' || $column == 'payment_currency' || $column == 'shipping_currency') {
                     $element->{$column} = array();
                     foreach ($formData[$this->plugin_type][$column] as $key => $val) {
                         $element->{$column}[(int) $key] = strip_tags($val);
                     }
                 }
             } else {
                 $element->{$column} = strip_tags($value);
             }
         }
         if ($this->plugin_type == 'payment') {
             if (!isset($element->payment_shipping_methods)) {
                 $element->payment_shipping_methods = array();
             }
             if (!isset($element->payment_currency)) {
                 $element->payment_currency = array();
             }
         } elseif ($this->plugin_type == 'shipping') {
             if (!isset($element->shipping_currency)) {
                 $element->shipping_currency = array();
             }
         }
         $plugin_description = $this->plugin_type . '_description';
         $plugin_description_data = JRequest::getVar($plugin_description, '', '', 'string', JREQUEST_ALLOWRAW);
         $element->{$plugin_description} = $plugin_description_data;
         $translationHelper = hikashop_get('helper.translation');
         $translationHelper->getTranslations($element);
     }
     $function = 'on' . ucfirst($this->plugin_type) . 'ConfigurationSave';
     if (method_exists($data, $function)) {
         $data->{$function}($element);
     }
     if (!empty($element)) {
         $pluginClass = hikashop_get('class.' . $this->plugin_type);
         $status = $pluginClass->save($element);
         if (!$status) {
             JRequest::setVar('fail', $element);
         } else {
             $translationHelper->handleTranslations($this->plugin_type, $status, $element);
             $app = JFactory::getApplication();
             if (!HIKASHOP_J30) {
                 $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'), 'success');
             } else {
                 $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'));
             }
             if (empty($id)) {
                 JRequest::setVar($this->plugin_type . '_id', $status);
             }
         }
     }
 }
Beispiel #11
0
 function generateXML()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $pluginsClass = hikashop_get('class.plugins');
     $plugin = $pluginsClass->getByName('hikashop', 'google_products');
     if (empty($plugin->params['condition'])) {
         $plugin->params['condition'] = "new";
     }
     if (@$plugin->params['increase_perf']) {
         $memory = '128M';
         $max_execution = '120';
         if ($plugin->params['increase_perf'] == 2) {
             $memory = '512M';
             $max_execution = '600';
         } elseif ($plugin->params['increase_perf'] == 3) {
             $memory = '1024M';
             $max_execution = '6000';
         } elseif ($plugin->params['increase_perf'] == 10) {
             $memory = '4096M';
             $max_execution = '0';
         }
         ini_set('memory_limit', $memory);
         ini_set('max_execution_timeout', $max_execution);
     }
     $query = 'SELECT * FROM ' . hikashop_table('product') . ' WHERE product_access=\'all\' AND product_published=1 AND product_type=\'main\'';
     if (!empty($plugin->params['in_stock_only'])) {
         $query .= ' AND product_quantity!=0';
     }
     $db->setQuery($query);
     $products = $db->loadObjectList();
     if (empty($products)) {
         return true;
     }
     $ids = array();
     foreach ($products as $key => $row) {
         $ids[] = $row->product_id;
         $products[$key]->alias = JFilterOutput::stringURLSafe($row->product_name);
     }
     $queryCategoryId = 'SELECT * FROM ' . hikashop_table('product_category') . ' WHERE product_id IN (' . implode(',', $ids) . ')';
     $db->setQuery($queryCategoryId);
     $categoriesId = $db->loadObjectList();
     foreach ($products as $k => $row) {
         foreach ($categoriesId as $catId) {
             if ($row->product_id == $catId->product_id) {
                 $products[$k]->categories_id[] = $catId->category_id;
             }
         }
     }
     $usedCat = array();
     $catList = "";
     foreach ($products as $product) {
         if (!empty($product->categories_id)) {
             foreach ($product->categories_id as $catId) {
                 if (!isset($usedCat[$catId])) {
                     $usedCat[$catId] = $catId;
                     $catList .= $catId . ',';
                 }
             }
         }
     }
     $catList = substr($catList, 0, -1);
     $parentCatId = 'product';
     $categoryClass = hikashop_get('class.category');
     $categoryClass->getMainElement($parentCatId);
     $query = 'SELECT DISTINCT b.* FROM ' . hikashop_table('category') . ' AS a LEFT JOIN ' . hikashop_table('category') . ' AS b ON a.category_left >= b.category_left WHERE ' . 'b.category_right >= a.category_right AND a.category_id IN (' . $catList . ') AND a.category_published=1 AND a.category_type=\'product\' AND b.category_id!=' . $parentCatId . ' ' . 'ORDER BY b.category_left';
     $db->setQuery($query);
     $categories = $db->loadObjectList();
     $category_path = array();
     $discard_products_without_valid_categories = array();
     foreach ($products as $k => $product) {
         if (empty($product->categories_id)) {
             $discard_products_without_valid_categories[] = $k;
         } else {
             $path = array();
             $at_least_a_category_valid = false;
             foreach ($categories as $category) {
                 foreach ($product->categories_id as $catID) {
                     if ($catID == $category->category_id) {
                         $at_least_a_category_valid = true;
                         if (!isset($category_path[$catID])) {
                             $category_path[$catID] = $this->_getCategoryParent($category, $categories, $path, $parentCatId);
                         }
                     }
                 }
             }
             if (!$at_least_a_category_valid) {
                 $discard_products_without_valid_categories[] = $k;
             }
         }
     }
     if (!empty($discard_products_without_valid_categories)) {
         foreach ($discard_products_without_valid_categories as $k) {
             unset($products[$k]);
         }
     }
     foreach ($category_path as $id => $mainCat) {
         $path = '';
         for ($i = count($mainCat); $i > 0; $i--) {
             $path .= $mainCat[$i - 1]->category_name . ' > ';
         }
         $category_path[$id]['path'] = substr($path, 0, -3);
     }
     $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ordering ASC, file_id ASC';
     $db->setQuery($queryImage);
     $images = $db->loadObjectList();
     $products[$k]->images = array();
     foreach ($products as $k => $row) {
         $i = 0;
         foreach ($images as $image) {
             if ($row->product_id == $image->file_ref_id) {
                 $products[$k]->images[$i] = new stdClass();
                 foreach (get_object_vars($image) as $key => $name) {
                     $products[$k]->images[$i]->{$key} = $name;
                 }
             }
             $i++;
         }
     }
     $db->setQuery('SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id IN (' . implode(',', $ids) . ')');
     $variants = $db->loadObjectList();
     if (!empty($variants)) {
         foreach ($products as $k => $product) {
             foreach ($variants as $variant) {
                 if ($product->product_id == $variant->variant_product_id) {
                     $products[$k]->has_options = true;
                     break;
                 }
             }
         }
     }
     $zone_id = hikashop_getZone();
     $currencyClass = hikashop_get('class.currency');
     $config =& hikashop_config();
     $main_currency = (int) $config->get('main_currency', 1);
     if (empty($plugin->params['price_displayed'])) {
         $plugin->params['price_displayed'] = 'cheapest';
     }
     if ($plugin->params['price_displayed'] == 'cheapest') {
         $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'cheapest');
     }
     if ($plugin->params['price_displayed'] == 'unit') {
         $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'unit');
     }
     if ($plugin->params['price_displayed'] == 'average') {
         $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'range');
         $tmpPrice = 0;
         $tmpTaxPrice = 0;
         foreach ($products as $product) {
             if (isset($product->prices[0]->price_value)) {
                 if (count($product->prices) > 1) {
                     for ($i = 0; $i < count($product->prices); $i++) {
                         if ($product->prices[$i]->price_value > $tmpPrice) {
                             $tmpPrice += $product->prices[$i]->price_value;
                             $tmpTaxPrice += @$product->prices[$i]->price_value_with_tax;
                         }
                     }
                     $product->prices[0]->price_value = $tmpPrice / count($product->prices);
                     $product->prices[0]->price_value_with_tax = $tmpTaxPrice / count($product->prices);
                     for ($i = 1; $i < count($product->prices); $i++) {
                         unset($product->prices[$i]);
                     }
                 }
             }
         }
     }
     if ($plugin->params['price_displayed'] == 'expensive') {
         $currencyClass->getListingPrices($products, $zone_id, $main_currency, 'range');
         $tmpPrice = 0;
         foreach ($products as $product) {
             if (isset($product->prices[0]->price_value)) {
                 if (count($product->prices) > 1) {
                     for ($i = 0; $i < count($product->prices); $i++) {
                         if ($product->prices[$i]->price_value > $tmpPrice) {
                             $tmpPrice = $product->prices[$i]->price_value;
                             $key = $i;
                         }
                     }
                     $product->prices[0] = $product->prices[$key];
                     for ($i = 1; $i < count($product->prices); $i++) {
                         unset($product->prices[$i]);
                     }
                 }
             }
         }
     }
     if (!empty($plugin->params['use_brand'])) {
         $parentCatId = 'manufacturer';
         $categoryClass->getMainElement($parentCatId);
         $query = 'SELECT DISTINCT * FROM ' . hikashop_table('category') . ' AS a WHERE a.category_published=1 AND a.category_type=\'manufacturer\' AND a.category_parent_id=' . $parentCatId;
         $db->setQuery($query);
         $brands = $db->loadObjectList('category_id');
     }
     $config =& hikashop_config();
     $uploadFolder = ltrim(JPath::clean(html_entity_decode($config->get('uploadfolder'))), DS);
     $uploadFolder = rtrim($uploadFolder, DS) . DS;
     $this->uploadFolder_url = str_replace(DS, '/', $uploadFolder);
     $this->uploadFolder = JPATH_ROOT . DS . $uploadFolder;
     $app = JFactory::getApplication();
     $this->thumbnail = $config->get('thumbnail', 1);
     $this->thumbnail_x = $config->get('thumbnail_x', 100);
     $this->thumbnail_y = $config->get('thumbnail_y', 100);
     $this->main_thumbnail_x = $this->thumbnail_x;
     $this->main_thumbnail_y = $this->thumbnail_y;
     $this->main_uploadFolder_url = $this->uploadFolder_url;
     $this->main_uploadFolder = $this->uploadFolder;
     $conf = JFactory::getConfig();
     if (!HIKASHOP_J30) {
         $siteName = $conf->getValue('config.sitename');
         $siteDesc = $conf->getValue('config.MetaDesc');
     } else {
         $siteName = $conf->get('sitename');
         $siteDesc = $conf->get('MetaDesc');
     }
     $siteAddress = JURI::base();
     $siteAddress = str_replace('administrator/', '', $siteAddress);
     $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" . '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">' . "\n" . "\t" . '<channel>' . "\n" . "\t\t" . '<title><![CDATA[ ' . $siteName . ' ]]></title>' . "\n" . "\t\t" . '<description><![CDATA[ ' . $siteDesc . ' ]]></description>' . "\n" . "\t\t" . '<link><![CDATA[ ' . $siteAddress . ' ]]></link>' . "\n" . "\n";
     $productClass = hikashop_get('class.product');
     foreach ($products as $product) {
         if (isset($product->prices[0]->price_value)) {
             $price_name = 'price_value';
             if (!empty($plugin->params['taxed_price'])) {
                 $price_name = 'price_value_with_tax';
             }
             if (empty($product->product_min_per_order)) {
                 $price = round($product->prices[0]->{$price_name}, 2);
             } else {
                 $price = round($product->prices[0]->{$price_name}, 2) * $product->product_min_per_order;
             }
             $currencies = array();
             $currencyClass = hikashop_get('class.currency');
             $ids[$product->prices[0]->price_currency_id] = $product->prices[0]->price_currency_id;
             $currencies = $currencyClass->getCurrencies($ids[$product->prices[0]->price_currency_id], $currencies);
             $currency = reset($currencies);
             $xml .= '<item>' . "\n";
             $productClass->addAlias($product);
             if ($product->product_weight_unit == 'mg') {
                 $product->product_weight = $product->product_weight * 1000;
                 $product->product_weight_unit = 'g';
             }
             $xml .= "\t" . '<g:id>' . $product->product_id . '</g:id>' . "\n";
             $xml .= "\t" . '<title><![CDATA[ ' . $product->product_name . ' ]]></title>' . "\n";
             $itemID = '';
             if (!empty($plugin->params['item_id'])) {
                 $itemID = '&Itemid=' . $plugin->params['item_id'];
             }
             if (!empty($product->product_canonical)) {
                 $xml .= "\t" . '<g:link><![CDATA[ ' . str_replace('/administrator/', '/', hikashop_cleanURL($product->product_canonical)) . ' ]]></g:link>' . "\n";
             } else {
                 $xml .= "\t" . '<g:link><![CDATA[ ' . $siteAddress . 'index.php?option=com_hikashop&ctrl=product&task=show&cid=' . $product->product_id . '&name=' . $product->alias . $itemID . ' ]]></g:link>' . "\n";
             }
             $xml .= "\t" . '<g:price>' . $price . ' ' . $currency->currency_code . '</g:price>' . "\n";
             if (!empty($product->product_description)) {
                 if (@$plugin->params['preview']) {
                     $xml .= "\t" . '<g:description><![CDATA[ ' . strip_tags(preg_replace('#<hr *id="system-readmore" */>.*#is', '', $product->product_description)) . ' ]]></g:description>' . "\n";
                 } else {
                     $xml .= "\t" . '<g:description><![CDATA[ ' . strip_tags($product->product_description) . ' ]]></g:description>' . "\n";
                 }
             } elseif (!empty($plugin->params['message'])) {
                 $xml .= "\t" . '<g:description><![CDATA[ ' . $plugin->params['message'] . ' ]]></g:description>' . "\n";
             } else {
                 $xml .= "\t" . '<g:description>No description</g:description>' . "\n";
             }
             $xml .= $this->_additionalParameter($product, $plugin, 'condition', 'condition');
             $xml .= $this->_additionalParameter($product, $plugin, 'gender', 'gender');
             $xml .= $this->_additionalParameter($product, $plugin, 'gtin', 'gtin');
             $xml .= $this->_additionalParameter($product, $plugin, 'age_group', 'age_group');
             $xml .= $this->_additionalParameter($product, $plugin, 'size', 'size');
             $xml .= $this->_additionalParameter($product, $plugin, 'color', 'color');
             $xml .= $this->_additionalParameter($product, $plugin, 'identifier_exists', 'identifier_exists');
             $xml .= $this->_addShipping($product, $plugin);
             if (!empty($plugin->params['use_brand']) && !empty($brands[$product->product_manufacturer_id]->category_name)) {
                 $xml .= "\t" . '<g:brand><![CDATA[ ' . $brands[$product->product_manufacturer_id]->category_name . ' ]]></g:brand>' . "\n";
             } else {
                 $xml .= $this->_additionalParameter($product, $plugin, 'brand', 'brand');
             }
             $xml .= $this->_additionalParameter($product, $plugin, 'category', 'google_product_category');
             if ($plugin->params['add_code']) {
                 $xml .= "\t" . '<g:mpn><![CDATA[ ' . str_replace(array(' ', '-'), array('', ''), $product->product_code) . ' ]]></g:mpn>' . "\n";
             }
             if (isset($product->images) && count($product->images)) {
                 $i = 0;
                 $name = "image_link";
                 foreach ($product->images as $image) {
                     if ($i < 10) {
                         $xml .= "\t" . '<g:' . $name . '>' . htmlspecialchars($siteAddress . $this->main_uploadFolder_url . $image->file_path) . '</g:' . $name . '>' . "\n";
                         $name = "additional_image_link";
                         $i++;
                     }
                 }
             }
             $type = '';
             foreach ($product->categories_id as $catID) {
                 foreach ($category_path as $id => $catPath) {
                     if ($id == $catID) {
                         if (strlen($type . '"' . $catPath['path'] . '",') > 750) {
                             continue;
                         }
                         $type .= '"' . $catPath['path'] . '",';
                     }
                 }
             }
             if (!empty($type)) {
                 $type = substr($type, 0, -1);
                 $xml .= "\t" . '<g:product_type><![CDATA[ ' . $type . ' ]]></g:product_type>' . "\n";
             }
             if ($product->product_quantity != -1) {
                 $xml .= "\t" . '<g:quantity>' . $product->product_quantity . '</g:quantity>' . "\n";
             }
             if ($product->product_quantity == 0) {
                 $xml .= "\t" . '<g:availability>out of stock</g:availability>' . "\n";
             } else {
                 $xml .= "\t" . '<g:availability>in stock</g:availability>' . "\n";
             }
             $xml .= "\t" . '<g:shipping_weight>' . (double) hikashop_toFloat($product->product_weight) . ' ' . $product->product_weight_unit . '</g:shipping_weight>' . "\n";
             $xml .= '</item>' . "\n";
         }
     }
     $xml .= '</channel>' . "\n" . '</rss>' . "\n";
     return $xml;
 }
Beispiel #12
0
 function toFloatArray(&$array, $default = null)
 {
     if (is_array($array)) {
         foreach ($array as $i => $v) {
             $array[$i] = hikashop_toFloat($v);
         }
     } else {
         if ($default === null) {
             $array = array();
         } elseif (is_array($default)) {
             $this->toFloatArray($default, null);
             $array = $default;
         } else {
             $array = array((double) $default);
         }
     }
 }
Beispiel #13
0
 function pointsToCurrency($userPoints)
 {
     if (empty($this->plugin_params)) {
         return false;
     }
     $coupon = $userPoints * hikashop_toFloat($this->plugin_params->value);
     return $coupon;
 }
if (bccomp($data->cart->order_payment_price, 0, 5)) {
    if ($config->get('price_with_tax')) {
        $t = $currencyHelper->format($data->cart->order_payment_price, $data->cart->order_currency_id);
    } else {
        $t = $currencyHelper->format($data->cart->order_payment_price - @$data->cart->order_payment_tax, $data->cart->order_currency_id);
    }
    $cartFooters[] = array('NAME' => JText::_('HIKASHOP_PAYMENT'), 'VALUE' => $t);
}
if (!empty($data->cart->additional)) {
    $exclude_additionnal = explode(',', $config->get('order_additional_hide', ''));
    foreach ($data->cart->additional as $additional) {
        if (in_array($additional->order_product_name, $exclude_additionnal)) {
            continue;
        }
        if (!empty($additional->order_product_price)) {
            $additional->order_product_price = (double) hikashop_toFloat($additional->order_product_price);
        }
        if (!empty($additional->order_product_price) || empty($additional->order_product_options)) {
            if ($config->get('price_with_tax')) {
                $t = $currencyHelper->format($additional->order_product_price + @$additional->order_product_tax, $data->cart->order_currency_id);
            } else {
                $t = $currencyHelper->format($additional->order_product_price, $data->cart->order_currency_id);
            }
        } else {
            $t = $additional->order_product_options;
        }
        $cartFooters[] = array('NAME' => JText::_($additional->order_product_name), 'VALUE' => $t);
    }
}
if ($data->cart->full_total->prices[0]->price_value != $data->cart->full_total->prices[0]->price_value_with_tax) {
    if ($config->get('detailed_tax_display') && !empty($data->cart->order_tax_info)) {
Beispiel #15
0
 function _checkData(&$product, $main = false)
 {
     $this->currentProductVariants = array();
     if (empty($product->product_created)) {
         $product->product_created = time();
     } elseif (!is_numeric($product->product_created)) {
         $product->product_created = strtotime($product->product_created);
     }
     if (empty($product->product_modified)) {
         $product->product_modified = time();
     } elseif (!is_numeric($product->product_modified)) {
         $product->product_modified = strtotime($product->product_modified);
     }
     if (empty($product->product_sale_start)) {
         if (!empty($this->template->product_sale_start)) {
             $product->product_sale_start = $this->template->product_sale_start;
         }
     } elseif (!is_numeric($product->product_sale_start)) {
         $product->product_sale_start = strtotime($product->product_sale_start);
     }
     if (empty($product->product_sale_end)) {
         if (!empty($this->template->product_sale_end)) {
             $product->product_sale_end = $this->template->product_sale_end;
         }
     } elseif (!is_numeric($product->product_sale_end)) {
         $product->product_sale_end = strtotime($product->product_sale_end);
     }
     if (!empty($product->product_weight)) {
         $product->product_weight = hikashop_toFloat($product->product_weight);
     }
     if (!empty($product->product_width)) {
         $product->product_width = hikashop_toFloat($product->product_width);
     }
     if (!empty($product->product_height)) {
         $product->product_height = hikashop_toFloat($product->product_height);
     }
     if (!empty($product->product_length)) {
         $product->product_length = hikashop_toFloat($product->product_length);
     }
     if (empty($product->product_type)) {
         if (empty($product->product_parent_id)) {
             $product->product_type = 'main';
         } else {
             if (!empty($product->product_parent_id) && !empty($product->product_code) && $product->product_parent_id == $product->product_code) {
                 $app = JFactory::getApplication();
                 $app->enqueueMessage('The product ' . $product->product_code . ' has the same value in the product_parent_id and product_code fields which is not possible ( a main product cannot be a variant at the same time ). This product has been considered as a main product by HikaShop and has been imported as such.');
                 $product->product_type = 'main';
                 $product->product_parent_id = 0;
             } else {
                 $product->product_type = 'variant';
             }
         }
     } else {
         if (!in_array($product->product_type, array('main', 'variant'))) {
             $product->product_type = 'main';
         }
     }
     if ($product->product_type == 'main') {
         if (!empty($product->product_parent_id)) {
             $app = JFactory::getApplication();
             $app->enqueueMessage('The product ' . @$product->product_code . ' should have an empty value instead of the value ' . $product->product_parent_id . ' in the field product_parent_id as it is a main product (not a variant) and thus doesn\'t have any parent.', 'error');
         }
     } else {
         $product->product_tax_id = 0;
     }
     if (!isset($product->product_tax_id) || strlen($product->product_tax_id) < 1) {
         $product->product_tax_id = $this->tax_category;
     } else {
         if (!is_numeric($product->product_tax_id)) {
             $id = $this->_getCategory($product->product_tax_id, 0, !$this->createCategories, 'tax');
             if (empty($id) && $this->createCategories) {
                 $id = $this->_createCategory($product->product_tax_id, 0, 'tax');
             }
             $product->product_tax_id = $id;
         }
     }
     if (!empty($product->product_manufacturer_id) && !is_numeric($product->product_manufacturer_id)) {
         $id = $this->_getCategory($product->product_manufacturer_id, 0, !$this->createCategories, 'manufacturer');
         if (empty($id) && $this->createCategories) {
             $id = $this->_createCategory($product->product_manufacturer_id, 0, 'manufacturer');
         }
         $product->product_manufacturer_id = $id;
     }
     if (!isset($product->product_quantity) || strlen($product->product_quantity) < 1) {
         if (!empty($this->template->product_quantity)) {
             $product->product_quantity = $this->template->product_quantity;
         }
     }
     if (isset($product->product_quantity) && !is_numeric($product->product_quantity)) {
         $product->product_quantity = -1;
     }
     foreach ($this->fields as $field) {
         if (empty($product->{$field}) && !empty($this->template->{$field})) {
             $product->{$field} = $this->template->{$field};
         }
     }
     if (empty($product->product_dimension_unit)) {
         $product->product_dimension_unit = $this->volumeHelper->getSymbol();
     } else {
         $product->product_dimension_unit = strtolower($product->product_dimension_unit);
     }
     if (empty($product->product_weight_unit)) {
         $product->product_weight_unit = $this->weightHelper->getSymbol();
     } else {
         $product->product_weight_unit = strtolower($product->product_weight_unit);
     }
     if (!empty($product->product_published)) {
         $product->product_published = 1;
     }
     if (!isset($product->product_published)) {
         if (!empty($this->template)) {
             $product->product_published = $this->template->product_published;
         }
     }
     if (!empty($product->price_value_with_tax)) {
         $currencyHelper = hikashop_get('class.currency');
         if (empty($product->product_tax_id)) {
             $product->product_tax_id = $currencyHelper->getTaxCategory();
         }
         if ($product->product_tax_id) {
             if (strpos($product->price_value_with_tax, '|') === false) {
                 $product->price_value = $currencyHelper->getUntaxedPrice(hikashop_toFloat($product->price_value_with_tax), hikashop_getZone(), $product->product_tax_id);
             } else {
                 $price_value = explode('|', $product->price_value_with_tax);
                 foreach ($price_value as $k => $price_value_one) {
                     $price_value[$k] = $currencyHelper->getUntaxedPrice($price_value_one, hikashop_getZone(), $product->product_tax_id);
                 }
                 $product->price_value = implode('|', $price_value);
             }
         }
     }
     if (!empty($product->price_value)) {
         $product->prices = array();
         if (strpos($product->price_value, '|') === false) {
             $price = new stdClass();
             $price->price_value = hikashop_toFloat($product->price_value);
             if (!empty($this->price_fee)) {
                 $price->price_value += $price->price_value * hikashop_toFloat($this->price_fee) / 100;
             }
             $price->price_min_quantity = (int) @$product->price_min_quantity;
             if ($price->price_min_quantity == 1) {
                 $price->price_min_quantity = 0;
             }
             if (empty($product->price_access)) {
                 $price->price_access = 'all';
             } else {
                 $price->price_access = $product->price_access;
             }
             if (!empty($product->price_currency_id)) {
                 if (!is_numeric($product->price_currency_id)) {
                     $product->price_currency_id = $this->_getCurrency($product->price_currency_id);
                 }
                 $price->price_currency_id = $product->price_currency_id;
             } else {
                 $config =& hikashop_config();
                 $price->price_currency_id = $config->get('main_currency', 1);
             }
             $product->prices[] = $price;
         } else {
             $price_value = explode('|', $product->price_value);
             if (!empty($product->price_min_quantity)) {
                 $price_min_quantity = explode('|', $product->price_min_quantity);
             }
             if (!empty($product->price_access)) {
                 $price_access = explode('|', $product->price_access);
             }
             if (!empty($product->price_currency_id)) {
                 $price_currency_id = explode('|', $product->price_currency_id);
             }
             foreach ($price_value as $k => $price_value_one) {
                 $price = new stdClass();
                 $price->price_value = hikashop_toFloat($price_value_one);
                 if (!empty($this->price_fee)) {
                     $price->price_value += $price->price_value * hikashop_toFloat($this->price_fee) / 100;
                 }
                 $price->price_min_quantity = (int) @$price_min_quantity[$k];
                 if ($price->price_min_quantity == 1) {
                     $price->price_min_quantity = 0;
                 }
                 if (empty($price_access[$k])) {
                     $price->price_access = 'all';
                 } else {
                     $price->price_access = $price_access[$k];
                 }
                 if (!empty($price_currency_id[$k])) {
                     if (!is_numeric($price_currency_id[$k])) {
                         $price_currency_id[$k] = $this->_getCurrency($price_currency_id[$k]);
                     }
                     $price->price_currency_id = $price_currency_id[$k];
                 } else {
                     $config =& hikashop_config();
                     $price->price_currency_id = $config->get('main_currency', 1);
                 }
                 $product->prices[] = $price;
             }
         }
     }
     if (!empty($product->files) && !is_array($product->files)) {
         $this->_separate($product->files);
         $unset = array();
         foreach ($product->files as $k => $file) {
             $product->files[$k] = $file = trim($file);
             if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
                 $parts = explode('/', $file);
                 $name = array_pop($parts);
                 $name = explode('?', $name);
                 $name = array_shift($name);
                 $name = urldecode($name);
                 if (!file_exists($this->uploadFolder . $name)) {
                     $data = @file_get_contents($file);
                     if (empty($data) && !empty($this->default_file)) {
                         $name = $this->default_file;
                     } else {
                         JFile::write($this->uploadFolder . $name, $data);
                     }
                 } else {
                     $size = $this->getSizeFile($file);
                     if ($size != filesize($this->uploadFolder . $name)) {
                         $name = $size . '_' . $name;
                         if (!file_exists($this->uploadFolder . $name)) {
                             JFile::write($this->uploadFolder . $name, file_get_contents($file));
                         }
                     }
                 }
                 if (file_exists($this->uploadFolder . $name) && (filesize($this->uploadFolder . $name) > 0 || filesize($this->uploadFolder . $name) === false)) {
                     $product->files[$k] = $name;
                 } else {
                     $unset[] = $k;
                 }
             }
         }
         if (!empty($unset)) {
             foreach ($unset as $k) {
                 unset($product->files[$k]);
             }
         }
         $this->_filesToObject($product->files, 'files');
         $this->_getFilesExtraData($product->files, $product, 'files');
     }
     if (!empty($product->images) && !is_array($product->images)) {
         $this->_separate($product->images);
         $unset = array();
         foreach ($product->images as $k => $image) {
             $product->images[$k] = $image = trim($image);
             if (substr($image, 0, 7) == 'http://' || substr($image, 0, 8) == 'https://') {
                 $parts = explode('/', $image);
                 $name = array_pop($parts);
                 $name = explode('?', $name);
                 $name = array_shift($name);
                 $name = urldecode($name);
                 if (!file_exists($this->uploadFolder . $name)) {
                     $content = file_get_contents($image);
                     JFile::write($this->uploadFolder . $name, $content);
                 } else {
                     $size = $this->getSizeFile($image);
                     if ($size != filesize($this->uploadFolder . $name)) {
                         $name = $size . '_' . $name;
                         if (!file_exists($this->uploadFolder . $name)) {
                             $content = file_get_contents($image);
                             JFile::write($this->uploadFolder . $name, $content);
                         }
                     }
                 }
                 if (file_exists($this->uploadFolder . $name) && (filesize($this->uploadFolder . $name) > 0 || filesize($this->uploadFolder . $name) === false)) {
                     $product->images[$k] = $name;
                 } else {
                     $unset[] = $k;
                 }
             }
         }
         if (!empty($unset)) {
             foreach ($unset as $k) {
                 unset($product->images[$k]);
             }
         }
         $this->_filesToObject($product->images, 'images');
         $this->_getFilesExtraData($product->images, $product, 'images');
     }
     if (empty($product->product_name)) {
         if (!empty($product->files)) {
             if (!is_array($product->files)) {
                 $this->_separate($product->files);
             }
             if (is_object($product->files[0])) {
                 $name = $product->files[0]->file_name;
             } else {
                 $name = substr($product->files[0], 0, strrpos($product->files[0], '.'));
             }
             $product->product_name = $name;
         } elseif (!empty($product->images)) {
             if (!is_array($product->images)) {
                 $this->_separate($product->images);
             }
             if (is_object($product->images[0])) {
                 $name = $product->images[0]->file_name;
             } else {
                 $name = substr($product->images[0], 0, strrpos($product->images[0], '.'));
             }
             $product->product_name = $name;
         }
     }
     if (!empty($product->related) && !is_array($product->related)) {
         $this->_separate($product->related);
     }
     if (!empty($product->options) && !is_array($product->options)) {
         $this->_separate($product->options);
     }
     if ($product->product_type == 'variant') {
         $product->categories = null;
     } else {
         if (!empty($product->categories)) {
             if (!is_array($product->categories)) {
                 $this->_separate($product->categories);
             }
             $parent_id = 0;
             if ($this->createCategories && !empty($product->parent_category)) {
                 $this->_separate($product->parent_category);
                 $parent_id = array();
                 foreach ($product->parent_category as $k => $parent_category) {
                     if (is_numeric($parent_category)) {
                         $parent_id[$k] = $parent_category;
                     } else {
                         $parent_id[$k] = $this->_getCategory($parent_category, 0, false, 'product');
                         if (empty($parent_id[$k])) {
                             $parent_id[$k] = $this->_createCategory($parent_category);
                         }
                     }
                 }
             }
             if ($this->createCategories && !empty($product->categories_image)) {
                 $unset = array();
                 $this->_separate($product->categories_image);
                 foreach ($product->categories_image as $k => $image) {
                     if (substr($image, 0, 7) == 'http://' || substr($image, 0, 8) == 'https://') {
                         $parts = explode('/', $image);
                         $name = array_pop($parts);
                         if (!file_exists($this->uploadFolder . $name)) {
                             JFile::write($this->uploadFolder . $name, file_get_contents($image));
                         } else {
                             $size = $this->getSizeFile($image);
                             if ($size != filesize($this->uploadFolder . $name)) {
                                 $name = $size . '_' . $name;
                                 if (!file_exists($this->uploadFolder . $name)) {
                                     JFile::write($this->uploadFolder . $name, file_get_contents($image));
                                 }
                             }
                         }
                         if (filesize($this->uploadFolder . $name)) {
                             $product->categories_image[$k] = $name;
                         } else {
                             $unset[] = $k;
                         }
                     }
                 }
                 if (!empty($unset)) {
                     foreach ($unset as $k) {
                         unset($product->categories_image[$k]);
                     }
                 }
             }
             if ($this->createCategories && !empty($product->categories_namekey)) {
                 $this->_separate($product->categories_namekey);
             }
             foreach ($product->categories as $k => $v) {
                 if (!is_numeric($v) || !empty($product->categories_namekey)) {
                     $pid = 0;
                     if (is_array($parent_id)) {
                         if (!empty($parent_id[$k])) {
                             $pid = $parent_id[$k];
                         } elseif (!empty($parent_id[0])) {
                             $pid = $parent_id[0];
                         }
                     }
                     $id = $this->_getCategory($v, 0, !$this->createCategories, 'product', $pid, @$product->categories_image[$k]);
                     if (empty($id)) {
                         if ($this->createCategories) {
                             $id = $this->_createCategory($v, $pid, 'product', @$product->categories_image[$k], @$product->categories_namekey[$k]);
                         } else {
                             $app = JFactory::getApplication();
                             $app->enqueueMessage('The product ' . @$product->product_code . ' has the category name "' . $v . '" in your CSV but that category doesn\'t exist on your website and you turned off the automatic creation of categories for the import.', 'error');
                         }
                     }
                     $product->categories[$k] = (int) $id;
                 }
             }
         }
     }
     if (!empty($product->categories_ordering)) {
         $this->_separate($product->categories_ordering);
     }
     if (empty($product->product_access)) {
         if (!empty($this->template)) {
             $product->product_access = @$this->template->product_access;
         } else {
             $product->product_access = 'all';
         }
     }
     if (!isset($product->product_contact) && !empty($this->template)) {
         $product->product_contact = @$this->template->product_contact;
     }
     if (!isset($product->product_group_after_purchase) && !empty($this->template)) {
         $product->product_group_after_purchase = @$this->template->product_group_after_purchase;
     }
     if (hikashop_level(2) && !empty($product->product_access)) {
         if (!is_array($product->product_access)) {
             if (!in_array($product->product_access, array('none', 'all'))) {
                 if (!is_array($product->product_access)) {
                     $this->_separate($product->product_access);
                 }
             }
         }
         if (is_array($product->product_access)) {
             $accesses = array();
             foreach ($product->product_access as $access) {
                 if (empty($access)) {
                     continue;
                 }
                 if (!is_numeric($access)) {
                     $access = $this->_getAccess($access);
                     if (empty($access)) {
                         continue;
                     }
                 }
                 $accesses[] = $access;
             }
             $product->product_access = ',' . implode(',', $accesses) . ',';
         }
     }
     if (!empty($this->characteristicColumns)) {
         foreach ($this->characteristicColumns as $column) {
             if (isset($product->{$column}) && strlen($product->{$column}) > 0) {
                 if ($product->product_type == 'main' && !empty($this->characteristicsConversionTable[$column])) {
                     if (!isset($product->variant_links)) {
                         $product->variant_links = array();
                     }
                     $product->variant_links[] = $this->characteristicsConversionTable[$column];
                 }
                 if (function_exists('mb_strtolower')) {
                     $key = mb_strtolower(trim($product->{$column}, '" '));
                 } else {
                     $key = strtolower(trim($product->{$column}, '" '));
                 }
                 if (!empty($this->characteristicsConversionTable[$column . '_' . $key])) {
                     $key = $column . '_' . $key;
                 }
                 if (!empty($this->characteristicsConversionTable[$key])) {
                     if (!isset($product->variant_links)) {
                         $product->variant_links = array();
                     }
                     $product->variant_links[] = $this->characteristicsConversionTable[$key];
                 }
             }
         }
     }
     if (!empty($product->product_id) && empty($product->product_code)) {
         $query = 'SELECT `product_code` FROM ' . hikashop_table('product') . ' WHERE product_id=' . (int) $product->product_id;
         $this->db->setQuery($query);
         $product->product_code = $this->db->loadResult();
     } else {
         if (empty($product->product_code) && !empty($product->product_name)) {
             $test = preg_replace('#[^a-z0-9_-]#i', '', $product->product_name);
             if (empty($test)) {
                 static $last_pid = null;
                 if ($last_pid === null) {
                     $query = 'SELECT MAX(`product_id`) FROM ' . hikashop_table('product');
                     $this->db->setQuery($query);
                     $last_pid = (int) $this->db->loadResult();
                 }
                 $last_pid++;
                 $product->product_code = 'product_' . $last_pid;
             } else {
                 $product->product_code = preg_replace('#[^a-z0-9_-]#i', '_', $product->product_name);
             }
         }
     }
     if (empty($product->product_name) && !empty($this->template->product_name)) {
         $product->product_name = $this->template->product_name;
     }
     if (!empty($this->translateColumns)) {
         foreach ($this->translateColumns as $k => $v) {
             if (!empty($product->{$v})) {
                 list($name, $lng) = explode('__tr__', $v);
                 if ($lng == $this->locale) {
                     $product->{$name} =& $product->{$v};
                 } else {
                     if (isset($this->translateLanguages[$lng])) {
                         if (!isset($product->translations)) {
                             $product->translations = array();
                         }
                         $obj = new stdClass();
                         $obj->language_id = $this->translateLanguages[$lng];
                         $obj->reference_table = 'hikashop_product';
                         $obj->reference_field = $name;
                         $obj->value =& $product->{$v};
                         $obj->modified_by = 0;
                         //TODO
                         $obj->published = 1;
                         $product->translations[] = $obj;
                     }
                 }
             }
         }
     }
     $unset = array();
     foreach (get_object_vars($product) as $column => $value) {
         if (!empty($this->columnNamesConversionTable[$column]) && is_array($this->columnNamesConversionTable[$column])) {
             if (!empty($this->columnNamesConversionTable[$column]['append'])) {
                 $new_column = $this->columnNamesConversionTable[$column]['append'];
                 if (in_array($column, array('files', 'images'))) {
                     if (is_array($value)) {
                         $tmp = array();
                         foreach ($value as $v) {
                             $tmp[] = '<a href="' . $this->uploadFolder_url . $v . '">' . $v . '</a>';
                         }
                         $value = implode(',', $tmp);
                     } else {
                         $value = '<a href="' . $this->uploadFolder_url . $value . '">' . $value . '</a>';
                     }
                 }
                 $trans_string = 'HIKASHOP_FEED_' . strtoupper($column);
                 $trans = JText::_($trans_string);
                 if ($trans_string == $trans) {
                     $trans = $column;
                 }
                 $product->{$new_column} .= '<div id="hikashop_product_' . $column . '">' . $trans . ':' . $value . '</div>';
                 $unset[] = $column;
             }
             if (!empty($this->columnNamesConversionTable[$column]['copy'])) {
                 $new_column = $this->columnNamesConversionTable[$column]['copy'];
                 $product->{$new_column} = $value;
             }
         }
     }
     if ($product->product_type == 'main' && $main && !isset($product->product_parent_id)) {
         if (!empty($this->template->variants)) {
             foreach ($this->template->variants as $variant) {
                 $copy = !HIKASHOP_PHP5 ? $variant : clone $variant;
                 unset($copy->product_id);
                 $copy->product_parent_id = $product->product_code;
                 $copy->product_code = $product->product_code . '_' . $copy->product_code;
                 $this->currentProductVariants[] = $copy;
             }
         }
     }
     if (!empty($unset)) {
         foreach ($unset as $u) {
             unset($product->{$u});
         }
     }
 }
Beispiel #16
0
					</td>
					<td><?php 
echo $this->warehouseType->display('data[product][product_warehouse_id]', @$this->element->product_warehouse_id, true);
?>
</td>
				</tr>
				<tr class="hikashop_product_type_row">
					<td class="key">
							<?php 
echo JText::_('WIZARD_PRODUCT_TYPE');
?>
					</td>
					<td>
						<?php 
if (empty($this->product_type)) {
    if (!empty($this->element->product_weight) && hikashop_toFloat($this->element->product_weight) != 0.0) {
        $this->product_type = 'shippable';
    } else {
        $this->product_type = 'virtual';
    }
}
$arr = array(JHTML::_('select.option', 'shippable', JText::_('WIZARD_REAL')), JHTML::_('select.option', 'virtual', JText::_('WIZARD_VIRTUAL')));
echo JHTML::_('hikaselect.genericlist', $arr, "product_type", ' onchange="hikashopSetShippable(this.value);"', 'value', 'text', @$this->product_type);
?>
						<script type="text/javascript">
						function hikashopSetShippable(value){
							var display = false, fields = ['hikashop_product_weight_row', 'hikashop_product_volume_row'];
							if(value == 'shippable') display = true;
							window.hikashop.setArrayDisplay(fields, display);
						}
						window.hikashop.ready(function(){ hikashopSetShippable('<?php 
Beispiel #17
0
 function _RequestMethods($data, $xml)
 {
     $app = JFactory::getApplication();
     $session = curl_init("cybervente.postescanada.ca");
     curl_setopt($session, CURLOPT_HEADER, 1);
     curl_setopt($session, CURLOPT_POST, 1);
     curl_setopt($session, CURLOPT_PORT, 30000);
     curl_setopt($session, CURLOPT_TIMEOUT, 30);
     curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($session, CURLOPT_POSTFIELDS, $xml);
     $result = curl_exec($session);
     $error = curl_errno($session);
     $error_message = curl_error($session);
     curl_close($session);
     if ($error) {
         $app->enqueueMessage('An error occurred. The connection to the Canada Post server could not be established: ' . $error_message);
         return false;
     }
     $xml_data = strstr($result, '<?');
     $xml = simplexml_load_string($xml_data);
     if (isset($xml->ratesAndServicesResponse->statusCode) && $xml->ratesAndServicesResponse->statusCode != 1) {
         $app->enqueueMessage('Error while sending XML to CANADA POST. Error code: ' . $xml->ratesAndServicesResponse->statusCode . '. Message: ' . $xml->ratesAndServicesResponse->statusMessage . '', 'error');
         return false;
     }
     if (isset($xml->error->statusCode) && $xml->error->statusCode != 1) {
         $app->enqueueMessage('Error while sending XML to CANADA POST. Error code: ' . $xml->error->statusCode . '. Message: ' . $xml->error->statusMessage . '', 'error');
         return false;
     }
     $handling = 0.0;
     if (isset($xml->ratesAndServicesResponse->handling)) {
         $handling = hikashop_toFloat($xml->ratesAndServicesResponse->handling->__toString());
     }
     $i = 1;
     $shipment = array();
     foreach ($xml->ratesAndServicesResponse->product as $rate) {
         $shipment[$i++] = array('value' => hikashop_toFloat($rate->rate->__toString()) + $handling, 'name' => $rate->name->__toString(), 'shippingDate' => $rate->shippingDate->__toString(), 'deliveryDate' => $rate->deliveryDate->__toString(), 'deliveryDayOfWeek' => $rate->deliveryDayOfWeek->__toString(), 'nextDayAM' => $rate->nextDayAM->__toString(), 'status_code' => $xml->ratesAndServicesResponse->statusCode->__toString(), 'status_message' => $xml->ratesAndServicesResponse->statusMessage->__toString());
     }
     return $shipment;
 }