/** * Load the attributes for export * * @return void */ private function loadAttributes() { $producthelper = new producthelper(); $db = JFactory::getDbo(); $query = "SELECT * FROM `#__redshop_product` ORDER BY product_id asc "; $this->_db->setQuery($query); $cur = $this->_db->loadObjectList(); $ret = null; if (count($cur) > 0) { $redhelper = new redhelper(); $isrecrm = false; if ($redhelper->isredCRM()) { $isrecrm = true; } for ($i = 0; $i < count($cur); $i++) { if ($i == 0) { echo '"product_number","attribute_name","attribute_ordering","allow_multiple_selection","hide_attribute_price","attribute_required","display_type","property_name","property_stock"'; if ($isrecrm) { echo ',"property_stock_placement"'; } echo ',"property_ordering","property_virtual_number","setdefault_selected","setdisplay_type","oprand","property_price","property_image","property_main_image","subattribute_color_name","subattribute_stock"'; if ($isrecrm) { echo ',"subattribute_stock_placement"'; } echo ',"subattribute_color_ordering","subattribute_setdefault_selected","subattribute_color_title","subattribute_virtual_number","subattribute_color_oprand","required_sub_attribute","subattribute_color_price","subattribute_color_image","delete"'; echo "\r\n"; } // Added attribute of products $attribute = $producthelper->getProductAttribute($cur[$i]->product_id); $attr = array(); for ($att = 0; $att < count($attribute); $att++) { if ($attribute[$att]->attribute_name != "") { echo '"' . $cur[$i]->product_number . '","' . $attribute[$att]->attribute_name . '","' . $attribute[$att]->ordering . '","' . $attribute[$att]->allow_multiple_selection . '","' . $attribute[$att]->hide_attribute_price . '","' . $attribute[$att]->attribute_required . '","' . $attribute[$att]->display_type . '"'; if ($isrecrm) { echo ',,'; } echo ',,,,,,,,,,,,,,,,"0"'; echo "\r\n"; $att_property = $producthelper->getAttibuteProperty(0, $attribute[$att]->attribute_id); for ($prop = 0; $prop < count($att_property); $prop++) { $property_image = ""; $property_main_image = ""; $main_attribute_stock = ""; $sel_arrtibute_stock = "select * from `#__redshop_product_attribute_stockroom_xref` where section_id='" . $att_property[$prop]->property_id . "'"; $this->_db->setQuery($sel_arrtibute_stock); $fetch_arrtibute_stock = $this->_db->loadObjectList(); for ($h = 0; $h < count($fetch_arrtibute_stock); $h++) { $main_attribute_stock .= $fetch_arrtibute_stock[$h]->stockroom_id . ":" . $fetch_arrtibute_stock[$h]->quantity . "#"; } if ($att_property[$prop]->property_image != "") { $property_image = REDSHOP_FRONT_IMAGES_ABSPATH . 'product_attributes/' . $att_property[$prop]->property_image; } if ($att_property[$prop]->property_main_image != "") { $property_main_image = REDSHOP_FRONT_IMAGES_ABSPATH . 'property/' . $att_property[$prop]->property_main_image; } echo '"' . $cur[$i]->product_number . '","' . $attribute[$att]->attribute_name . '",,,,,,"' . $att_property[$prop]->property_name . '","' . $main_attribute_stock . '"'; if ($isrecrm) { $main_attribute_stock_placement = ""; // Initialiase variables. $query = $this->_db->getQuery(true); // Prepare query. $query->select('stock_placement'); $query->from('#__redcrm_attribute_stock_placement'); $query->where('section = "property"'); $query->where('section_id = "' . $att_property[$prop]->property_id . '"'); // Inject the query and load the result. $this->_db->setQuery($query); $main_attribute_stock_placement = $this->_db->loadResult(); echo ',"' . $main_attribute_stock_placement . '"'; } echo ',"' . $att_property[$prop]->ordering . '","' . $att_property[$prop]->property_number . '","' . $att_property[$prop]->setdefault_selected . '","' . $att_property[$prop]->setdisplay_type . '","' . $att_property[$prop]->oprand . '","' . $att_property[$prop]->property_price . '","' . $property_image . '","' . $property_main_image . '"'; if ($isrecrm) { echo ','; } echo ',,,,,,,,,"0"'; echo "\n"; $subatt_property = $producthelper->getAttibuteSubProperty(0, $att_property[$prop]->property_id); for ($subprop = 0; $subprop < count($subatt_property); $subprop++) { $subattribute_color_image = ""; $main_attribute_stock_sub = ""; $sel_arrtibute_stock_sub = "select * from `#__redshop_product_attribute_stockroom_xref` where section_id='" . $subatt_property[$subprop]->subattribute_color_id . "'"; $this->_db->setQuery($sel_arrtibute_stock_sub); $fetch_arrtibute_stock_sub = $this->_db->loadObjectList(); for ($b = 0; $b < count($fetch_arrtibute_stock_sub); $b++) { $main_attribute_stock_sub .= $fetch_arrtibute_stock_sub[$b]->stockroom_id . ":" . $fetch_arrtibute_stock_sub[$b]->quantity . "#"; } if ($subatt_property[$subprop]->subattribute_color_image != "") { $subattribute_color_image = REDSHOP_FRONT_IMAGES_ABSPATH . 'subcolor/' . $subatt_property[$subprop]->subattribute_color_image; } echo '"' . $cur[$i]->product_number . '","' . $attribute[$att]->attribute_name . '",,,,,,"' . $att_property[$prop]->property_name . '"'; if ($isrecrm) { echo ','; } echo ',,,,,,,,,,"' . $subatt_property[$subprop]->subattribute_color_name . '","' . $main_attribute_stock_sub . '"'; if ($isrecrm) { $main_attribute_stock_sub_placement = ""; // Initialiase variables. $query = $this->_db->getQuery(true); // Prepare query. $query->select('stock_placement'); $query->from('#__redcrm_attribute_stock_placement'); $query->where('section = "subproperty"'); $query->where('section_id = "' . $subatt_property[$subprop]->subattribute_color_id . '"'); // Inject the query and load the result. $this->_db->setQuery($query); $main_attribute_stock_sub_placement = $this->_db->loadResult(); echo ',"' . $main_attribute_stock_sub_placement . '"'; } echo ',"' . $subatt_property[$subprop]->ordering . '","' . $subatt_property[$subprop]->setdefault_selected . '","' . $subatt_property[$subprop]->subattribute_color_title . '","' . $subatt_property[$subprop]->subattribute_color_number . '","' . $subatt_property[$subprop]->oprand . '","' . $att_property[$prop]->setrequire_selected . '","' . $subatt_property[$subprop]->subattribute_color_price . '","' . $subattribute_color_image . '","0"'; echo "\n"; } } } } } } }
public function getProductMinDeliveryTime($product_id = 0, $section_id = 0, $section = '', $loadDiv = 1) { $db = JFactory::getDbo(); $helper = new redhelper(); if (!$section_id && !$section) { $query = "SELECT min_del_time as deltime, s.max_del_time, s.delivery_time " . " FROM " . $this->_table_prefix . "product_stockroom_xref AS ps , " . $this->_table_prefix . "stockroom as s " . " WHERE " . " ps.product_id = " . (int) $product_id . " AND ps.stockroom_id = s.stockroom_id and ps.quantity >0 ORDER BY min_del_time ASC LIMIT 0,1"; } else { $query = "SELECT min_del_time as deltime, s.max_del_time, s.delivery_time " . " FROM " . $this->_table_prefix . "product_attribute_stockroom_xref AS pas , " . $this->_table_prefix . "stockroom as s " . " WHERE " . " pas.section_id = " . (int) $section_id . " AND pas.section = " . $db->quote($section) . " AND pas.stockroom_id = s.stockroom_id and pas.quantity >0 ORDER BY min_del_time ASC LIMIT 0,1"; } $this->_db->setQuery($query); $result = $this->_db->loadObject(); $product_delivery_time = ''; if ($result) { if (!$section_id && !$section) { $sql = "SELECT min_del_time as deltime, s.max_del_time,s.delivery_time " . " FROM " . $this->_table_prefix . "stockroom as s, " . $this->_table_prefix . "product_stockroom_xref AS ps " . " WHERE " . " ps.product_id = " . (int) $product_id . " AND ps.stockroom_id = s.stockroom_id AND s.min_del_time = " . (int) $result->deltime . " and ps.quantity >=0 ORDER BY max_del_time ASC LIMIT 0,1"; } else { $sql = "SELECT min_del_time as deltime, s.max_del_time,s.delivery_time " . " FROM " . $this->_table_prefix . "stockroom as s, " . $this->_table_prefix . "product_attribute_stockroom_xref AS pas " . " WHERE " . " pas.section_id = " . (int) $section_id . " AND pas.section = '" . $db->quote($section) . "' AND pas.stockroom_id = s.stockroom_id AND s.min_del_time = " . (int) $result->deltime . " AND pas.quantity >=0 ORDER BY max_del_time ASC LIMIT 0,1"; } $this->_db->setQuery($sql); $row = $this->_db->loadObject(); if ($row->deltime == 0 || $row->deltime == ' ') { $product_delivery_time = ''; } else { if ($row->delivery_time == "Days") { $duration = JText::_('COM_REDSHOP_DAYS'); } else { $row->deltime = $row->deltime / 7; $row->max_del_time = $row->max_del_time / 7; $duration = JText::_('COM_REDSHOP_WEEKS'); } $product_delivery_time = (int) $row->deltime . "-" . (int) $row->max_del_time . " " . $duration; } } /** * redCRM includes */ if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $sendData = new stdClass(); $sendData->product_id = $product_id; $sendData->property_id = 0; $sendData->subproperty_id = 0; if ($section == 'property') { $sendData->property_id = $section_id; } elseif ($section == 'subproperty') { // Get data for property id $subattribute_data = $this->getAttibuteSubProperty($section_id); $sendData->property_id = $subattribute_data[0]->subattribute_id; $sendData->subproperty_id = $section_id; } $product_delivery_time = $crmSupplierOrderHelper->getProductDeliveryTime($sendData); $dayLanguage = strlen($product_delivery_time) == 1 && $product_delivery_time == 1 ? JText::_('COM_REDSHOP_DAY') : JText::_('COM_REDSHOP_DAYS'); $product_delivery_time = $product_delivery_time . " " . $dayLanguage; } } if ($product_delivery_time && $loadDiv) { $product_delivery_time = '<div id="ProductAttributeMinDelivery' . $product_id . '">' . $product_delivery_time . '</div>'; } return $product_delivery_time; }
JLoader::import('stockroom', JPATH_ADMINISTRATOR . '/components/com_redshop/helpers'); JLoader::import('economic', JPATH_ADMINISTRATOR . '/components/com_redshop/helpers'); JLoader::import('images', JPATH_ADMINISTRATOR . '/components/com_redshop/helpers'); $Redconfiguration = new Redconfiguration(); $Redconfiguration->defineDynamicVars(); JLoader::import('joomla.html.pagination'); require_once JPATH_COMPONENT . '/helpers/cron.php'; require_once JPATH_COMPONENT . '/helpers/statistic.php'; require_once JPATH_COMPONENT . '/helpers/pagination.php'; require_once JPATH_COMPONENT . '/helpers/helper.php'; require_once JPATH_COMPONENT . '/helpers/product.php'; require_once JPATH_COMPONENT . '/helpers/currency.php'; // Helper object $helper = new redhelper(); // Include redCRM if required $helper->isredCRM(); $print = JRequest::getCmd('print'); // Adding Redshop CSS $doc = JFactory::getDocument(); // Use diffrent CSS for print layout if (!$print) { JHTML::Stylesheet('redshop.css', 'components/com_redshop/assets/css/'); } else { JHTML::Stylesheet('print.css', 'components/com_redshop/assets/css/'); } JHTML::Stylesheet('style.css', 'components/com_redshop/assets/css/'); $Itemid = $helper->getCheckoutItemid(); $Itemid = JRequest::getInt('Itemid', $Itemid); $Itemid = $helper->getCartItemid(); // Include redshop js file. require_once JPATH_COMPONENT . '/helpers/redshop.js.php';
public function store($postdata) { $redshopMail = new redshopMail(); $order_functions = new order_functions(); $helper = new redhelper(); $producthelper = new producthelper(); $rsCarthelper = new rsCarthelper(); $shippinghelper = new shipping(); $adminproducthelper = new adminproducthelper(); $stockroomhelper = new rsstockroomhelper(); // For barcode generation $barcode_code = $order_functions->barcode_randon_number(12, 0); $postdata['barcode'] = $barcode_code; $row = $this->getTable('order_detail'); if (!$row->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } $iscrm = $helper->isredCRM(); if ($iscrm) { $postdata['order_id'] = $row->order_id; $postdata['debitor_id'] = $postdata['user_info_id']; JTable::addIncludePath(REDCRM_ADMIN . '/tables'); $crmorder =& $this->getTable('crm_order'); if (!$crmorder->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$crmorder->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Update rma table entry if (ENABLE_RMA && isset($postdata['rmanotes'])) { $rmaInfo = $this->getTable('rma_orders'); $rmaInfo->rma_number = $postdata['rma_number']; $rmaInfo->original_order_id = $postdata['main_order_id']; $rmaInfo->credit_note_order_id = $row->order_id; $rmaInfo->rma_note = $postdata['rmanotes']; $rmaInfo->store(); } JTable::addIncludePath(REDSHOP_ADMIN . '/tables'); } $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $row->ship_method_id))); $rowOrderStatus =& $this->getTable('order_status_log'); $rowOrderStatus->order_id = $row->order_id; $rowOrderStatus->order_status = $row->order_status; $rowOrderStatus->date_changed = time(); $rowOrderStatus->customer_note = $row->customer_note; $rowOrderStatus->store(); $billingaddresses = $order_functions->getBillingAddress($row->user_id); if (isset($postdata['billisship']) && $postdata['billisship'] == 1) { $shippingaddresses = $billingaddresses; } else { $key = 0; $shippingaddresses = $order_functions->getShippingAddress($row->user_id); $shipp_users_info_id = isset($postdata['shipp_users_info_id']) && $postdata['shipp_users_info_id'] != 0 ? $postdata['shipp_users_info_id'] : 0; if ($shipp_users_info_id != 0) { for ($o = 0; $o < count($shippingaddresses); $o++) { if ($shippingaddresses[$o]->users_info_id == $shipp_users_info_id) { $key = $o; break; } } } $shippingaddresses = $shippingaddresses[$key]; } // ORDER DELIVERY TIME IS REMAINING $user_id = $row->user_id; $item = $postdata['order_item']; for ($i = 0; $i < count($item); $i++) { $product_id = $item[$i]->product_id; $quantity = $item[$i]->quantity; $product_excl_price = $item[$i]->prdexclprice; $product_price = $item[$i]->productprice; // Attribute price added $generateAttributeCart = $rsCarthelper->generateAttributeArray((array) $item[$i], $user_id); $retAttArr = $producthelper->makeAttributeCart($generateAttributeCart, $product_id, $user_id, 0, $quantity); $product_attribute = $retAttArr[0]; // Accessory price $generateAccessoryCart = $rsCarthelper->generateAccessoryArray((array) $item[$i], $user_id); $retAccArr = $producthelper->makeAccessoryCart($generateAccessoryCart, $product_id, $user_id); $product_accessory = $retAccArr[0]; $accessory_total_price = $retAccArr[1]; $accessory_vat_price = $retAccArr[2]; $wrapper_price = 0; $wrapper_vat = 0; if ($item[$i]->wrapper_data != 0 && $item[$i]->wrapper_data != '') { $wrapper = $producthelper->getWrapper($product_id, $item[$i]->wrapper_data); if (count($wrapper) > 0) { if ($wrapper[0]->wrapper_price > 0) { $wrapper_vat = $producthelper->getProducttax($product_id, $wrapper[0]->wrapper_price, $user_id); } $wrapper_price = $wrapper[0]->wrapper_price + $wrapper_vat; } } $product = $producthelper->getProductById($product_id); $rowitem =& $this->getTable('order_item_detail'); if (!$rowitem->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } // STOCKROOM update $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, $quantity); $stockroom_id_list = $updatestock['stockroom_list']; $stockroom_quantity_list = $updatestock['stockroom_quantity_list']; $rowitem->stockroom_id = $stockroom_id_list; $rowitem->stockroom_quantity = $stockroom_quantity_list; $rowitem->order_item_id = 0; $rowitem->order_id = $row->order_id; $rowitem->user_info_id = $row->user_info_id; $rowitem->supplier_id = $product->manufacturer_id; $rowitem->product_id = $product_id; $rowitem->order_item_sku = $product->product_number; $rowitem->order_item_name = $product->product_name; $rowitem->product_quantity = $quantity; $rowitem->product_item_price = $product_price; $rowitem->product_item_price_excl_vat = $product_excl_price; $rowitem->product_final_price = $product_price * $quantity; $rowitem->order_item_currency = REDCURRENCY_SYMBOL; $rowitem->order_status = $row->order_status; $rowitem->cdate = $row->cdate; $rowitem->mdate = $row->cdate; $rowitem->product_attribute = $product_attribute; $rowitem->product_accessory = $product_accessory; $rowitem->wrapper_id = $item[$i]->wrapper_data; $rowitem->wrapper_price = $wrapper_price; $rowitem->is_giftcard = 0; // RedCRM product purchase price if ($iscrm) { $crmProductHelper = new crmProductHelper(); $crmproduct = $crmProductHelper->getProductById($product_id); $rowitem->product_purchase_price = $crmproduct->product_purchase_price > 0 ? $crmproduct->product_purchase_price : $crmproduct->product_price; } if ($producthelper->checkProductDownload($product_id)) { $medianame = $producthelper->getProductMediaName($product_id); for ($j = 0; $j < count($medianame); $j++) { $product_serial_number = $producthelper->getProdcutSerialNumber($product_id); $producthelper->insertProductDownload($product_id, $user_id, $rowitem->order_id, $medianame[$j]->media_name, $product_serial_number->serial_number); } } if (!$rowitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } /** my accessory save in table start */ if (count($generateAccessoryCart) > 0) { $attArr = $generateAccessoryCart; for ($a = 0; $a < count($attArr); $a++) { $accessory_vat_price = 0; $accessory_attribute = ""; $accessory_id = $attArr[$a]['accessory_id']; $accessory_name = $attArr[$a]['accessory_name']; $accessory_price = $attArr[$a]['accessory_price']; $accessory_org_price = $accessory_price; if ($accessory_price > 0) { $accessory_vat_price = $producthelper->getProductTax($product_id, $accessory_price, $user_id); } $attchildArr = $attArr[$a]['accessory_childs']; for ($j = 0; $j < count($attchildArr); $j++) { $attribute_id = $attchildArr[$j]['attribute_id']; $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>"; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $accessory_id; $rowattitem->section_name = $attchildArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 1; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attchildArr[$j]['attribute_childs']; for ($k = 0; $k < count($propArr); $k++) { $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $producthelper->getProducttax($product_id, $propArr[$k]['property_price'], $user_id); } $property_id = $propArr[$k]['property_id']; $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>"; $subpropArr = $propArr[$k]['property_childs']; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 1; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price'], $user_id); } $subproperty_id = $subpropArr[$l]['subproperty_id']; $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>"; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 1; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } } $accdata =& $this->getTable('accessory_detail'); if ($accessory_id > 0) { $accdata->load($accessory_id); } $accProductinfo = $producthelper->getProductById($accdata->child_product_id); $rowaccitem =& $this->getTable('order_acc_item'); $rowaccitem->order_item_acc_id = 0; $rowaccitem->order_item_id = $rowitem->order_item_id; $rowaccitem->product_id = $accessory_id; $rowaccitem->order_acc_item_sku = $accProductinfo->product_number; $rowaccitem->order_acc_item_name = $accessory_name; $rowaccitem->order_acc_price = $accessory_org_price; $rowaccitem->order_acc_vat = $accessory_vat_price; $rowaccitem->product_quantity = $quantity; $rowaccitem->product_acc_item_price = $accessory_price; $rowaccitem->product_acc_final_price = $accessory_price * $quantity; $rowaccitem->product_attribute = $accessory_attribute; if ($accessory_id > 0) { if (!$rowaccitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } /** my attribute save in table start */ if (count($generateAttributeCart) > 0) { $attArr = $generateAttributeCart; for ($j = 0; $j < count($attArr); $j++) { $attribute_id = $attArr[$j]['attribute_id']; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $rowitem->product_id; $rowattitem->section_name = $attArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 0; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attArr[$j]['attribute_childs']; for ($k = 0; $k < count($propArr); $k++) { $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price'], $user_id); } $property_id = $propArr[$k]['property_id']; /** product property STOCKROOM update start */ $updatestock = $stockroomhelper->updateStockroomQuantity($property_id, $quantity, "property"); $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 0; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $subpropArr = $propArr[$k]['property_childs']; for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $producthelper->getProducttax($product_id, $subpropArr[$l]['subproperty_price'], $user_id); } $subproperty_id = $subpropArr[$l]['subproperty_id']; /** product subproperty STOCKROOM update start */ $updatestock = $stockroomhelper->updateStockroomQuantity($subproperty_id, $quantity, "subproperty"); $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 0; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } } } // $producthelper->insertProdcutUserfield($i,$item,$rowitem->order_item_id,12); if (USE_CONTAINER) { $producthelper->updateContainerStock($product_id, $quantity, $rowitem->container_id); } // Store userfields $userfields = $item[$i]->extrafieldname; $userfields_id = $item[$i]->extrafieldId; for ($ui = 0; $ui < count($userfields); $ui++) { $adminproducthelper->admin_insertProdcutUserfield($userfields_id[$ui], $rowitem->order_item_id, 12, $userfields[$ui]); } // redCRM RMA Transaction Entry if ($iscrm) { if (ENABLE_RMA && $rowitem->product_final_price < 0) { // RMA transation log if (isset($item[$i]->reason)) { $rmaTrans =& $this->getTable('rma_transaction'); $rmaTrans->rma_transaction_id = 0; $rmaTrans->rma_number = $postdata['rma_number']; $rmaTrans->order_item_return_id = $rowitem->order_item_id; $rmaTrans->order_item_return_reason = $item[$i]->reason; $rmaTrans->order_item_return_status = $item[$i]->deposition; $rmaTrans->order_item_return_action = $item[$i]->action; $rmaTrans->cdate = time(); $rmaTrans->store(); if (ENABLE_ITEM_TRACKING_SYSTEM) { // Manage supplier order stock $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $senddata['main_order_number'] = $postdata['main_order_number']; $senddata['order_status'] = $row->order_status; $senddata['product_id'] = $rowitem->product_id; $senddata['property_id'] = $property_id; $senddata['subproperty_id'] = $subproperty_id; $senddata['deposition'] = $item[$i]->deposition; $itemqty = $rowitem->product_quantity; for ($r = 0; $r < $itemqty; $r++) { $crmSupplierOrderHelper->manageStockAffectedRMA($senddata); } } } } } } $rowpayment =& $this->getTable('order_payment'); if (!$rowpayment->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } $rowpayment->order_id = $row->order_id; $rowpayment->payment_method_id = $postdata['payment_method_class']; $rowpayment->order_payment_amount = $row->order_total; $rowpayment->order_payment_name = $postdata['order_payment_name']; $rowpayment->payment_method_class = $postdata['payment_method_class']; if (!$rowpayment->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add billing Info $userrow =& $this->getTable('user_detail'); $userrow->load($billingaddresses->users_info_id); $orderuserrow =& $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $row->order_id; $orderuserrow->address_type = 'BT'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add shipping Info $userrow =& $this->getTable('user_detail'); if (isset($shippingaddresses->users_info_id)) { $userrow->load($shippingaddresses->users_info_id); } $orderuserrow =& $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $row->order_id; $orderuserrow->address_type = 'ST'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } if ($row->order_status == CLICKATELL_ORDER_STATUS) { $helper->clickatellSMS($row->order_id); } // Maintan supplier order stck when item tracking system is enabled if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $getStatus = array(); $getStatus['orderstatus'] = $row->order_status; $getStatus['paymentstatus'] = $row->order_payment_status; $crmSupplierOrderHelper->redSHOPOrderUpdate($row->order_id, $getStatus); unset($getStatus); } } $checkOrderStatus = 1; if ($postdata['payment_method_class'] == "rs_payment_banktransfer" || $postdata['payment_method_class'] == "rs_payment_banktransfer_discount" || $postdata['payment_method_class'] == "rs_payment_banktransfer2" || $postdata['payment_method_class'] == "rs_payment_banktransfer3" || $postdata['payment_method_class'] == "rs_payment_banktransfer4" || $postdata['payment_method_class'] == "rs_payment_banktransfer5") { $checkOrderStatus = 0; } // Economic Integration start for invoice generate and book current invoice if (ECONOMIC_INTEGRATION == 1 && ECONOMIC_INVOICE_DRAFT != 2) { $issplit = 0; $economic = new economic(); if (isset($postdata['issplit']) && $postdata['issplit'] == 1) { $issplit = 1; } $economicdata['split_payment'] = $issplit; $economicdata['economic_payment_terms_id'] = $postdata['economic_payment_terms_id']; $economicdata['economic_design_layout'] = $postdata['economic_design_layout']; $economicdata['economic_is_creditcard'] = $postdata['economic_is_creditcard']; $payment_name = $postdata['payment_method_class']; $paymentArr = explode("rs_payment_", $postdata['payment_method_class']); if (count($paymentArr) > 0) { $payment_name = $paymentArr[1]; } $economicdata['economic_payment_method'] = $payment_name; $invoiceHandle = $economic->createInvoiceInEconomic($row->order_id, $economicdata); if (ECONOMIC_INVOICE_DRAFT == 0) { $bookinvoicepdf = $economic->bookInvoiceInEconomic($row->order_id, $checkOrderStatus); if (is_file($bookinvoicepdf)) { $ret = $redshopMail->sendEconomicBookInvoiceMail($row->order_id, $bookinvoicepdf); } } } // ORDER MAIL SEND if ($postdata['task'] != "save_without_sendmail") { $redshopMail->sendOrderMail($row->order_id); } return $row; }
/** * Method for checkout second step. * * @return void */ public function checkoutnext() { $app = JFactory::getApplication(); $session = JFactory::getSession(); $post = JRequest::get('post'); $user = JFactory::getUser(); $cart = $session->get('cart'); if (isset($post['extrafields0']) && isset($post['extrafields']) && count($cart) > 0) { if (count($post['extrafields0']) > 0 && count($post['extrafields']) > 0) { for ($r = 0; $r < count($post['extrafields']); $r++) { $post['extrafields_values'][$post['extrafields'][$r]] = $post['extrafields0'][$r]; } $cart['extrafields_values'] = $post['extrafields_values']; $session->set('cart', $cart); } } $Itemid = JRequest::getInt('Itemid'); $users_info_id = JRequest::getInt('users_info_id'); $helper = new redhelper(); $chk = $this->chkvalidation($users_info_id); if (!empty($chk)) { if ($chk == 1) { $link = 'index.php?option=com_redshop&view=account_billto&return=checkout&setexit=0&Itemid=' . $Itemid; } else { $link = 'index.php?option=com_redshop&view=account_shipto&task=addshipping&setexit=0&return=checkout&infoid=' . $users_info_id . '&Itemid=' . $Itemid; } $app->Redirect($link); } if ($helper->isredCRM()) { if (($session->get('isredcrmuser_debitor') || $session->get('isredcrmuser')) && ($post['payment_method_id'] == "rs_payment_banktransfer" || $post['payment_method_id'] == "rs_payment_banktransfer2" || $post['payment_method_id'] == "rs_payment_banktransfer3" || $post['payment_method_id'] == "rs_payment_banktransfer4" || $post['payment_method_id'] == "rs_payment_banktransfer5" || $post['payment_method_id'] == "rs_payment_cashtransfer" || $post['payment_method_id'] == "rs_payment_cashsale" || $post['payment_method_id'] == "rs_payment_banktransfer_discount")) { $crmDebitorHelper = new crmDebitorHelper(); if ($session->get('isredcrmuser_debitor')) { $debitor_id = $session->get('isredcrmuser_debitor'); } else { $debitor_id_tot = $crmDebitorHelper->getContactPersons(0, 0, 0, $user->id); $debitor_id = $debitor_id_tot[0]->section_id; } $details = $crmDebitorHelper->getDebitor($debitor_id); if (count($details) > 0 && $details[0]->is_company == 1) { $unpaid = $details[0]->debitor_unpaid_balance; $max_credit = $details[0]->debitor_max_credit; $total = $cart['total']; if ($max_credit <= $unpaid + $total) { $option = JRequest::getVar('option'); $Itemid = JRequest::getVar('Itemid'); $msg = JText::_('DEBITOR_CREDIT_LIMIT_EXCEED'); $link = JRoute::_('index.php?option=' . $option . '&view=checkout&Itemid=' . $Itemid, false); $this->setRedirect($link, $msg); } } } } $option = JRequest::getVar('option'); $Itemid = JRequest::getVar('Itemid'); $ccinfo = JRequest::getVar('ccinfo'); $errormsg = ""; if ($ccinfo == 1) { $errormsg = $this->setcreditcardInfo(); } if ($errormsg != "") { $app->Redirect('index.php?option=' . $option . '&view=checkout&Itemid=' . $Itemid, $errormsg); } else { $view = $this->getView('checkout', 'next'); parent::display(); } }
</th> <th><?php echo JText::_('COM_REDSHOP_ALREDAY_ORDERED_PREORDER_STOCKROOM_QTY'); ?> </th> </tr> </thead> <tbody> <?php $iscrm = false; $helper = new redhelper(); /** * redCRM includes */ if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { $iscrm = true; $crmHelper = new crmHelper(); $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $stockWhere = USE_STOCKROOM ? " 1=1" : " stockroom_id = " . DEFAULT_STOCKROOM; $stockroom_list = $crmHelper->getStockroom('stockroom_id AS value,stockroom_name AS text', "1", $stockWhere); $stockroomname = $stockroom_list[0]->text; $data = new stdClass(); $data->product_id = $this->detail->product_id; $data->property_id = 0; $data->subproperty_id = 0; if ($section == 'property') { $data->property_id = $section_id; } elseif ($section == 'subproperty') { // Get data for property id.
public function orderplace() { $app = JFactory::getApplication(); $redconfig = new Redconfiguration(); $quotationHelper = new quotationHelper(); $stockroomhelper = new rsstockroomhelper(); $helper = new redhelper(); $shippinghelper = new shipping(); $order_functions = new order_functions(); $post = JRequest::get('post'); $option = JRequest::getVar('option', 'com_redshop'); $Itemid = JRequest::getVar('Itemid'); $shop_id = JRequest::getVar('shop_id'); $gls_mobile = JRequest::getVar('gls_mobile'); $customer_message = JRequest::getVar('rs_customer_message_ta'); $referral_code = JRequest::getVar('txt_referral_code'); if ($gls_mobile) { $shop_id = $shop_id . '###' . $gls_mobile; } $user = JFactory::getUser(); $session = JFactory::getSession(); $auth = $session->get('auth'); if (!$user->id && $auth['users_info_id']) { $user->id = -$auth['users_info_id']; } $db = JFactory::getDbo(); $issplit = $session->get('issplit'); $url = JURI::root(); // If user subscribe for the newsletter if (isset($post['newsletter_signup']) && $post['newsletter_signup'] == 1) { $this->_userhelper->newsletterSubscribe(); } // If user unsubscribe for the newsletter if (isset($post['newsletter_signoff']) && $post['newsletter_signoff'] == 1) { $this->_userhelper->newsletterUnsubscribe(); } $order_paymentstatus = 'Unpaid'; $objshipping = new shipping(); $users_info_id = JRequest::getInt('users_info_id'); $thirdparty_email = JRequest::getVar('thirdparty_email'); $shippingaddresses = $this->shipaddress($users_info_id); $billingaddresses = $this->billingaddresses(); if (isset($shippingaddresses)) { $d["shippingaddress"] = $shippingaddresses; $d["shippingaddress"]->country_2_code = $redconfig->getCountryCode2($d["shippingaddress"]->country_code); $d["shippingaddress"]->state_2_code = $redconfig->getStateCode2($d["shippingaddress"]->state_code); $shippingaddresses->country_2_code = $d["shippingaddress"]->country_2_code; $shippingaddresses->state_2_code = $d["shippingaddress"]->state_2_code; } if (isset($billingaddresses)) { $d["billingaddress"] = $billingaddresses; if (isset($billingaddresses->country_code)) { $d["billingaddress"]->country_2_code = $redconfig->getCountryCode2($billingaddresses->country_code); $billingaddresses->country_2_code = $d["billingaddress"]->country_2_code; } if (isset($billingaddresses->state_code)) { $d["billingaddress"]->state_2_code = $redconfig->getStateCode2($billingaddresses->state_code); $billingaddresses->state_2_code = $d["billingaddress"]->state_2_code; } } $cart = $session->get('cart'); if ($cart['idx'] < 1) { $msg = JText::_('COM_REDSHOP_EMPTY_CART'); $app->Redirect('index.php?option=' . $option . '&Itemid=' . $Itemid, $msg); } $ccdata = $session->get('ccdata'); $shipping_rate_id = ''; if ($cart['free_shipping'] != 1) { $shipping_rate_id = JRequest::getVar('shipping_rate_id'); } $payment_method_id = JRequest::getVar('payment_method_id'); $ccinfo = JRequest::getVar('ccinfo'); if ($shipping_rate_id && $cart['free_shipping'] != 1) { $shipArr = $this->calculateShipping($shipping_rate_id); $cart['shipping'] = $shipArr['order_shipping_rate']; $cart['shipping_vat'] = $shipArr['shipping_vat']; } $cart = $this->_carthelper->modifyDiscount($cart); $paymentinfo = $this->_order_functions->getPaymentMethodInfo($payment_method_id); $paymentinfo = $paymentinfo[0]; $paymentparams = new JRegistry($paymentinfo->params); $paymentinfo = new stdclass(); $paymentinfo->payment_price = $paymentparams->get('payment_price', ''); $paymentinfo->payment_oprand = $paymentparams->get('payment_oprand', ''); $paymentinfo->payment_discount_is_percent = $paymentparams->get('payment_discount_is_percent', ''); if (PAYMENT_CALCULATION_ON == 'subtotal') { $paymentAmount = $cart['product_subtotal']; } else { $paymentAmount = $cart['total']; } $paymentArray = $this->_carthelper->calculatePayment($paymentAmount, $paymentinfo, $cart['total']); $cart['total'] = $paymentArray[0]; $cart = $session->set('cart', $cart); $cart = $session->get('cart'); $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $shipping_rate_id))); $order_status = 'P'; $order_status_full = $this->_order_functions->getOrderStatusTitle('P'); // Start code to track duplicate order number checking by parth $order_number = $this->getOrdernumber(); // End code to track duplicate order number checking by parth $order_subtotal = $cart['product_subtotal']; $cdiscount = $cart['coupon_discount']; $order_tax = $cart['tax']; $d['order_tax'] = $order_tax; $tax_after_discount = 0; if (isset($cart['tax_after_discount'])) { $tax_after_discount = $cart['tax_after_discount']; } $odiscount = $cart['coupon_discount'] + $cart['voucher_discount'] + $cart['cart_discount']; $odiscount_vat = $cart['discount_vat']; $d["order_payment_trans_id"] = ''; $d['discount'] = $odiscount; $order_total = $cart['total']; if ($issplit) { $order_total = $order_total / 2; } JRequest::setVar('order_ship', $order_shipping[3]); $paymentmethod = $this->_order_functions->getPaymentMethodInfo($payment_method_id); $paymentmethod = $paymentmethod[0]; $mainelement = $paymentmethod->element; if ($paymentmethod->element == "rs_payment_banktransfer" || $paymentmethod->element == "rs_payment_banktransfer2" || $paymentmethod->element == "rs_payment_banktransfer3" || $paymentmethod->element == "rs_payment_banktransfer4" || $paymentmethod->element == "rs_payment_banktransfer5" || $paymentmethod->element == "rs_payment_cashtransfer" || $paymentmethod->element == "rs_payment_cashsale" || $paymentmethod->element == "rs_payment_banktransfer_discount" || $paymentmethod->element == "rs_payment_eantransfer") { $paymentmethod = $order_functions->getPaymentMethodInfo($paymentmethod->element); $paymentmethod = $paymentmethod[0]; $paymentpath = JPATH_SITE . '/plugins/redshop_payment/' . $paymentmethod->element . '.xml'; $paymentparams = new JRegistry($paymentmethod->params); $order_main_status = $paymentparams->get('verify_status', ''); if ($paymentmethod->element != "rs_payment_banktransfer" && $paymentmethod->element != "rs_payment_cashtransfer" && $paymentmethod->element != "rs_payment_cashsale" && $paymentmethod->element != "rs_payment_banktransfer_discount" && $paymentmethod->element != "rs_payment_eantransfer") { $paymentmethod->element = substr($paymentmethod->element, 0, -1); } } if ($paymentmethod->element == "rs_payment_banktransfer" || $paymentmethod->element == "rs_payment_cashtransfer" || $paymentmethod->element == "rs_payment_cashsale" || $paymentmethod->element == "rs_payment_banktransfer_discount" || $paymentmethod->element == "rs_payment_eantransfer") { $order_status = $order_main_status; if ($issplit) { $order_paymentstatus = trim("Partial Paid"); } else { $order_paymentstatus = trim("Unpaid"); } $order_status_full = $this->_order_functions->getOrderStatusTitle($order_main_status); } $paymentmethod->element = $mainelement; $payment_amount = 0; if (isset($cart['payment_amount'])) { $payment_amount = $cart['payment_amount']; } $payment_oprand = ""; if (isset($cart['payment_oprand'])) { $payment_oprand = $cart['payment_oprand']; } $xmlpath = JPATH_SITE . '/plugins/redshop_payment/' . $paymentmethod->element . '.xml'; $params = new JRegistry($paymentmethod->params, $xmlpath); $economic_payment_terms_id = $params->get('economic_payment_terms_id'); $economic_design_layout = $params->get('economic_design_layout'); $is_creditcard = $params->get('is_creditcard', ''); $is_redirected = $params->get('is_redirected', 0); JRequest::setVar('payment_status', $order_paymentstatus); $d['order_shipping'] = $order_shipping[3]; $GLOBALS['billingaddresses'] = $billingaddresses; $timestamp = time(); // Get the IP Address if (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = 'unknown'; } $row = $this->getTable('order_detail'); if (!$row->bind($post)) { $this->setError($this->_db->getErrorMsg()); return false; } $shippingVatRate = 0; if (array_key_exists(6, $order_shipping)) { $shippingVatRate = $order_shipping[6]; } $random_gen_enc_key = $this->_order_functions->random_gen_enc_key(35); $users_info_id = $billingaddresses->users_info_id; $row->user_id = $user->id; $row->order_number = $order_number; $row->user_info_id = $users_info_id; $row->order_total = $order_total; $row->order_subtotal = $order_subtotal; $row->order_tax = $order_tax; $row->tax_after_discount = $tax_after_discount; $row->order_tax_details = ''; $row->analytics_status = 0; $row->order_shipping = $order_shipping[3]; $row->order_shipping_tax = $shippingVatRate; $row->coupon_discount = $cdiscount; $row->shop_id = $shop_id; $row->customer_message = $customer_message; $row->referral_code = $referral_code; $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); $order_status_log = ''; // For credit card payment gateway page will redirect to order detail page from plugin if ($is_creditcard == 1 && $is_redirected == 1) { $redirect_ccdata = $session->set('redirect_ccdata', $ccdata); } if ($is_creditcard == 1 && $is_redirected == 0 && $cart['total'] > 0) { JPluginHelper::importPlugin('redshop_payment'); $values['order_shipping'] = $d['order_shipping']; $values['order_number'] = $order_number; $values['order_tax'] = $d['order_tax']; $values['shippinginfo'] = $d['shippingaddress']; $values['billinginfo'] = $d['billingaddress']; $values['order_total'] = $order_total; $values['order_subtotal'] = $order_subtotal; $values["order_id"] = $order_id; $values['payment_plugin'] = $paymentmethod->element; $values['odiscount'] = $odiscount; $paymentResponses = $dispatcher->trigger('onPrePayment_' . $values['payment_plugin'], array($values['payment_plugin'], $values)); $paymentResponse = $paymentResponses[0]; if ($paymentResponse->responsestatus == "Success") { $d["order_payment_trans_id"] = $paymentResponse->transaction_id; $order_status_log = $paymentResponse->message; $order_status = 'C'; $order_paymentstatus = 'Paid'; } else { if ($values['payment_plugin'] != 'rs_payment_localcreditcard') { $errorMsg = $paymentResponse->message; $this->setError($errorMsg); return false; } } } if ($order_total <= 0) { $paymentpath = JPATH_SITE . '/plugins/redshop_payment/' . $paymentmethod->element . '.xml'; $paymentparams = new JRegistry($paymentmethod->params); $order_main_status = $paymentparams->get('verify_status', ''); $order_status = $order_main_status; $order_paymentstatus = 'Paid'; } if (USE_AS_CATALOG) { $order_status = 'P'; $order_paymentstatus = 'Unpaid'; } // For barcode generation $barcode_code = $order_functions->barcode_randon_number(12, 0); // End $row->order_discount = $odiscount; $row->order_discount_vat = $odiscount_vat; $row->payment_discount = $payment_amount; $row->payment_oprand = $payment_oprand; $row->order_status = $order_status; $row->order_payment_status = $order_paymentstatus; $row->cdate = $timestamp; $row->mdate = $timestamp; $row->ship_method_id = $shipping_rate_id; $row->customer_note = $post['customer_note']; $row->requisition_number = $post['requisition_number']; $row->ip_address = $ip; $row->encr_key = $random_gen_enc_key; $row->split_payment = $issplit; $row->discount_type = $this->discount_type; $row->order_id = JRequest::getVar('order_id', $row->order_id); $row->barcode = $barcode_code; if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); // Start code to track duplicate order number checking by parth $this->deleteOrdernumberTrack(); // End code to track duplicate order number checking by parth return false; } // Start code to track duplicate order number checking by parth $this->deleteOrdernumberTrack(); // End code to track duplicate order number checking by parth $order_id = $row->order_id; $this->coupon($cart, $order_id); $this->voucher($cart, $order_id); $query = "UPDATE `#__redshop_orders` SET discount_type = " . $db->quote($this->discount_type) . " where order_id = " . (int) $order_id; $db->setQuery($query); $db->query(); if (SHOW_TERMS_AND_CONDITIONS == 1 && isset($post['termscondition']) && $post['termscondition'] == 1) { $this->_userhelper->updateUserTermsCondition($users_info_id, 1); } // Place order id in quotation table if it Quotation if (array_key_exists("quotation_id", $cart) && $cart['quotation_id']) { $quotationHelper->updateQuotationwithOrder($cart['quotation_id'], $row->order_id); } if ($row->order_status == CLICKATELL_ORDER_STATUS) { $helper->clickatellSMS($order_id); } $session->set('order_id', $order_id); // Add order status log $rowOrderStatus = $this->getTable('order_status_log'); $rowOrderStatus->order_id = $order_id; $rowOrderStatus->order_status = $order_status; $rowOrderStatus->date_changed = time(); $rowOrderStatus->customer_note = $order_status_log; $rowOrderStatus->store(); $country_name = $this->_order_functions->getCountryName($billingaddresses->country_code); $state_name = $this->_order_functions->getStateName($billingaddresses->state_code, $billingaddresses->country_code); JRequest::setVar('order_id', $row->order_id); JRequest::setVar('order_number', $row->order_number); if (!isset($order_shipping[5])) { $order_shipping[5] = ""; } if ($order_shipping[5] == 'regular') { $regDel = $objshipping->getRegularDelivery(); JRequest::setVar('order_delivery', "Delivered in one instance � DELIVERY TIME: " . current($regDel) . " weeks</td>"); } elseif ($order_shipping[5] == 'split') { $delArray = $objshipping->getProductDeliveryArray($shipping_rate_id); $splitdel = $objshipping->getSplitDelivery(); if (count($splitdel) > 1) { $split1 = $splitdel[0]; $split2 = $splitdel[1]; $prods1 = ''; $prods2 = ''; for ($i = 0; $i < count($split1); $i++) { $value = current($split1); $deltime1 = $value; $key = key($split1); $product = $this->_producthelper->getProductById($key, "product_name"); $prods1 .= $product->product_name . ','; next($split1); } for ($i = 0; $i < count($split2); $i++) { $value = current($split2); $deltime2 = $value; $key = key($split2); $product = $this->_producthelper->getProductById($key, "product_name"); $prods2 .= $product->product_name . ','; next($split2); } $prods1 = trim($prods1, ","); $prods2 = trim($prods2, ","); } JRequest::setVar('order_delivery', "Delivered over two instances for " . SPLIT_DELIVERY_COST . "kr extra DELIVERY TIME: " . $deltime1 . " Weeks for " . $prods1 . " AND " . $deltime2 . " Weeks for " . $prods2 . " "); } else { $delArray = $objshipping->getProductDeliveryArray($shipping_rate_id); $splitdel = $objshipping->getSplitDelivery(); $split1 = $splitdel[0]; $value = current($split1); $product_delivery_time = $this->_producthelper->getProductMinDeliveryTime($cart[0]['product_id']); JRequest::setVar('order_delivery', $product_delivery_time); } $idx = $cart['idx']; $product_name = ""; $product_note = ""; $product_price = ""; $product_quantity = ""; $product_total_price = ""; for ($i = 0; $i < $idx; $i++) { // GiftCARD start $is_giftcard = 0; $giftcard_price = 0; $giftcard_name = 0; // GiftCARD end $product_id = $cart[$i]['product_id']; $product = $this->_producthelper->getProductById($product_id); $rowitem = $this->getTable('order_item_detail'); // The redCRM product purchase price if ($helper->isredCRM()) { $crmProductHelper = new crmProductHelper(); $crmproduct = $crmProductHelper->getProductById($product_id); $rowitem->product_purchase_price = $crmproduct->product_purchase_price > 0 ? $crmproduct->product_purchase_price : $crmproduct->product_price; $crmdata = array(); $crmDebitorHelper = new crmDebitorHelper(); $crmDebitorHelper_values = $crmDebitorHelper->getShippingDestination(0, 0, $shippingaddresses->users_info_id); if ($session->get('isredcrmuser')) { $crmDebitorHelper_contact_values = $crmDebitorHelper->getContactPersons(0, 0, 0, $user->id, 0); } else { $crmDebitorHelper_contact_values = $crmDebitorHelper->getContactPersons(0, 0, 0, 0, $crmDebitorHelper_values[0]->shipping_id); } $crmdata['order_id'] = JRequest::getVar('order_id', $row->order_id); $crmdata['debitor_id'] = $shippingaddresses->users_info_id; $crmdata['custom_status'] = ''; $crmdata['rma_number'] = ''; if (count($crmDebitorHelper_values) > 0) { $crmdata['shipping_id'] = $crmDebitorHelper_values[0]->shipping_id; } else { $crmdata['shipping_id'] = 0; } if (count($crmDebitorHelper_contact_values) > 0 && count($crmDebitorHelper_values) > 0) { $crmdata['person_id'] = $crmDebitorHelper_contact_values[0]->person_id; } else { $crmdata['person_id'] = 0; } $crmOrderHelper = new crmOrderHelper(); $crmOrderHelper->storeCRMOrder($crmdata); } // End if (!$rowitem->bind($post)) { $this->setError($this->_db->getErrorMsg()); return false; } if ($order_shipping[5] == 'regular') { $rowitem->delivery_time = $regDel; } elseif ($order_shipping[5] == 'split') { $rowitem->delivery_time = $delArray[$product_id]; } else { $rowitem->delivery_time = ''; } if (isset($cart[$i]['giftcard_id']) && $cart[$i]['giftcard_id']) { $is_giftcard = 1; } // Product stockroom update if (!$is_giftcard) { $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, $cart[$i]['quantity']); $stockroom_id_list = $updatestock['stockroom_list']; $stockroom_quantity_list = $updatestock['stockroom_quantity_list']; $rowitem->stockroom_id = $stockroom_id_list; $rowitem->stockroom_quantity = $stockroom_quantity_list; } // End product stockroom update $vals = explode('product_attributes/', $cart[$i]['hidden_attribute_cartimage']); if (!empty($cart[$i]['attributeImage']) && file_exists(JPATH_ROOT . '/components/com_redshop/assets/images/mergeImages/' . $cart[$i]['attributeImage'])) { $rowitem->attribute_image = $order_id . $cart[$i]['attributeImage']; $old_media = JPATH_ROOT . '/components/com_redshop/assets/images/mergeImages/' . $cart[$i]['attributeImage']; $new_media = JPATH_ROOT . '/components/com_redshop/assets/images/orderMergeImages' . $rowitem->attribute_image; copy($old_media, $new_media); } elseif (!empty($vals[1])) { $rowitem->attribute_image = $vals[1]; } $wrapper_price = 0; if (@$cart[$i]['wrapper_id']) { $wrapper_price = $cart[$i]['wrapper_price']; } if ($is_giftcard == 1) { $giftcardData = $this->_producthelper->getGiftcardData($cart[$i]['giftcard_id']); $rowitem->product_id = $cart[$i]['giftcard_id']; $rowitem->order_item_name = $giftcardData->giftcard_name; $rowitem->product_item_old_price = $cart[$i]['product_price']; } else { $rowitem->product_id = $product_id; $rowitem->product_item_old_price = $cart[$i]['product_old_price']; $rowitem->supplier_id = $product->manufacturer_id; $rowitem->order_item_sku = $product->product_number; $rowitem->order_item_name = $product->product_name; } $rowitem->product_item_price = $cart[$i]['product_price']; $rowitem->product_quantity = $cart[$i]['quantity']; $rowitem->product_item_price_excl_vat = $cart[$i]['product_price_excl_vat']; $rowitem->product_final_price = $cart[$i]['product_price'] * $cart[$i]['quantity']; $rowitem->is_giftcard = $is_giftcard; $retAttArr = $this->_producthelper->makeAttributeCart($cart[$i]['cart_attribute'], $product_id, 0, 0, $cart[$i]['quantity']); $cart_attribute = $retAttArr[0]; // For discount calc data $cart_calc_data = ""; if (isset($cart[$i]['discount_calc_output'])) { $cart_calc_data = $cart[$i]['discount_calc_output']; } // End $retAccArr = $this->_producthelper->makeAccessoryCart($cart[$i]['cart_accessory'], $product_id); $cart_accessory = $retAccArr[0]; $rowitem->order_id = $order_id; $rowitem->user_info_id = $users_info_id; $rowitem->order_item_currency = REDCURRENCY_SYMBOL; $rowitem->order_status = $order_status; $rowitem->cdate = $timestamp; $rowitem->mdate = $timestamp; $rowitem->product_attribute = $cart_attribute; $rowitem->discount_calc_data = $cart_calc_data; $rowitem->product_accessory = $cart_accessory; $rowitem->container_id = $objshipping->getProductContainerId($cart[$i]['product_id']); $rowitem->wrapper_price = $wrapper_price; if (!empty($cart[$i]['wrapper_id'])) { $rowitem->wrapper_id = $cart[$i]['wrapper_id']; } if (!empty($cart[$i]['reciver_email'])) { $rowitem->giftcard_user_email = $cart[$i]['reciver_email']; } if (!empty($cart[$i]['reciver_name'])) { $rowitem->giftcard_user_name = $cart[$i]['reciver_name']; } if ($this->_producthelper->checkProductDownload($rowitem->product_id)) { $medianame = $this->_producthelper->getProductMediaName($rowitem->product_id); for ($j = 0; $j < count($medianame); $j++) { $product_serial_number = $this->_producthelper->getProdcutSerialNumber($rowitem->product_id); $this->_producthelper->insertProductDownload($rowitem->product_id, $user->id, $rowitem->order_id, $medianame[$j]->media_name, $product_serial_number->serial_number); } } // Import files for plugin JPluginHelper::importPlugin('redshop_product'); if (!$rowitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add plugin support $dispatcher->trigger('afterOrderItemSave', array($cart, $rowitem, $i)); // End if (isset($cart[$i]['giftcard_id']) && $cart[$i]['giftcard_id']) { $section_id = 13; } else { $section_id = 12; } $this->_producthelper->insertProdcutUserfield($i, $cart, $rowitem->order_item_id, $section_id); // My accessory save in table start if (count($cart[$i]['cart_accessory']) > 0) { $setPropEqual = true; $setSubpropEqual = true; $attArr = $cart[$i]['cart_accessory']; for ($a = 0; $a < count($attArr); $a++) { $accessory_vat_price = 0; $accessory_attribute = ""; $accessory_id = $attArr[$a]['accessory_id']; $accessory_name = $attArr[$a]['accessory_name']; $accessory_price = $attArr[$a]['accessory_price']; $accessory_quantity = $attArr[$a]['accessory_quantity']; $accessory_org_price = $accessory_price; if ($accessory_price > 0) { $accessory_vat_price = $this->_producthelper->getProductTax($rowitem->product_id, $accessory_price); } $attchildArr = $attArr[$a]['accessory_childs']; for ($j = 0; $j < count($attchildArr); $j++) { $prooprand = array(); $proprice = array(); $attribute_id = $attchildArr[$j]['attribute_id']; $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>"; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $accessory_id; $rowattitem->section_name = $attchildArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 1; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attchildArr[$j]['attribute_childs']; for ($k = 0; $k < count($propArr); $k++) { $prooprand[$k] = $propArr[$k]['property_oprand']; $proprice[$k] = $propArr[$k]['property_price']; $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $this->_producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price']); } $property_id = $propArr[$k]['property_id']; $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $this->_producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>"; $subpropArr = $propArr[$k]['property_childs']; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 1; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $this->_producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price']); } $subproperty_id = $subpropArr[$l]['subproperty_id']; $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $this->_producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>"; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 1; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } // FOR ACCESSORY PROPERTY AND SUBPROPERTY PRICE CALCULATION if ($setPropEqual && $setSubpropEqual) { $accessory_priceArr = $this->_producthelper->makeTotalPriceByOprand($accessory_price, $prooprand, $proprice); $setPropEqual = $accessory_priceArr[0]; $accessory_price = $accessory_priceArr[1]; } for ($t = 0; $t < count($propArr); $t++) { $subprooprand = array(); $subproprice = array(); $subElementArr = $propArr[$t]['property_childs']; for ($tp = 0; $tp < count($subElementArr); $tp++) { $subprooprand[$tp] = $subElementArr[$tp]['subproperty_oprand']; $subproprice[$tp] = $subElementArr[$tp]['subproperty_price']; } if ($setPropEqual && $setSubpropEqual) { $accessory_priceArr = $this->_producthelper->makeTotalPriceByOprand($accessory_price, $subprooprand, $subproprice); $setSubpropEqual = $accessory_priceArr[0]; $accessory_price = $accessory_priceArr[1]; } } // FOR ACCESSORY PROPERTY AND SUBPROPERTY PRICE CALCULATION } $accdata = $this->getTable('accessory_detail'); if ($accessory_id > 0) { $accdata->load($accessory_id); } $accProductinfo = $this->_producthelper->getProductById($accdata->child_product_id); $rowaccitem = $this->getTable('order_acc_item'); $rowaccitem->order_item_acc_id = 0; $rowaccitem->order_item_id = $rowitem->order_item_id; $rowaccitem->product_id = $accessory_id; $rowaccitem->order_acc_item_sku = $accProductinfo->product_number; $rowaccitem->order_acc_item_name = $accessory_name; $rowaccitem->order_acc_price = $accessory_org_price; $rowaccitem->order_acc_vat = $accessory_vat_price; $rowaccitem->product_quantity = $accessory_quantity; $rowaccitem->product_acc_item_price = $accessory_price; $rowaccitem->product_acc_final_price = $accessory_price * $accessory_quantity; $rowaccitem->product_attribute = $accessory_attribute; if ($accessory_id > 0) { if (!$rowaccitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } // My attribute save in table start if (count($cart[$i]['cart_attribute']) > 0) { $attchildArr = $cart[$i]['cart_attribute']; for ($j = 0; $j < count($attchildArr); $j++) { $attribute_id = $attchildArr[$j]['attribute_id']; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $rowitem->product_id; $rowattitem->section_name = $attchildArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 0; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attchildArr[$j]['attribute_childs']; if (count($propArr) > 0) { for ($k = 0; $k < count($propArr); $k++) { $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $this->_producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price']); } $property_id = $propArr[$k]['property_id']; // Product property STOCKROOM update start $updatestock_att = $stockroomhelper->updateStockroomQuantity($property_id, $cart[$i]['quantity'], "property", $product_id); $stockroom_att_id_list = $updatestock_att['stockroom_list']; $stockroom_att_quantity_list = $updatestock_att['stockroom_quantity_list']; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 0; $rowattitem->stockroom_id = $stockroom_att_id_list; $rowattitem->stockroom_quantity = $stockroom_att_quantity_list; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $subpropArr = $propArr[$k]['property_childs']; for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $this->_producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price']); } $subproperty_id = $subpropArr[$l]['subproperty_id']; // Product subproperty STOCKROOM update start $updatestock_subatt = $stockroomhelper->updateStockroomQuantity($subproperty_id, $cart[$i]['quantity'], "subproperty", $product_id); $stockroom_subatt_id_list = $updatestock_subatt['stockroom_list']; $stockroom_subatt_quantity_list = $updatestock_subatt['stockroom_quantity_list']; $rowattitem = $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 0; $rowattitem->stockroom_id = $stockroom_subatt_id_list; $rowattitem->stockroom_quantity = $stockroom_subatt_quantity_list; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } } } } // Subtracting the products from the container. means decreasing stock if (USE_CONTAINER) { $this->_producthelper->updateContainerStock($product_id, $cart[$i]['quantity'], $rowitem->container_id); } // Subtracting the products from the container. means decreasing stock end // Store user product subscription detail if ($product->product_type == 'subscription') { $subscribe = $this->getTable('product_subscribe_detail'); $subscription_detail = $this->_producthelper->getProductSubscriptionDetail($product_id, $cart[$i]['subscription_id']); $add_day = $subscription_detail->period_type == 'days' ? $subscription_detail->subscription_period : 0; $add_month = $subscription_detail->period_type == 'month' ? $subscription_detail->subscription_period : 0; $add_year = $subscription_detail->period_type == 'year' ? $subscription_detail->subscription_period : 0; $subscribe->order_id = $order_id; $subscribe->order_item_id = $rowitem->order_item_id; $subscribe->product_id = $product_id; $subscribe->subscription_id = $cart[$i]['subscription_id']; $subscribe->user_id = $user->id; $subscribe->start_date = time(); $subscribe->end_date = mktime(0, 0, 0, date('m') + $add_month, date('d') + $add_day, date('Y') + $add_year); if (!$subscribe->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } $rowpayment = $this->getTable('order_payment'); if (!$rowpayment->bind($post)) { $this->setError($this->_db->getErrorMsg()); return false; } $rowpayment->order_id = $order_id; $rowpayment->payment_method_id = $payment_method_id; if (!isset($ccdata['creditcard_code'])) { $ccdata['creditcard_code'] = 0; } if (!isset($ccdata['order_payment_number'])) { $ccdata['order_payment_number'] = 0; } if (!isset($ccdata['order_payment_expire_month'])) { $ccdata['order_payment_expire_month'] = 0; } if (!isset($ccdata['order_payment_expire_year'])) { $ccdata['order_payment_expire_year'] = 0; } $rowpayment->order_payment_code = $ccdata['creditcard_code']; $rowpayment->order_payment_cardname = base64_encode($ccdata['order_payment_name']); $rowpayment->order_payment_number = base64_encode($ccdata['order_payment_number']); // This is ccv code $rowpayment->order_payment_ccv = base64_encode($ccdata['credit_card_code']); $rowpayment->order_payment_amount = $order_total; $rowpayment->order_payment_expire = $ccdata['order_payment_expire_month'] . $ccdata['order_payment_expire_year']; $rowpayment->order_payment_name = $paymentmethod->name; $rowpayment->payment_method_class = $paymentmethod->element; $rowpayment->order_payment_trans_id = $d["order_payment_trans_id"]; $rowpayment->authorize_status = ""; if (!$rowpayment->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // For authorize status JPluginHelper::importPlugin('redshop_payment'); $dispatcher = JDispatcher::getInstance(); $data = $dispatcher->trigger('onAuthorizeStatus_' . $paymentmethod->element, array($paymentmethod->element, $order_id)); $GLOBALS['shippingaddresses'] = $shippingaddresses; // Add billing Info $userrow = $this->getTable('user_detail'); $userrow->load($billingaddresses->users_info_id); $userrow->thirdparty_email = $post['thirdparty_email']; $orderuserrow = $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $order_id; $orderuserrow->address_type = 'BT'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add shipping Info $userrow = $this->getTable('user_detail'); if (isset($shippingaddresses->users_info_id)) { $userrow->load($shippingaddresses->users_info_id); } $orderuserrow = $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $order_id; $orderuserrow->address_type = 'ST'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } $checkOrderStatus = 1; if ($paymentmethod->element == "rs_payment_banktransfer" || $paymentmethod->element == "rs_payment_banktransfer_discount" || $paymentmethod->element == "rs_payment_banktransfer2" || $paymentmethod->element == "rs_payment_banktransfer3" || $paymentmethod->element == "rs_payment_banktransfer4" || $paymentmethod->element == "rs_payment_banktransfer5") { $checkOrderStatus = 0; } if (isset($cart['extrafields_values'])) { if (count($cart['extrafields_values']) > 0) { $this->_producthelper->insertPaymentShippingField($cart, $order_id, 18); $this->_producthelper->insertPaymentShippingField($cart, $order_id, 19); } } // Economic Integration start for invoice generate and book current invoice if (ECONOMIC_INTEGRATION == 1 && ECONOMIC_INVOICE_DRAFT != 2) { $economic = new economic(); $economicdata['split_payment'] = $issplit; $economicdata['economic_payment_terms_id'] = $economic_payment_terms_id; $economicdata['economic_design_layout'] = $economic_design_layout; $economicdata['economic_is_creditcard'] = $is_creditcard; $payment_name = $paymentmethod->element; $paymentArr = explode("rs_payment_", $paymentmethod->element); if (count($paymentArr) > 0) { $payment_name = $paymentArr[1]; } $economicdata['economic_payment_method'] = $payment_name; $invoiceHandle = $economic->createInvoiceInEconomic($row->order_id, $economicdata); if (ECONOMIC_INVOICE_DRAFT == 0) { $bookinvoicepdf = $economic->bookInvoiceInEconomic($row->order_id, $checkOrderStatus); if (is_file($bookinvoicepdf)) { $ret = $this->_redshopMail->sendEconomicBookInvoiceMail($row->order_id, $bookinvoicepdf); } } } // End Economic // Send the Order mail before payment if (!ORDER_MAIL_AFTER || ORDER_MAIL_AFTER && $row->order_payment_status == "Paid") { $this->_redshopMail->sendOrderMail($row->order_id); } else { // If Order mail set to send after payment then send mail to administrator only. $this->_redshopMail->sendOrderMail($row->order_id, true); } if ($row->order_status == "C") { $this->_order_functions->SendDownload($row->order_id); } // RedCRM includes if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $getStatus = array(); $getStatus['orderstatus'] = $row->order_status; $getStatus['paymentstatus'] = $row->order_payment_status; $crmSupplierOrderHelper->redSHOPOrderUpdate($row->order_id, $getStatus); unset($getStatus); } } return $row; }
public function display($tpl = null) { global $context; $app = JFactory::getApplication(); $prodhelperobj = new producthelper(); $prodhelperobj->generateBreadcrumb(); $Itemid = JRequest::getInt('Itemid'); $layout = JRequest::getCmd('layout'); $params = $app->getParams('com_redshop'); $document = JFactory::getDocument(); $model = $this->getModel(); $user = JFactory::getUser(); $userdata = $model->getuseraccountinfo($user->id); if (!count($userdata) && $layout != 'mywishlist') { $msg = JText::_('COM_REDSHOP_LOGIN_USER_IS_NOT_REDSHOP_USER'); $app->Redirect("index.php?option=com_redshop&view=account_billto&Itemid=" . $Itemid, $msg); } $layout = JRequest::getCmd('layout', 'default'); $mail = JRequest::getInt('mail'); // Preform security checks if ($user->id == 0 && $layout != 'mywishlist' || $user->id == 0 && $layout == 'mywishlist' && !isset($mail)) { $app->Redirect('index.php?option=com_redshop&view=login&Itemid=' . JRequest::getInt('Itemid')); return; } if ($layout == 'mytags') { JLoader::import('joomla.html.pagination'); $this->setLayout('mytags'); $remove = JRequest::getInt('remove', 0); if ($remove == 1) { $model->removeTag(); } $maxcategory = $params->get('maxcategory', 5); $limit = $app->getUserStateFromRequest($context . 'limit', 'limit', $maxcategory, 5); $limitstart = JRequest::getInt('limitstart', 0, '', 'int'); $total = $this->get('total'); $pagination = new redPagination($total, $limitstart, $limit); $this->pagination = $pagination; } if ($layout == 'mywishlist') { $wishlist_id = $app->input->getInt('wishlist_id', 0); // If wishlist Id is not set then redirect to it's main page if ($wishlist_id == 0) { $app->Redirect("index.php?option=com_redshop&view=wishlist&layout=viewwishlist&Itemid=" . $Itemid); } JLoader::import('joomla.html.pagination'); JHTML::Stylesheet('colorbox.css', 'components/com_redshop/assets/css/'); JHTML::Script('jquery.js', 'components/com_redshop/assets/js/', false); JHTML::Script('jquery.colorbox-min.js', 'components/com_redshop/assets/js/', false); JHTML::Script('redBOX.js', 'components/com_redshop/assets/js/', false); JHTML::Script('attribute.js', 'components/com_redshop/assets/js/', false); JHTML::Script('common.js', 'components/com_redshop/assets/js/', false); $this->setLayout('mywishlist'); $remove = JRequest::getInt('remove', 0); if ($remove == 1) { $model->removeWishlistProduct(); } $maxcategory = $params->get('maxcategory', 5); $limit = $app->getUserStateFromRequest($context . 'limit', 'limit', $maxcategory, 5); $limitstart = JRequest::getInt('limitstart', 0, '', 'int'); $total = $this->get('total'); $pagination = new redPagination($total, $limitstart, $limit); $this->pagination = $pagination; } if ($layout == 'compare') { $remove = JRequest::getInt('remove', 0); if ($remove == 1) { $model->removeCompare(); } JLoader::import('joomla.html.pagination'); $this->setLayout('compare'); } $this->user = $user; $this->userdata = $userdata; $this->params = $params; // RedCRM Template // Helper object $helper = new redhelper(); if ($layout == "default" && $helper->isredCRM()) { $tmplPath = JPATH_BASE . '/components/com_redcrm/views/account/tmpl'; $this->addTemplatePath($tmplPath); parent::display('storemanagement'); } // RedCRM Template END parent::display($tpl); }
public function storeRedshopUser($data, $user_id = 0, $admin = 0) { $redshopMail = new redshopMail(); $extra_field = new extra_field(); $helper = new redhelper(); $data['user_email'] = $data['email'] = $data['email1']; $data['name'] = $name = $data['firstname']; $data['address_type'] = 'BT'; $row = JTable::getInstance('user_detail', 'Table'); if (isset($data['users_info_id']) && $data['users_info_id'] != 0) { $isNew = false; $row->load($data['users_info_id']); $data["old_tax_exempt_approved"] = $row->tax_exempt_approved; $user_id = $row->user_id; } else { $isNew = true; $data['password'] = JRequest::getVar('password1', '', 'post', 'string', JREQUEST_ALLOWRAW); $app = JFactory::getApplication(); $is_admin = $app->isAdmin(); if ($data['is_company'] == 1) { if ($is_admin && $data['shopper_group_id'] != 0) { $data['shopper_group_id'] = $data['shopper_group_id']; } else { $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_COMPANY != 0 ? SHOPPER_GROUP_DEFAULT_COMPANY : 2; } } else { if ($is_admin && isset($data['shopper_group_id']) && $data['shopper_group_id'] != 0) { $data['shopper_group_id'] = $data['shopper_group_id']; } else { $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_PRIVATE != 0 ? SHOPPER_GROUP_DEFAULT_PRIVATE : 1; } } } if ($user_id > 0) { $joomlauser = new JUser($user_id); $data['username'] = $joomlauser->username; $data['name'] = $joomlauser->name; $data['email'] = $joomlauser->email; } if (SHOW_TERMS_AND_CONDITIONS == 1 && isset($data['termscondition']) && $data['termscondition'] == 1) { $data['accept_terms_conditions'] = 1; } $row->user_id = $data['user_id'] = $user_id; if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (USE_TAX_EXEMPT) { if (!$admin && $row->is_company == 1) { $row->requesting_tax_exempt = $data['tax_exempt']; if ($row->requesting_tax_exempt == 1) { $redshopMail->sendRequestTaxExemptMail($row, $data['username']); } } // Sending tax exempted mails (tax_exempt_approval_mail) if (!$isNew && $admin && isset($data["tax_exempt_approved"]) && $data["old_tax_exempt_approved"] != $data["tax_exempt_approved"]) { if ($data["tax_exempt_approved"] == 1) { $redshopMail->sendTaxExemptMail("tax_exempt_approval_mail", $data, $row->user_email); } else { $redshopMail->sendTaxExemptMail("tax_exempt_disapproval_mail", $data, $row->user_email); } } } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Update user info id if (ECONOMIC_INTEGRATION) { $economic = new economic(); $original_info_id = $row->users_info_id; if ($isNew) { $maxDebtor = $economic->getMaxDebtorInEconomic(); if (count($maxDebtor) > 0) { $maxDebtor = $maxDebtor[0]; if ($row->users_info_id <= $maxDebtor) { $nextId = $maxDebtor + 1; $sql = "UPDATE " . $this->_table_prefix . "users_info " . "SET users_info_id = " . (int) $nextId . " " . "WHERE users_info_id = " . (int) $row->users_info_id; $this->_db->setQuery($sql); $this->_db->Query(); $row->users_info_id = $nextId; } } } $debtorHandle = $economic->createUserInEconomic($row); if ($row->is_company && trim($row->ean_number) != '' && JError::isError(JError::getError())) { $msg = JText::_('PLEASE_ENTER_EAN_NUMBER'); JError::raiseWarning('', $msg); return false; } } $auth['users_info_id'] = $row->users_info_id; $this->_session->set('auth', $auth); // For non-registered customers if (!$row->user_id) { $row->user_id = 0 - $row->users_info_id; $row->store(); $u = JFactory::getUser(); $u->set('username', $row->user_email); $u->set('email', $row->user_email); $u->set('usertype', 'Registered'); $date = JFactory::getDate(); $u->set('registerDate', $date->toMySQL()); $data['user_id'] = $row->user_id; $data['username'] = $row->user_email; $data['email'] = $row->user_email; } if (isset($data['newsletter_signup']) && $data['newsletter_signup'] == 1) { $this->newsletterSubscribe($row->user_id, $data); } $billisship = 1; if (!isset($data['billisship'])) { $billisship = 0; } // Info: field_section 6 :Userinformations $list_field = $extra_field->extra_field_save($data, 6, $row->users_info_id); if ($row->is_company == 0) { // Info: field_section 7 :Userinformations $list_field = $extra_field->extra_field_save($data, 7, $row->users_info_id); } else { // Info: field_section 8 :Userinformations $list_field = $extra_field->extra_field_save($data, 8, $row->users_info_id); } if ($billisship != 1) { $rowShip = $this->storeRedshopUserShipping($data); } if (REGISTER_METHOD != 1 && $isNew && $admin == 0) { if (REGISTER_METHOD == 2) { if (isset($data['createaccount']) && $data['createaccount'] == 1) { $redshopMail->sendRegistrationMail($data); } } else { $redshopMail->sendRegistrationMail($data); } } if ($isNew) { JPluginHelper::importPlugin('highrise'); $dispatcher = JDispatcher::getInstance(); $hResponses = $dispatcher->trigger('oncreateHighriseUser', array()); } /** * redCRM includes */ if ($helper->isredCRM()) { $this->setoreredCRMDebtor($row); } return $row; }
if ($billingaddresses) { // Dont allow to edit if redCRM Contact Person is logged in if (!$session->get('isredcrmuser')) { ?> <a class="modal" href="<?php echo $editbill; ?> " rel="{handler: 'iframe', size: {x: 720, y: 470}}"><?php echo JText::_('COM_REDSHOP_EDIT'); ?> </a> <?php } // Billing or Shipping address if ($redhelper->isredCRM()) { echo $this->loadTemplate('billing_crm'); } else { echo $this->loadTemplate('billing'); } } else { ?> <div class="billnotice"><?php echo JText::_('COM_REDSHOP_FILL_BILLING_ADDRESS'); ?> </div> <a class="modal" href="<?php echo $editbill; ?> " rel="{handler: 'iframe', size: {x: 800, y: 550}}"> <?php
public function importdata() { ob_clean(); $thumb = new thumbnail(); $obj_img = new thumbnail_images(); $session = JFactory::getSession(); /* Get all posted data */ $new_line = JRequest::getVar('new_line'); $post = $session->get('ImportPost'); $files = $session->get('Importfile'); $file_name = $session->get('Importfilename'); /* Load the table model */ switch ($post['import']) { case 'products': $row = $this->getTable('product_detail'); break; case 'categories': $row = $this->getTable('category_detail'); break; } /** * check is redCRM is installed or not */ $redhelper = new redhelper(); $isredcrm = false; if ($redhelper->isredCRM()) { $isredcrm = true; } /* Loop through the CSV file */ /* First line first as that is the column headers */ $line = 1; $headers = array(); $correctlines = 0; $handle = fopen(JPATH_ROOT . '/components/com_redshop/assets/importcsv/' . $post['import'] . '/' . $file_name, "r"); $separator = ","; if ($post['separator'] != "") { $separator = $post['separator']; } list($susec, $ssec) = explode(" ", microtime()); $start_micro_time = (double) $susec + (double) $ssec; $session->set('start_micro_time', $start_micro_time); while (($data = fgetcsv($handle, 0, $separator, '"')) !== false) { if ($this->getTimeLeft() > 0) { // Skip headers if ($line == 1) { foreach ($data as $key => $name) { /* Set the column headers */ $headers[$key] = $name; } } else { if ($line > $new_line) { $rawdata = array(); foreach ($data as $key => $name) { // Bind the data if ($headers[$key] == 'category_full_image' && $post['import'] == 'categories') { $image_name = basename($name); $rawdata[$headers[$key]] = $image_name; if ($image_name != "") { @fopen($name, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'category/' . $image_name; // Copy If file is not already exist if (!file_exists($dest)) { copy($name, $dest); } } } elseif ($headers[$key] == 'sitepath' && $post['import'] == 'products') { $this->sitepath = $rawdata[$headers[$key]] = $name; } else { $rawdata[$headers[$key]] = $name; } } // Import categories if ($post['import'] == 'categories') { $category_id = $rawdata['category_id']; $query = "SELECT COUNT(*) FROM " . $this->_table_prefix . "category WHERE category_id = '" . $category_id . "'"; $this->_db->setQuery($query); $cidCount = $this->_db->loadResult(); // Updating category $row = $this->getTable('category_detail'); if ($cidCount > 0) { $row->load($category_id); } else { $row->category_id = $category_id; } $row->category_name = $rawdata['category_name']; $row->category_short_description = $rawdata['category_short_description']; $row->category_description = $rawdata['category_description']; $row->category_template = $rawdata['category_template']; $row->category_more_template = $rawdata['category_more_template']; $row->products_per_page = $rawdata['products_per_page']; $row->category_thumb_image = $rawdata['category_thumb_image']; $row->category_full_image = $rawdata['category_full_image']; $row->metakey = $rawdata['metakey']; $row->metadesc = $rawdata['metadesc']; $row->metalanguage_setting = $rawdata['metalanguage_setting']; $row->metarobot_info = $rawdata['metarobot_info']; $row->pagetitle = $rawdata['pagetitle']; $row->pageheading = $rawdata['pageheading']; $row->sef_url = $rawdata['sef_url']; $row->published = $rawdata['published']; $row->category_pdate = $rawdata['category_pdate']; $row->ordering = $rawdata['ordering']; if ($cidCount > 0) { // Update if (!$row->store()) { return JText::_('COM_REDSHOP_ERROR_DURING_IMPORT'); } } else { // Insert $ret = $this->_db->insertObject($this->_table_prefix . 'category', $row, 'category_id'); if (!$ret) { return JText::_('COM_REDSHOP_ERROR_DURING_IMPORT'); } } $query = "SELECT COUNT(*) FROM " . $this->_table_prefix . "category_xref " . "WHERE category_parent_id='" . $rawdata['category_parent_id'] . "' " . "AND category_child_id='" . $row->category_id . "' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count == 0) { // Remove existing $query = "DELETE FROM `" . $this->_table_prefix . "category_xref` WHERE `category_child_id` = '" . $row->category_id . "' "; $this->_db->setQuery($query); $this->_db->Query(); $query = "INSERT INTO " . $this->_table_prefix . "category_xref VALUES('" . $rawdata['category_parent_id'] . "','" . $row->category_id . "') "; $this->_db->setQuery($query); $this->_db->Query(); } $correctlines++; } // Import products if ($post['import'] == 'products' && isset($rawdata['product_number'])) { $rawdata['product_price'] = '' . str_replace(',', '.', $rawdata['product_price']) . ''; $product_id = $this->getProductIdByNumber($rawdata['product_number']); if ((int) $product_id > 0) { $rawdata['product_id'] = (int) $product_id; } // Product Description is optional - no need to add column in csv everytime. if (isset($rawdata['product_desc']) === true) { $rawdata['product_desc'] = htmlentities($rawdata['product_desc']); } // Product Short Description is also optional - no need to add column in csv everytime. if (isset($rawdata['product_s_desc']) === true) { $rawdata['product_s_desc'] = htmlentities($rawdata['product_s_desc']); } if (isset($rawdata['manufacturer_name'])) { $query = "SELECT `manufacturer_id` FROM `" . $this->_table_prefix . "manufacturer` " . "WHERE `manufacturer_name` = '" . $rawdata['manufacturer_name'] . "' "; $this->_db->setQuery($query); $manufacturer_id = $this->_db->loadResult(); $rawdata['manufacturer_id'] = $manufacturer_id; } // Updating/inserting product $row = $this->getTable('product_detail'); $row->load($rawdata['product_id']); // Do not update with blank imagecategory_id if ($rawdata['product_thumb_image'] == "") { unset($rawdata['product_thumb_image']); } if ($rawdata['product_full_image'] == "") { unset($rawdata['product_full_image']); } if ($rawdata['product_back_full_image'] == "") { unset($rawdata['product_back_full_image']); } if ($rawdata['product_preview_back_image'] == "") { unset($rawdata['product_preview_back_image']); } $row->bind($rawdata); // Set boolean for Error $isError = false; if ((int) $product_id > 0) { // Update if (!$row->store()) { $isError = true; return JText::_('COM_REDSHOP_ERROR_DURING_IMPORT'); } } else { // Insert $row->product_id = (int) $rawdata['product_id']; $ret = $this->_db->insertObject($this->_table_prefix . 'product', $row, 'product_id'); if (!$ret) { $isError = true; return JText::_('COM_REDSHOP_ERROR_DURING_IMPORT'); } } if (!$isError) { // Last inserted product id $product_id = $row->product_id; // Product Full Image $product_full_image = trim($rawdata['product_full_image']); if ($product_full_image != "") { $src = $this->sitepath . "components/com_redshop/assets/images/product/" . $product_full_image; @fopen($src, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'product/' . $product_full_image; // Copy If file is not already exist if (!file_exists($dest)) { @copy($name, $dest); } } $section_images = $rawdata['images']; $image_name = explode("#", $section_images); if (is_array($image_name)) { for ($i = 0; $i < count($image_name); $i++) { if (trim($image_name[$i]) != "") { $src = $this->sitepath . "components/com_redshop/assets/images/product/" . trim($image_name[$i]); @fopen($src, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'product/' . trim($image_name[$i]); // Copy If file is not already exist if (!file_exists($dest)) { @copy($src, $dest); } } } } $section_images_order = $rawdata['images_order']; $section_images_alternattext = $rawdata['images_alternattext']; // Section videos $section_video = $rawdata['video']; $image_name = explode("#", $section_video); if (is_array($image_name)) { for ($i = 0; $i < count($image_name); $i++) { if (trim($image_name[$i]) != "") { $src = $this->sitepath . "components/com_redshop/assets/video/product/" . trim($image_name[$i]); @fopen($src, "r"); $dest = JPATH_COMPONENT_SITE . '/assets/video/product/' . trim($image_name[$i]); // Copy If file is not already exist if (!file_exists($dest)) { @copy($src, $dest); } } } } $section_video_order = $rawdata['video_order']; $section_video_alternattext = $rawdata['video_alternattext']; // Section document $section_document = $rawdata['document']; $image_name = explode("#", $section_document); if (is_array($image_name)) { for ($i = 0; $i < count($image_name); $i++) { if (trim($image_name[$i]) != "") { $src = $this->sitepath . "components/com_redshop/assets/document/product/" . trim($image_name[$i]); @fopen($src, "r"); $dest = REDSHOP_FRONT_DOCUMENT_RELPATH . 'product/' . trim($image_name[$i]); // Copy If file is not already exist if (!file_exists($dest)) { @copy($src, $dest); } } } } $section_document_order = $rawdata['document_order']; $section_document_alternattext = $rawdata['document_alternattext']; // Section Download if (isset($rawdata['download'])) { $section_download = $rawdata['download']; $image_name = explode("#", $section_download); if (is_array($image_name)) { for ($i = 0; $i < count($image_name); $i++) { if (trim($image_name[$i]) != "") { $src = $this->sitepath . "components/com_redshop/assets/download/product/" . trim($image_name[$i]); @fopen($src, "r"); $dest = JPATH_COMPONENT_SITE . '/assets/download/product/' . trim($image_name[$i]); // Copy If file is not already exist if (!file_exists($dest)) { @copy($src, $dest); } } } } } $section_download_order = $rawdata['download_order']; $section_download_alternattext = $rawdata['download_alternattext']; $category_id = $rawdata['category_id']; // Insert into media $query = "SELECT count(*) FROM `" . $this->_table_prefix . "media` " . "WHERE `media_name` LIKE '" . $product_full_image . "' " . "AND `media_section` LIKE 'product' " . "AND `section_id`='" . $product_id . "' " . "AND `media_type` LIKE 'images' " . "AND `published`=1 "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $rows = $this->getTable('media_detail'); $rows->media_id = 0; $rows->media_name = $product_full_image; $rows->media_section = 'product'; $rows->section_id = $product_id; $rows->media_type = 'images'; $rows->media_mimetype = ''; $rows->published = 1; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); } } // Product Extra Field Import $newkeys = array(); array_walk($rawdata, 'checkkeys', $newkeys); if (count($newkeys) > 0) { foreach ($newkeys as $fieldkey) { $this->importProductExtrafieldData($fieldkey, $rawdata, $product_id); } } $correctlines++; } // Category product relation insert $category_id = ''; $category_name = ''; if (isset($rawdata['category_id'])) { $category_id = $rawdata['category_id']; } if (isset($rawdata['category_name'])) { $category_name = $rawdata['category_name']; } if ($category_id != "" || $category_name != "") { $category = false; if ($category_id != "") { $categoryArr = explode("###", $rawdata['category_id']); } else { $categoryArr = explode("###", $rawdata['category_name']); $category = true; } // Remove all current product category $query = "DELETE FROM `" . $this->_table_prefix . "product_category_xref` WHERE `product_id` = " . $product_id; $this->_db->setQuery($query); $this->_db->Query(); for ($i = 0; $i < count($categoryArr); $i++) { if ($category) { $query = "SELECT category_id FROM `" . $this->_table_prefix . "category` " . "WHERE `category_name` = '" . $categoryArr[$i] . "' "; $this->_db->setQuery($query); $category_id = $this->_db->loadResult(); } else { $category_id = $categoryArr[$i]; } $query = "SELECT COUNT(*) FROM " . $this->_table_prefix . "product_category_xref " . "WHERE category_id = '" . $category_id . "' " . "AND product_id = '" . $product_id . "' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "product_category_xref` " . "(`category_id`, `product_id`) " . "VALUES ('" . $category_id . "', '" . $product_id . "')"; $this->_db->setQuery($query); $this->_db->Query(); } } } // Importing accessory product $accessory_products = $rawdata['accessory_products']; if ($accessory_products != "") { $accessory_products = explode("###", $rawdata['accessory_products']); for ($i = 0; $i < count($accessory_products); $i++) { $accids = explode("~", $accessory_products[$i]); $accessory_product_sku = $accids[0]; $accessory_price = $accids[1]; $query = 'SELECT COUNT(*) AS total FROM `' . $this->_table_prefix . 'product_accessory` AS pa ' . 'LEFT JOIN ' . $this->_table_prefix . 'product p ON p.product_id = pa.child_product_id ' . 'WHERE pa.`product_id`="' . $product_id . '" ' . 'AND p.product_number="' . $accessory_product_sku . '" '; $this->_db->setQuery($query); $total = $this->_db->loadresult(); $query = "SELECT product_id FROM `" . $this->_table_prefix . "product` WHERE `product_number`='" . $accessory_product_sku . "' "; $this->_db->setQuery($query); $child_product_id = $this->_db->loadresult(); if ($total <= 0) { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "product_accessory` " . "(`accessory_id`, `product_id`, `child_product_id`, `accessory_price`) " . "VALUES ('', '" . $product_id . "', '" . $child_product_id . "', '" . $accessory_price . "')"; } else { $query = "UPDATE `" . $this->_table_prefix . "product_accessory` " . "SET `accessory_price`='" . $accessory_price . "' " . "WHERE `product_id`='" . $product_id . "' " . "AND `child_product_id`='" . $child_product_id . "'"; } $this->_db->setQuery($query); $this->_db->Query(); } } $product_stock = $rawdata['product_stock']; $query = "SELECT COUNT(*) AS total FROM `" . $this->_table_prefix . "product_stockroom_xref` " . "WHERE `product_id`='" . $product_id . "' " . "AND `stockroom_id`='" . DEFAULT_STOCKROOM . "'"; $this->_db->setQuery($query); $total = $this->_db->loadresult(); if ($product_stock && DEFAULT_STOCKROOM != 0) { if ($total <= 0) { $query = "INSERT INTO `" . $this->_table_prefix . "product_stockroom_xref` " . "(`product_id`, `stockroom_id`, `quantity`) " . "VALUES ('" . $product_id . "', '" . DEFAULT_STOCKROOM . "', '" . $product_stock . "') "; } else { $query = "UPDATE `" . $this->_table_prefix . "product_stockroom_xref` " . "SET `quantity`='" . $product_stock . "' " . "WHERE `product_id`='" . $product_id . "' " . "AND `stockroom_id`='" . DEFAULT_STOCKROOM . "'"; } $this->_db->setQuery($query); $this->_db->Query(); } // Import image section $section_images = explode("#", $section_images); $section_images_order = explode("#", $section_images_order); $section_images_alternattext = explode("#", $section_images_alternattext); if (is_array($section_images)) { for ($s = 0; $s < count($section_images); $s++) { if (trim($section_images[$s]) != "") { $ordering = 0; if (isset($section_images_order[$s])) { $ordering = $section_images_order[$s]; } $media_alternate_text = ""; if (isset($section_images_alternattext[$s])) { $media_alternate_text = $section_images_alternattext[$s]; } $query = "SELECT media_id FROM `" . $this->_table_prefix . "media` " . "WHERE `media_name` LIKE '" . $section_images[$s] . "' " . "AND `media_section`='product' " . "AND `section_id`='" . $product_id . "' " . "AND `media_type` LIKE 'images' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $rows = $this->getTable('media_detail'); $rows->media_id = 0; $rows->media_name = trim($section_images[$s]); $rows->media_section = 'product'; $rows->section_id = $product_id; $rows->media_type = 'images'; $rows->media_mimetype = ''; $rows->published = 1; $rows->media_alternate_text = $media_alternate_text; $rows->ordering = $ordering; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); } } else { $query = "UPDATE `" . $this->_table_prefix . "media` " . "SET `media_alternate_text` = '" . $media_alternate_text . "', " . "`ordering` = '" . $ordering . "' " . "WHERE `media_id`='" . $count . "' "; $this->_db->setQuery($query); $this->_db->Query(); } } } } // Import video section $section_video = explode("#", $section_video); $section_video_order = explode("#", $section_video_order); $section_video_alternattext = explode("#", $section_video_alternattext); if (is_array($section_video)) { for ($s = 0; $s < count($section_video); $s++) { if (trim($section_video[$s]) != "") { $ordering = 0; if (isset($section_video_order[$s])) { $ordering = $section_video_order[$s]; } $media_alternate_text = ""; if (isset($section_video_alternattext[$s])) { $media_alternate_text = $section_video_alternattext[$s]; } $query = "SELECT count(*) FROM `" . $this->_table_prefix . "media` " . "WHERE `media_name` LIKE '" . $section_video[$s] . "' " . "AND `media_section`='product' " . "AND `section_id` = '" . $product_id . "' " . "AND `media_type`='video' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $rows = $this->getTable('media_detail'); $rows->media_id = 0; $rows->media_name = trim($section_video[$s]); $rows->media_section = 'product'; $rows->section_id = $product_id; $rows->media_type = 'video'; $rows->media_mimetype = ''; $rows->published = 1; $rows->media_alternate_text = $media_alternate_text; $rows->ordering = $ordering; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); } } } } } // Import document section $section_document = explode("#", $section_document); $section_document_order = explode("#", $section_document_order); $section_document_alternattext = explode("#", $section_document_alternattext); if (is_array($section_document)) { for ($s = 0; $s < count($section_document); $s++) { if (trim($section_document[$s]) != "") { $ordering = 0; if (isset($section_document_order[$s])) { $ordering = $section_document_order[$s]; } $media_alternate_text = ""; if (isset($section_document_alternattext[$s])) { $media_alternate_text = $section_document_alternattext[$s]; } $query = "SELECT count(*) FROM `" . $this->_table_prefix . "media` " . "WHERE `media_name` LIKE '" . $section_document[$s] . "' " . "AND `media_section`='product' " . "AND `section_id` = '" . $product_id . "' " . "AND `media_type`='document' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $rows = $this->getTable('media_detail'); $rows->media_id = 0; $rows->media_name = trim($section_download[$s]); $rows->media_section = 'product'; $rows->section_id = $product_id; $rows->media_type = 'document'; $rows->media_mimetype = ''; $rows->published = 1; $rows->media_alternate_text = $media_alternate_text; $rows->ordering = $ordering; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); } } } } } // Import download section $section_download = explode("#", $section_download); $section_download_order = explode("#", $section_download_order); $section_download_alternattext = explode("#", $section_download_alternattext); if (is_array($section_download)) { for ($s = 0; $s < count($section_download); $s++) { if (trim($section_download[$s]) != "") { $ordering = 0; if (isset($section_download_order[$s])) { $ordering = $section_download_order[$s]; } $media_alternate_text = ""; if (isset($section_download_alternattext[$s])) { $media_alternate_text = $section_download_alternattext[$s]; } $query = "SELECT count(*) FROM `" . $this->_table_prefix . "media` " . "WHERE `media_name` LIKE '" . $section_download[$s] . "' " . "AND `media_section`='product' " . "AND `section_id`='" . $product_id . "' " . "AND `media_type`='download' "; $this->_db->setQuery($query); $count = $this->_db->loadResult(); if ($count <= 0) { $rows = $this->getTable('media_detail'); $rows->media_id = 0; $rows->media_name = trim($section_download[$s]); $rows->media_section = 'product'; $rows->section_id = $product_id; $rows->media_type = 'download'; $rows->media_mimetype = ''; $rows->published = 1; $rows->media_alternate_text = $media_alternate_text; $rows->ordering = $ordering; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); } } } } } } // Import Manufacturers if ($post['import'] == 'manufacturer') { $manufacturer_id = $rawdata['manufacturer_id']; $product_id = $rawdata['product_id']; $prd = explode('|', $product_id); $prd_final = implode(',', $prd); // Updating manufacturer $row = $this->getTable('manufacturer_detail'); $row->load($manufacturer_id); $row->manufacturer_name = $rawdata['manufacturer_name']; $row->manufacturer_desc = $rawdata['manufacturer_desc']; $row->manufacturer_email = $rawdata['manufacturer_email']; $row->product_per_page = $rawdata['product_per_page']; $row->template_id = $rawdata['template_id']; $row->metakey = $rawdata['metakey']; $row->metadesc = $rawdata['metadesc']; $row->metalanguage_setting = $rawdata['metalanguage_setting']; $row->metarobot_info = $rawdata['metarobot_info']; $row->pagetitle = $rawdata['pagetitle']; $row->pageheading = $rawdata['pageheading']; $row->sef_url = $rawdata['sef_url']; $row->published = $rawdata['published']; $row->ordering = $rawdata['ordering']; $row->manufacturer_url = $rawdata['manufacturer_url']; if (!$row->store()) { return JText::_('ERROR_DURING_IMPORT'); } else { $rows = $this->getTable('manufacturer_detail'); $rows->manufacturer_id = $manufacturer_id; $rows->manufacturer_name = $rawdata['manufacturer_name']; $rows->manufacturer_desc = $rawdata['manufacturer_desc']; $rows->manufacturer_email = $rawdata['manufacturer_email']; $rows->product_per_page = $rawdata['product_per_page']; $rows->template_id = $rawdata['template_id']; $rows->metakey = $rawdata['metakey']; $rows->metadesc = $rawdata['metadesc']; $rows->metalanguage_setting = $rawdata['metalanguage_setting']; $rows->metarobot_info = $rawdata['metarobot_info']; $rows->pagetitle = $rawdata['pagetitle']; $rows->pageheading = $rawdata['pageheading']; $rows->sef_url = $rawdata['sef_url']; $rows->published = $rawdata['published']; $rows->ordering = $rawdata['ordering']; $rows->manufacturer_url = $rawdata['manufacturer_url']; if (!$rows->store()) { $this->setError($this->_db->getErrorMsg()); return false; } $rows->set('manufacturer_id', $manufacturer_id); $ret = $this->_db->insertObject($this->_table_prefix . 'manufacturer', $rows, 'manufacturer_id'); } if (count($prd) > 0) { $query = "UPDATE `" . $this->_table_prefix . "product` " . "SET `manufacturer_id` = " . $manufacturer_id . " " . "WHERE `product_id` IN(" . $prd_final . ") "; $this->_db->setQuery($query); $this->_db->Query(); } $correctlines++; } // Import attributes if ($post['import'] == 'attributes') { $product_id = $this->getProductIdByNumber($rawdata['product_number']); // Insert product attributes $attribute_id = ""; $attribute_name = $rawdata['attribute_name']; $attribute_ordering = $rawdata['attribute_ordering']; $allow_multiple_selection = $rawdata['allow_multiple_selection']; $hide_attribute_price = $rawdata['hide_attribute_price']; $attribute_display_type = $rawdata['display_type']; $attribute_required = $rawdata['attribute_required']; $query = "SELECT `attribute_id` FROM `" . $this->_table_prefix . "product_attribute` WHERE `product_id` = " . $product_id . " AND `attribute_name` = '" . $attribute_name . "'"; $this->_db->setQuery($query); $attribute_id = $this->_db->loadResult(); // Get table Instance $attrow = $this->getTable('product_attribute'); $attrow->load($attribute_id); $attrow->attribute_name = $attribute_name; if ($attribute_ordering != '') { $attrow->ordering = $attribute_ordering; } if ($allow_multiple_selection != '') { $attrow->allow_multiple_selection = $allow_multiple_selection; } if ($hide_attribute_price != '') { $attrow->hide_attribute_price = $hide_attribute_price; } if ($attribute_required != '') { $attrow->attribute_required = $attribute_required; } if ($attribute_display_type != '') { $attrow->display_type = $attribute_display_type; } $attrow->product_id = $product_id; if ($attrow->store()) { $att_insert_id = $attrow->attribute_id; // Insert product attributes property $property_id = 0; $property_name = $rawdata['property_name']; if ($property_name != "") { $property_ordering = $rawdata['property_ordering']; $property_price = $rawdata['property_price']; $property_number = $rawdata['property_virtual_number']; $setdefault_selected = $rawdata['setdefault_selected']; $setdisplay_type = $rawdata['setdisplay_type']; $setrequire_selected = $rawdata['required_sub_attribute']; $oprand = $rawdata['oprand']; $property_image = @basename($rawdata['property_image']); $property_main_image = @basename($rawdata['property_main_image']); $query = "SELECT `property_id` FROM `" . $this->_table_prefix . "product_attribute_property` WHERE `attribute_id` = " . $att_insert_id . " AND `property_name` = '" . $property_name . "'"; $this->_db->setQuery($query); $property_id = $this->_db->loadResult(); // Get Table Instance $proprow = $this->getTable('attribute_property'); $proprow->load($property_id); $proprow->attribute_id = $att_insert_id; $proprow->property_name = $property_name; if ($property_price != "") { $proprow->property_price = $property_price; } if ($property_ordering != "") { $proprow->ordering = $property_ordering; } if ($property_number != "") { $proprow->property_number = $property_number; } if ($setdefault_selected != "") { $proprow->setdefault_selected = $setdefault_selected; } if ($setrequire_selected != "") { $proprow->setrequire_selected = $setrequire_selected; } if ($setdisplay_type != "") { $proprow->setdisplay_type = $setdisplay_type; } if ($oprand == '+' || $oprand == '-' || $oprand == '*' || $oprand == '/' || $oprand == '=') { $proprow->oprand = $oprand; } if ($property_image) { $proprow->property_image = $property_image; } if ($property_main_image) { $proprow->property_main_image = $property_main_image; } if ($proprow->store()) { $prop_insert_id = $proprow->property_id; $mainstock = $rawdata['property_stock']; if ($mainstock != "") { $mainstock_split = explode("#", $mainstock); for ($r = 0; $r < count($mainstock_split); $r++) { if ($mainstock_split[$r] != "") { $mainquaexplode = explode(":", $mainstock_split[$r]); if (count($mainquaexplode) == 2) { $query_mainins_stockroom = "SELECT * FROM `" . $this->_table_prefix . "stockroom` WHERE `stockroom_id` = '" . $mainquaexplode[0] . "'"; $this->_db->setQuery($query_mainins_stockroom); $stock_id = $this->_db->loadObjectList(); if (count($stock_id) > 0) { $query_mainins = "SELECT * FROM `" . $this->_table_prefix . "product_attribute_stockroom_xref` WHERE `stockroom_id` = '" . $mainquaexplode[0] . "' and section='property' and section_id='" . $prop_insert_id . "'"; $this->_db->setQuery($query_mainins); $product_id = $this->_db->loadObjectList(); if (count($product_id) > 0) { $update_row_query = "update `" . $this->_table_prefix . "product_attribute_stockroom_xref` set quantity='" . $mainquaexplode[1] . "' where `stockroom_id` = '" . $mainquaexplode[0] . "' and section='property' and section_id='" . $prop_insert_id . "'"; $this->_db->setQuery($update_row_query); $this->_db->Query(); } else { $insert_row_query = "insert into `" . $this->_table_prefix . "product_attribute_stockroom_xref` set quantity='" . $mainquaexplode[1] . "',`stockroom_id` = '" . $mainquaexplode[0] . "',section='property',section_id='" . $prop_insert_id . "'"; $this->_db->setQuery($insert_row_query); $this->_db->Query(); } } } } } } /** * update property stock placement */ if ($isredcrm && isset($rawdata['property_stock_placement']) && trim($rawdata['property_stock_placement']) != "") { $property_save = array(); $property_save['stockposition'] = $rawdata['property_stock_placement']; $property_save['product_id'] = $attrow->product_id; $property_save['property_id'] = $prop_insert_id; $this->storePropertyStockPosition($property_save); unset($property_save); } if ($property_image != "") { $property_image_path = $rawdata['property_image']; @fopen($property_image_path, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'product_attributes/' . $property_image; // Copy If file is not already exist if (!file_exists($dest)) { @copy($property_image_path, $dest); } } if ($property_main_image != "") { $property_image_path = $rawdata['property_main_image']; @fopen($property_image_path, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'property/' . $property_main_image; // Copy If file is not already exist if (!file_exists($dest)) { @copy($property_image_path, $dest); } } // Redshop product attribute subproperty $subattribute_color_id = ""; $subattribute_color_name = $rawdata['subattribute_color_name']; if ($subattribute_color_name != "") { $subattribute_color_ordering = $rawdata['subattribute_color_ordering']; $subattribute_setdefault_selected = $rawdata['subattribute_setdefault_selected']; $subattribute_color_title = $rawdata['subattribute_color_title']; $subattribute_color_number = $rawdata['subattribute_virtual_number']; $subattribute_color_price = $rawdata['subattribute_color_price']; $oprand = $rawdata['subattribute_color_oprand']; $subattribute_color_image = @basename($rawdata['subattribute_color_image']); $query = "SELECT `subattribute_color_id` FROM `" . $this->_table_prefix . "product_subattribute_color` WHERE `subattribute_id` = " . $prop_insert_id . " AND `subattribute_color_name` = '" . $subattribute_color_name . "'"; $this->_db->setQuery($query); $subattribute_color_id = $this->_db->loadResult(); // Get Table Instance $subproprow = $this->getTable('subattribute_property'); $subproprow->load($subattribute_color_id); $subproprow->subattribute_color_name = $subattribute_color_name; if ($subattribute_color_price != "") { $subproprow->subattribute_color_price = $subattribute_color_price; } if ($subattribute_color_ordering != "") { $subproprow->ordering = $subattribute_color_ordering; } if ($subattribute_setdefault_selected != "") { $subproprow->setdefault_selected = $subattribute_setdefault_selected; } if ($subattribute_color_title != "") { $subproprow->subattribute_color_title = $subattribute_color_title; } if ($subattribute_color_number != "") { $subproprow->subattribute_color_number = $subattribute_color_number; } if ($oprand == '+' || $oprand == '-' || $oprand == '*' || $oprand == '/' || $oprand == '=') { $subproprow->oprand = $oprand; } if ($subattribute_color_image) { $subproprow->subattribute_color_image = $subattribute_color_image; } $subproprow->subattribute_id = $prop_insert_id; $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "product_subattribute_color` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_color_id` ,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_color_name` ,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_color_price` ,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`oprand` ,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_color_image` ,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_id`,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`ordering`,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`setdefault_selected`,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`subattribute_color_title`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $subattribute_color_id . "', '" . $subattribute_color_name . "', '" . $subattribute_color_price . "', '" . $oprand . "', '" . $subattribute_color_image . "', '" . $prop_insert_id . "', '" . $subattribute_color_ordering . "', '" . $subattribute_setdefault_selected . "', '" . $subattribute_color_title . "'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)"; if ($subproprow->store()) { $prop_insert_id_sub = $subproprow->subattribute_color_id; $mainstock = $rawdata['subattribute_stock']; if ($mainstock != "") { $mainstock_split = explode("#", $mainstock); for ($r = 0; $r < count($mainstock_split); $r++) { if ($mainstock_split[$r] != "") { $mainquaexplode = explode(":", $mainstock_split[$r]); if (count($mainquaexplode) == 2) { $query_mainins_stockroom = "SELECT * FROM `" . $this->_table_prefix . "stockroom` WHERE `stockroom_id` = '" . $mainquaexplode[0] . "'"; $this->_db->setQuery($query_mainins_stockroom); $stock_id = $this->_db->loadObjectList(); if (count($stock_id) > 0) { $query_mainins = "SELECT * FROM `" . $this->_table_prefix . "product_attribute_stockroom_xref` WHERE `stockroom_id` = '" . $mainquaexplode[0] . "' and section='subproperty' and section_id='" . $prop_insert_id_sub . "'"; $this->_db->setQuery($query_mainins); $product_id = $this->_db->loadObjectList(); if (count($product_id) > 0) { $update_row_query = "update `" . $this->_table_prefix . "product_attribute_stockroom_xref` set quantity='" . $mainquaexplode[1] . "' where `stockroom_id` = '" . $mainquaexplode[0] . "' and section='subproperty' and section_id='" . $prop_insert_id_sub . "'"; $this->_db->setQuery($update_row_query); $this->_db->Query(); } else { $insert_row_query = "insert into `" . $this->_table_prefix . "product_attribute_stockroom_xref` set quantity='" . $mainquaexplode[1] . "',`stockroom_id` = '" . $mainquaexplode[0] . "',section='subproperty',section_id='" . $prop_insert_id_sub . "'"; $this->_db->setQuery($insert_row_query); $this->_db->Query(); } } } } } } /** * update property stock placement */ if ($isredcrm && isset($rawdata['subattribute_stock_placement']) && trim($rawdata['subattribute_stock_placement']) != "") { $subproperty_save = array(); $subproperty_save['stockposition'] = $rawdata['subattribute_stock_placement']; $subproperty_save['product_id'] = $attrow->product_id; $subproperty_save['subattribute_color_id'] = $prop_insert_id_sub; $this->storePropertyStockPosition($subproperty_save, 'subproperty'); unset($subproperty_save); } if ($subattribute_color_image != "") { $subproperty_image_path = $rawdata['subattribute_color_image']; @fopen($subproperty_image_path, "r"); $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'subcolor/' . $subattribute_color_image; // Copy If file is not already exist if (!file_exists($dest)) { @copy($subproperty_image_path, $dest); } } } } } } $correctlines++; } } // Import fields if ($post['import'] == 'fields') { $field_id = $rawdata['field_id']; $field_title = $rawdata['field_title']; $field_name_field = $rawdata['field_name_field']; $field_type = $rawdata['field_type']; $field_desc = $rawdata['field_desc']; $field_class = $rawdata['field_class']; $field_section = $rawdata['field_section']; $field_maxlength = $rawdata['field_maxlength']; $field_cols = $rawdata['field_cols']; $field_rows = $rawdata['field_rows']; $field_size = $rawdata['field_size']; $field_show_in_front = $rawdata['field_show_in_front']; $required = $rawdata['required']; $published = $rawdata['published']; $data_id = $rawdata['data_id']; $data_txt = $rawdata['data_txt']; $itemid = $rawdata['itemid']; $section = $rawdata['section']; $data_insert_id = 0; if ($section == 1) { $itemid = $this->getProductIdByNumber($rawdata['data_number']); } $value_id = $rawdata['value_id']; $field_value = $rawdata['field_value']; $field_name_value = $rawdata['field_name']; // Get field id $query = $this->_db->getQuery(true)->select('field_id')->from($this->_db->quoteName('#__redshop_fields'))->where($this->_db->quoteName('field_id') . ' = ' . $this->_db->quote($field_id)); $this->_db->setQuery($query); $field_id_dv = $this->_db->loadResult(); $field_title = $rawdata['field_title']; $field_name = $rawdata['field_name_field']; // Get Data Id $query = $this->_db->getQuery(true)->select('data_id')->from($this->_db->quoteName('#__redshop_fields_data'))->where($this->_db->quoteName('fieldid') . ' = ' . $this->_db->quote($field_id))->where($this->_db->quoteName('itemid') . ' = ' . $this->_db->quote($itemid)); $this->_db->setQuery($query); $ch_data_id = $this->_db->loadResult(); // Get Value Id $query = $this->_db->getQuery(true)->select('value_id')->from($this->_db->quoteName('#__redshop_fields_value'))->where($this->_db->quoteName('field_id') . ' = ' . $this->_db->quote($field_id))->where($this->_db->quoteName('value_id') . ' = ' . $this->_db->quote($value_id)); $this->_db->setQuery($query); $ch_value_id = $this->_db->loadResult(); if ($field_title != "" && $field_id_dv == '') { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "fields` (\r\n\t\t\t\t\t\t\t\t`field_title` ,\r\n\t\t\t\t\t\t\t\t`field_name` ,\r\n\t\t\t\t\t\t\t\t`field_type`,\r\n\t\t\t\t\t\t\t\t`field_desc`,\r\n\t\t\t\t\t\t\t\t`field_class`,\r\n\t\t\t\t\t\t\t\t`field_section`,\r\n\t\t\t\t\t\t\t\t`field_maxlength`,\r\n\t\t\t\t\t\t\t\t`field_cols`,\r\n\t\t\t\t\t\t\t\t`field_rows`,\r\n\t\t\t\t\t\t\t\t`field_size`,\r\n\t\t\t\t\t\t\t\t`field_show_in_front`,\r\n\t\t\t\t\t\t\t\t`required`,\r\n\t\t\t\t\t\t\t\t`published`\r\n\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\tVALUES (\r\n\t\t\t\t\t\t\t\t'" . $field_title . "',\r\n\t\t\t\t\t\t\t\t'" . $field_name . "',\r\n\t\t\t\t\t\t\t\t'" . $field_type . "',\r\n\t\t\t\t\t\t\t\t'" . $field_desc . "',\r\n\t\t\t\t\t\t\t\t'" . $field_class . "',\r\n\t\t\t\t\t\t\t\t'" . $field_section . "',\r\n\t\t\t\t\t\t\t\t'" . $field_maxlength . "',\r\n\t\t\t\t\t\t\t\t'" . $field_cols . "',\r\n\t\t\t\t\t\t\t\t'" . $field_rows . "',\r\n\t\t\t\t\t\t\t\t'" . $field_size . "',\r\n\t\t\t\t\t\t\t\t'" . $field_show_in_front . "',\r\n\t\t\t\t\t\t\t\t'" . $required . "',\r\n\t\t\t\t\t\t\t\t'" . $published . "'\r\n\t\t\t\t\t\t\t\t)"; $this->_db->setQuery($query); $this->_db->Query(); $data_insert_id = $this->_db->insertid(); } if ($data_insert_id == 0) { $new_field_id = $field_id; } else { $new_field_id = $data_insert_id; } if (!$ch_data_id) { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "fields_data` " . "(`data_id`,`fieldid` ,`data_txt` ,`itemid`,`section`) " . "VALUES ('','" . $new_field_id . "','" . $data_txt . "','" . $itemid . "','" . $section . "')"; $this->_db->setQuery($query); $this->_db->Query(); } else { $query = "UPDATE `" . $this->_table_prefix . "fields_data` " . "SET `fieldid` = '" . $field_id . "', " . "`data_txt` = '" . $data_txt . "', " . "`itemid` = '" . $itemid . "', " . "`section` = '" . $section . "' " . "WHERE `data_id` = '" . $ch_data_id . "' "; $this->_db->setQuery($query); $this->_db->Query(); } if ($value_id != '') { if (!$ch_value_id) { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "fields_value` " . "(`value_id`, `field_id`, `field_value`, `field_name`) " . "VALUES ('" . $value_id . "','" . $new_field_id . "','" . $field_value . "','" . $field_name_value . "')"; $this->_db->setQuery($query); $this->_db->Query(); } else { $query = "UPDATE `" . $this->_table_prefix . "fields_value` " . "SET `field_value` = '" . $field_value . "', " . "`field_name` = '" . $field_name_value . "' " . "WHERE `value_id` = '" . $value_id . "' "; $this->_db->setQuery($query); $this->_db->Query(); } } $correctlines++; } // Import fields if ($post['import'] == 'fields_data') { $field_id = $rawdata['field_id']; $field_product_number = $rawdata['data_number']; $field_data_txt = $rawdata['data_txt']; if ($field_product_number && $field_id) { $product_id = $this->getProductIdByNumber($field_product_number); if ($product_id) { $q = "SELECT count(fieldid) as fieldexist FROM `" . $this->_table_prefix . "fields_data` " . "WHERE `fieldid` = '" . $field_id . "' " . "AND itemid ='" . $product_id . "' " . "AND section ='1' "; $this->_db->setQuery($q); $fieldexist = $this->_db->loadResult(); if ($fieldexist == 0) { $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "fields_data` " . "(`fieldid`, `data_txt`, `itemid`, `section` ) " . "VALUES ('" . $field_id . "', '" . $field_data_txt . "', '" . $product_id . "', '1') "; $this->_db->setQuery($query); $this->_db->Query(); } else { $query = "UPDATE `" . $this->_table_prefix . "fields_data` SET\r\n\t\t\t\t\t\t\t\t\t\t\t`data_txt` = '" . $field_data_txt . "'\r\n\t\t\t\t\t\t\t\t\t\t\t WHERE `fieldid` = '" . $field_id . "'\r\n\t\t AND itemid ='" . $product_id . "'\r\n\t\t AND \tsection ='1' "; $this->_db->setQuery($query); $this->_db->Query(); } $correctlines++; } } } // Import Related Products if ($post['import'] == 'related_product') { $relpid = $this->getProductIdByNumber($rawdata['related_sku']); $pid = $this->getProductIdByNumber($rawdata['product_sku']); $query = "INSERT IGNORE INTO `" . $this->_table_prefix . "product_related` (`related_id`, `product_id`) VALUES ('" . $relpid . "', '" . $pid . "')"; $this->_db->setQuery($query); if ($this->_db->Query()) { $correctlines++; } } // Import users if ($post['import'] == 'users') { $app = JFactory::getApplication(); $q = "SELECT * FROM `" . $this->_table_prefix . "shopper_group` " . "WHERE `shopper_group_name` = '" . $rawdata['shopper_group_name'] . "'"; $this->_db->setQuery($q); $shopper_group_data = $this->_db->loadObject(); // Insert shopper group if not available if (count($shopper_group_data) <= 0) { $shopper = $this->getTable('shopper_group_detail'); $shopper->load(); $shopper->shopper_group_name = $rawdata['shopper_group_name']; $shopper->shopper_group_customer_type = 1; $shopper->shopper_group_portal = 0; $shopper->store(); // Get last shopper group id $shopper_group_id = $shopper->shopper_group_id; } else { // Get shopper group id $shopper_group_id = $shopper_group_data->shopper_group_id; } // Get redshop user info table $reduser = $this->getTable('user_detail'); // Check for user available if ($rawdata['id'] > 0) { $q = "SELECT * FROM `#__users` " . "WHERE `email` = '" . trim($rawdata['email']) . "' "; $this->_db->setQuery($q); $joomusers = $this->_db->loadObject(); if (count($joomusers) == 0) { $user_id = 0; } else { $user_id = $joomusers->id; } // Initialize some variables $db = JFactory::getDbo(); $me = JFactory::getUser(); $acl = JFactory::getACL(); $MailFrom = $app->getCfg('mailfrom'); $FromName = $app->getCfg('fromname'); $SiteName = $app->getCfg('sitename'); // Create a new JUser object $user = new JUser($user_id); $user->set('username', trim($rawdata['username'])); $user->set('name', $rawdata['name']); $user->set('email', trim($rawdata['email'])); $user->set('password', $rawdata['password']); $user->set('password_clear', $rawdata['password']); $user->set('block', $rawdata['block']); $user->set('sendEmail', $rawdata['sendEmail']); // Set some initial user values $user->set('usertype', $rawdata['usertype']); $user->set('gid', $rawdata['gid']); $date = JFactory::getDate(); $user->set('registerDate', $date->toMySQL()); if ($user->save()) { $reduser->set('user_id', $user->id); $reduser->set('user_email', trim($rawdata['email'])); $reduser->set('firstname', $rawdata['firstname']); $reduser->set('address_type', 'BT'); $reduser->set('lastname', $rawdata['lastname']); $reduser->set('company_name', $rawdata['company_name']); $reduser->set('vat_number', $rawdata['vat_number']); $reduser->set('tax_exempt', $rawdata['tax_exempt']); $reduser->set('shopper_group_id', $shopper_group_id); $reduser->set('is_company', $rawdata['is_company']); $reduser->set('address', $rawdata['address']); $reduser->set('city', $rawdata['city']); $reduser->set('country_code', $rawdata['country_code']); $reduser->set('state_code', $rawdata['state_code']); $reduser->set('zipcode', $rawdata['zipcode']); $reduser->set('phone', $rawdata['phone']); $reduser->set('tax_exempt_approved', $rawdata['tax_exempt_approved']); $reduser->set('approved', $rawdata['approved']); if (count($joomusers) == 0) { $reduser->set('users_info_id', $rawdata['users_info_id']); $ret = $this->_db->insertObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); } else { $user_id = $joomusers->id; $q = "SELECT * FROM `" . $this->_table_prefix . "users_info` " . "WHERE `user_id` = '" . $user_id . "'"; $this->_db->setQuery($q); $redusers = $this->_db->loadObject(); if (count($redusers) > 0) { $reduser->set('users_info_id', $redusers->users_info_id); $ret = $this->_db->updateObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); } else { $reduser->set('users_info_id', $rawdata['users_info_id']); $ret = $this->_db->insertObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); } } if ($ret) { $correctlines++; } } } else { $q = "SELECT * FROM `" . $this->_table_prefix . "users_info` " . "WHERE `user_email` = '" . $rawdata['email'] . "' "; $this->_db->setQuery($q); $redusers = $this->_db->loadObject(); $reduser->set('user_id', $rawdata['id']); $reduser->set('user_email', trim($rawdata['email'])); $reduser->set('firstname', $rawdata['firstname']); $reduser->set('address_type', 'BT'); $reduser->set('lastname', $rawdata['lastname']); $reduser->set('company_name', $rawdata['company_name']); $reduser->set('vat_number', $rawdata['vat_number']); $reduser->set('tax_exempt', $rawdata['tax_exempt']); $reduser->set('shopper_group_id', $shopper_group_id); $reduser->set('is_company', $rawdata['is_company']); $reduser->set('address', $rawdata['address']); $reduser->set('city', $rawdata['city']); $reduser->set('country_code', $rawdata['country_code']); $reduser->set('state_code', $rawdata['state_code']); $reduser->set('zipcode', $rawdata['zipcode']); $reduser->set('phone', $rawdata['phone']); $reduser->set('tax_exempt_approved', $rawdata['tax_exempt_approved']); $reduser->set('approved', $rawdata['approved']); if (count($redusers) > 0) { $reduser->set('users_info_id', $redusers->users_info_id); $ret = $this->_db->updateObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); } else { $reduser->set('users_info_id', $rawdata['users_info_id']); $ret = $this->_db->insertObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); } if ($ret) { $correctlines++; } } } // Shipping Address Import if ($post['import'] == 'shipping_address') { if (trim($rawdata['username']) != "") { $q = "SELECT id FROM `#__users` " . "WHERE `username` = '" . trim($rawdata['username']) . "' "; $this->_db->setQuery($q); $joom_user_id = $this->_db->loadResult(); if ($joom_user_id > 0) { $reduser = $this->getTable('user_detail'); $reduser->set('user_id', $joom_user_id); $reduser->set('user_email', trim($rawdata['email'])); $reduser->set('firstname', $rawdata['firstname']); $reduser->set('address_type', 'ST'); $reduser->set('lastname', $rawdata['lastname']); $reduser->set('company_name', $rawdata['company_name']); $reduser->set('address', $rawdata['address']); $reduser->set('city', $rawdata['city']); $reduser->set('country_code', $rawdata['country_code']); $reduser->set('state_code', $rawdata['state_code']); $reduser->set('zipcode', $rawdata['zipcode']); $reduser->set('phone', $rawdata['phone']); $reduser->set('users_info_id', 0); $ret = $this->_db->insertObject($this->_table_prefix . 'users_info', $reduser, 'users_info_id'); if ($ret) { $correctlines++; } } } } // Shopper group Import if ($post['import'] == 'shopper_group_price') { $ret = $this->importShopperGroupPrice($rawdata); if ($ret) { $correctlines++; } } // Import stockroom data if ($post['import'] == 'product_stockroom_data') { $product_number = $rawdata['Product_SKU']; $product_stock = $rawdata['stock']; $preorder_stock = 0; $ordered_preorder = 0; $stockroom_id = $rawdata['stockroom_id']; if ($product_number) { $product_id = $this->getProductIdByNumber($product_number); if ($product_id) { echo $q = "SELECT product_id FROM `" . $this->_table_prefix . "product_stockroom_xref` where product_id ='" . $product_id . "' and stockroom_id ='" . $stockroom_id . "'"; $this->_db->setQuery($q); $stock_exists = $this->_db->loadResult(); if ($stock_exists == 0) { $query = 'INSERT INTO ' . $this->_table_prefix . 'product_stockroom_xref ' . '(product_id,stockroom_id,quantity,preorder_stock, ordered_preorder) ' . 'VALUE("' . $product_id . '","' . $stockroom_id . '","' . $product_stock . '","' . $preorder_stock . '","' . $ordered_preorder . '")'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } else { $query = "UPDATE `" . $this->_table_prefix . "product_stockroom_xref` SET\r\n\t\t\t\t\t\t\t\t\t\t\t`quantity` = '" . $product_stock . "'\r\n\t\t\t\t\t\t\t\t\t\t\t WHERE `product_id` = '" . $product_id . "' and stockroom_id = '" . $stockroom_id . "'"; $this->_db->setQuery($query); $this->_db->Query(); } $correctlines++; } } } // Import Economic group Products if ($post['import'] == 'economic_group_product') { $product_number = $rawdata['product_number']; $product_group = $rawdata['product_group']; if ($product_group == "") { $product_group = 1; } if ($product_number) { $product_id = $this->getProductIdByNumber($product_number); if ($product_id) { $query = "UPDATE `" . $this->_table_prefix . "product` SET\r\n\t\t\t\t\t\t\t\t\t\t\t`accountgroup_id` = '" . $product_group . "'\r\n\t\t\t\t\t\t\t\t\t\t\t WHERE `product_id` = '" . $product_id . "'"; $this->_db->setQuery($query); $this->_db->Query(); $correctlines++; } } } } } $line++; } else { $blank = ""; $text = "" . $line . "`_`" . $blank . ""; ob_clean(); echo $text; exit; } } fclose($handle); $blank = ""; $text = "`_`" . $line . "`_`" . $line . ""; ob_clean(); echo $text; exit; }
public function getOrderShippingUserInfo($order_id) { $helper = new redhelper(); if ($helper->isredCRM()) { $order = $this->getOrderDetails($order_id); $crmDebitorHelper = new crmDebitorHelper(); /* * get shippinginfo for redCRM */ $crmusers = $crmDebitorHelper->getShippingInfo(0, $order->user_info_id); if (count($crmusers) > 0) { $crmusers = $crmusers[0]; return $crmusers; } } $query = 'SELECT * FROM ' . $this->_table_prefix . 'order_users_info ' . 'WHERE address_type LIKE "ST" ' . 'AND order_id = ' . (int) $order_id; $this->_db->setQuery($query); $list = $this->_db->loadObject(); return $list; }
function getPreorderStockAmountwithReserve($section_id = 0, $section = "product", $stockroom_id = 0) { $quantity = 1; if (USE_STOCKROOM == 1) { $and = ""; $table = "product"; $db = JFactory::getDbo(); if ($section != "product") { $table = "product_attribute"; } if ($section_id != 0) { // Sanitize ids $section_id = explode(',', $section_id); JArrayHelper::toInteger($section_id); if ($section != "product") { $and = "AND x.section = " . $db->quote($section) . " AND x.section_id IN (" . implode(',', $section_id) . ") "; } else { $and = "AND x.product_id IN (" . implode(',', $section_id) . ") "; } } if ($stockroom_id != 0) { $and .= "AND x.stockroom_id = " . (int) $stockroom_id . " "; } $query = "SELECT SUM(x.preorder_stock) as preorder_stock, SUM(x.ordered_preorder) as ordered_preorder FROM " . $this->_table_prefix . $table . "_stockroom_xref AS x " . ", " . $this->_table_prefix . "stockroom AS s " . "WHERE s.stockroom_id=x.stockroom_id " . "AND x.quantity>=0 " . $and . "ORDER BY s.min_del_time "; $db->setQuery($query); $pre_order_stock = $db->loadObjectList(); if ($pre_order_stock[0]->ordered_preorder == $pre_order_stock[0]->preorder_stock || $pre_order_stock[0]->ordered_preorder > $pre_order_stock[0]->preorder_stock) { $quantity = 0; } else { $quantity = $pre_order_stock[0]->preorder_stock - $pre_order_stock[0]->ordered_preorder; } } else { $helper = new redhelper(); if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM && !ENABLE_ONE_STOCKROOM_MANAGEMENT) { // Include redSHOP product helper $producthelper = new producthelper(); // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $getstockdata = new stdClass(); $getstockdata->property_id = 0; $getstockdata->subproperty_id = 0; if ($section == "product") { $getstockdata->product_id = $section_id; } elseif ($section == "property") { $property = $producthelper->getAttibuteProperty($section_id); $attribute_id = $property[0]->attribute_id; $attribute = $producthelper->getProductAttribute(0, 0, $attribute_id); $product_id = $attribute[0]->product_id; $getstockdata->product_id = $product_id; $getstockdata->property_id = $section_id; } elseif ($section == "subproperty") { $subproperty = $producthelper->getAttibuteSubProperty($section_id); $property_id = $subproperty[0]->subattribute_id; $property = $producthelper->getAttibuteProperty($property_id); $attribute_id = $property[0]->attribute_id; $attribute = $producthelper->getProductAttribute(0, 0, $attribute_id); $product_id = $attribute[0]->product_id; $getstockdata->product_id = $product_id; $getstockdata->property_id = $property_id; $getstockdata->subproperty_id = $section_id; } $quantity = $crmSupplierOrderHelper->getSupplierStock($getstockdata); } } } return $quantity; }