/** * Check for the product ID */ public function check() { $producthelper = new producthelper(); $unit = $producthelper->getUnitConversation("m", $discount_calc_unit[$c]); $converted_area_start = $this->area_start * $unit * $unit; $converted_area_end = $this->area_end * $unit * $unit; $query = "SELECT *\n\t\t\t\t\tFROM `" . $this->_table_prefix . "product_discount_calc`\n\t\t\t\t\tWHERE product_id = " . (int) $this->product_id . " AND (" . (int) $converted_area_start . "\n\t\t\t\t\tBETWEEN `area_start_converted`\n\t\t\t\t\tAND `area_end_converted` || " . (int) $converted_area_end . "\n\t\t\t\t\tBETWEEN `area_start_converted`\n\t\t\t\t\tAND `area_end_converted` )"; $this->_db->setQuery($query); $xid = intval($this->_db->loadResult()); if ($xid) { $this->_error = JText::_('COM_REDSHOP_SAME_RANGE'); return false; } return true; }
/** * Function copyDiscountCalcdata. * * @param int $old_product_id old_product_id * @param int $new_product_id new_product_id * @param string $discount_calc_method discount_calc_method * * @return bool */ public function copyDiscountCalcdata($old_product_id, $new_product_id, $discount_calc_method) { $producthelper = new producthelper(); $query = "SELECT * FROM `" . $this->table_prefix . "product_discount_calc`\r\n\t\t\t\t WHERE product_id='" . $old_product_id . "' "; $this->_db->setQuery($query); $list = $this->_db->loadObjectList(); for ($i = 0; $i < count($list); $i++) { $discount_calc_unit = $list[$i]->discount_calc_unit; $area_start = $list[$i]->area_start; $area_end = $list[$i]->area_end; $area_price = $list[$i]->area_price; $unit = $producthelper->getUnitConversation("m", $discount_calc_unit); // Replace comma with dot. $new_area_start = str_replace(",", ".", $area_start); $new_area_end = str_replace(",", ".", $area_end); if ($discount_calc_method == 'volume') { $calcunit = pow($unit, 3); } elseif ($discount_calc_method == 'area') { $calcunit = pow($unit, 2); } else { $calcunit = $unit; } // Updating value. $converted_area_start = $new_area_start * $calcunit; $converted_area_end = $new_area_end * $calcunit; // End $calcrow =& $this->getTable('product_discount_calc'); $calcrow->load(); $calcrow->discount_calc_unit = $discount_calc_unit; $calcrow->area_start = $new_area_start; $calcrow->area_end = $new_area_end; $calcrow->area_price = $area_price; $calcrow->area_start_converted = $converted_area_start; $calcrow->area_end_converted = $converted_area_end; $calcrow->product_id = $new_product_id; if ($calcrow->check()) { if (!$calcrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } // Discount calc extra data $query_extra = "Select * FROM `" . $this->table_prefix . "product_discount_calc_extra` WHERE product_id='" . $old_product_id . "' "; $this->_db->setQuery($query_extra); $list_extra = $this->_db->loadObjectList(); for ($i = 0; $i < count($list_extra); $i++) { $pdc_option_name = $list_extra[$i]->option_name; $pdc_price = $list_extra[$i]->price; $pdc_oprand = $list_extra[$i]->oprand; if (trim($pdc_option_name) != "") { $pdcextrarow =& $this->getTable('product_discount_calc_extra'); $pdcextrarow->load(); $pdcextrarow->pdcextra_id = 0; $pdcextrarow->option_name = $pdc_option_name; $pdcextrarow->oprand = $pdc_oprand; $pdcextrarow->price = $pdc_price; $pdcextrarow->product_id = $new_product_id; if (!$pdcextrarow->store()) { return false; } } } return true; }
public function generateParcel($order_id, $specifiedSendDate) { $order_details = $this->getOrderDetails($order_id); $producthelper = new producthelper(); $orderproducts = $this->getOrderItemDetail($order_id); $billingInfo = $this->getOrderBillingUserInfo($order_id); $shippingInfo = $this->getOrderShippingUserInfo($order_id); $shippinghelper = new shipping(); $shippingRateDecryptDetail = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $order_details->ship_method_id))); // Get Shipping Delivery Type $shippingDeliveryType = 1; if (isset($shippingRateDecryptDetail[8]) === true) { $shippingDeliveryType = (int) $shippingRateDecryptDetail[8]; } $sql = "SELECT country_2_code FROM " . $this->_table_prefix . "country WHERE country_3_code = " . $this->_db->quote(SHOP_COUNTRY); $this->_db->setQuery($sql); $billingInfo->country_code = $this->_db->loadResult(); $sql = "SELECT country_name FROM " . $this->_table_prefix . "country WHERE country_2_code = " . $this->_db->quote($billingInfo->country_code); $this->_db->setQuery($sql); $country_name = $this->_db->loadResult(); $sql = "SELECT country_2_code FROM " . $this->_table_prefix . "country WHERE country_3_code = " . $this->_db->quote($shippingInfo->country_code); $this->_db->setQuery($sql); $shippingInfo->country_code = $this->_db->loadResult(); // For product conetent $totalWeight = 0; $content_products = array(); $qty = 0; for ($c = 0; $c < count($orderproducts); $c++) { $product_id[] = $orderproducts[$c]->product_id; $qty += $orderproducts[$c]->product_quantity; $content_products[] = $orderproducts[$c]->order_item_name; // Product Weight $sql = "SELECT weight FROM " . $this->_table_prefix . "product WHERE product_id = " . (int) $orderproducts[$c]->product_id; $this->_db->setQuery($sql); $weight = $this->_db->loadResult(); // Accessory Weight $orderAccItemdata = $this->getOrderItemAccessoryDetail($orderproducts[$c]->order_item_id); $acc_weight = 0; if (count($orderAccItemdata) > 0) { for ($a = 0; $a < count($orderAccItemdata); $a++) { $accessory_quantity = $orderAccItemdata[$a]->product_quantity; $acc_sql = "SELECT weight FROM " . $this->_table_prefix . "product WHERE product_id = " . (int) $orderAccItemdata[$a]->product_id; $this->_db->setQuery($acc_sql); $accessory_weight = $this->_db->loadResult(); $acc_weight += $accessory_weight * $accessory_quantity; } } // Total weight $totalWeight += $weight * $orderproducts[$c]->product_quantity + $acc_weight; } $unitRatio = $producthelper->getUnitConversation('kg', DEFAULT_WEIGHT_UNIT); if ($unitRatio != 0) { // Converting weight in pounds $totalWeight = $totalWeight * $unitRatio; } if (SHOW_PRODUCT_DETAIL) { $content_products = array_unique($content_products); $content_products = implode(",", $content_products); $content_products = mb_convert_encoding($content_products, "ISO-8859-1", "UTF-8"); $content_products_remark = substr(mb_convert_encoding($content_products, "ISO-8859-1", "UTF-8"), 0, 29); } else { $content_products = " "; $content_products_remark = " "; } // Total quantity $total_qty = $qty; $firstname = mb_convert_encoding($shippingInfo->firstname, "ISO-8859-1", "UTF-8"); $lastname = mb_convert_encoding($shippingInfo->lastname, "ISO-8859-1", "UTF-8"); $full_name = $firstname . " " . $lastname; $address = mb_convert_encoding($shippingInfo->address, "ISO-8859-1", "UTF-8"); $city = mb_convert_encoding($shippingInfo->city, "ISO-8859-1", "UTF-8"); if ($billingInfo->is_company) { $company_name = mb_convert_encoding($shippingInfo->company_name, "ISO-8859-1", "UTF-8"); $fproductCode = "PDKEP"; $addon = "<addon adnid='POD'></addon>"; $finaladdress1 = $company_name; $finaladdress2 = $address; } else { $fproductCode = "P19DK"; $addon = "<addon adnid='DLV'></addon>"; $finaladdress1 = $address; $finaladdress2 = ""; } // When shipping delivery set to post office don't need to send DLV or POD addon. if ($shippingDeliveryType == 0) { $addon = ""; } if (WEBPACK_ENABLE_EMAIL_TRACK) { $addon .= '<addon adnid="NOTEMAIL"></addon>'; } if (WEBPACK_ENABLE_SMS) { $addon .= '<addon adnid="NOTSMS"></addon>'; } $xmlnew = '<?xml version="1.0" encoding="ISO-8859-1"?> <pacsoftonline> <meta> <val n="printer">1</val> </meta> <receiver rcvid="' . $shippingInfo->users_info_id . '"> <val n="name"><![CDATA[' . $full_name . ']]></val> <val n="address1"><![CDATA[' . $finaladdress1 . ']]></val> <val n="address2"><![CDATA[' . $finaladdress2 . ']]></val> <val n="zipcode">' . $shippingInfo->zipcode . '</val> <val n="city">' . $city . '</val> <val n="country">' . $shippingInfo->country_code . '</val> <val n="contact">' . $firstname . '</val> <val n="phone">' . $shippingInfo->phone . '</val> <val n="doorcode"/> <val n="email">' . $shippingInfo->user_email . '</val> <val n="sms">' . $shippingInfo->phone . '</val> </receiver> <shipment orderno="' . $shippingInfo->order_id . '"> <val n="from">1</val> <val n="to">' . $shippingInfo->users_info_id . '</val> <val n="reference">' . $order_details->order_number . '</val> <service srvid="' . $fproductCode . '"> ' . $addon . ' </service> <container type="parcel"> <val n="copies">1</val> <val n="weight">' . $totalWeight . '</val> <val n="contents">' . $content_products . '</val> <val n="packagecode">PC</val> </container> </shipment> </pacsoftonline>'; $postURL = "https://www.pacsoftonline.com/ufoweb/order?session=po_DK&user="******"&pin=" . POSTDK_CUSTOMER_PASSWORD . "&type=xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $postURL); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlnew); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); $oXML = new SimpleXMLElement($response); if ($oXML->val[1] == "201" && $oXML->val[2] == "Created") { $query = 'UPDATE ' . $this->_table_prefix . 'orders SET `order_label_create` = 1 WHERE order_id = ' . (int) $order_id; $this->_db->setQuery($query); $this->_db->query(); return "success"; } else { JError::raiseWarning(21, $oXML->val[1] . "-" . $oXML->val[2]); } }