private function getFreightPrice($weight, $type) { $vendor = JSFactory::getTable('vendor', 'jshop'); $vendor->loadMain(); $client = JSFactory::getUser(); $cep = preg_replace('|[^\\d]|', '', $client->d_zip ? $client->d_zip : $client->zip); $cost = $this->getCache($weight, $type, $cep); if ($cost) { return $cost; } $data = array('email' => plgSystemLigminchaFreight::$pagseguro_email, 'token' => plgSystemLigminchaFreight::$pagseguro_token, 'currency' => 'BRL', 'itemId1' => 1, 'itemDescription1' => 'Livros do Ligmincha Brasil Loja', 'itemAmount1' => '1.00', 'itemQuantity1' => 1, 'itemWeight1' => $weight, 'reference' => strtoupper(substr(uniqid('LB'), 1, 6)), 'senderName' => $vendor->shop_name, 'senderAreaCode' => $vendor->zip, 'senderEmail' => $vendor->email, 'shippingType' => $type, 'shippingAddressStreet' => $client->d_street ? $client->d_street : $client->street, 'shippingAddressNumber' => $client->d_street_nr ? $client->d_street_nr : $client->street_nr, 'shippingAddressPostalCode' => $cep, 'shippingAddressCity' => $client->d_city ? $client->d_city : $client->city, 'shippingAddressState' => $client->d_state ? $client->d_state : $client->state, 'shippingAddressCountry' => 'BRA'); $result = $this->post('https://ws.pagseguro.uol.com.br/v2/checkout/', $data); $code = preg_match('|<code>(.+?)</code>|', $result, $m) ? $m[1] : false; if ($code) { JFactory::getApplication()->enqueueMessage("Code: {$code}"); $html = file_get_contents("https://pagseguro.uol.com.br/v2/checkout/payment.html?code={$code}"); $cost = preg_match('|"freightRow".+?R\\$.+?([\\d,]+)|s', $html, $m) ? $m[1] : 0; $cost = str_replace(',', '.', $cost); } else { JError::raiseWarning('', curl_error($result)); } if ($cost == 0) { JError::raiseWarning('', 'Failed to obtain freight price!'); } else { $this->setCache($weight, $type, $cep, $cost); } return $cost; }
/** * отправляется запрос в базу локального сервера для окончательной проверки доступности для бронирования */ public function chekBookingBeforeSave(&$order, &$cart) { $db_local = JDatabase::getInstance(VipLocalApi::getDbConnectOptions()); $db = JFactory::getDBO(); $user = JFactory::getUser(); $adv_user = JSFactory::getUser(); $adv_user = JSFactory::getTable('usershop', 'jshop'); $adv_user->load($user->id); $order->country = $adv_user->country; $order->f_name = $adv_user->f_name; $order->l_name = $adv_user->l_name; $order->email = $adv_user->email; $order->phone = $adv_user->phone; // echo'<pre>';print_r($user);echo'</pre>';//die; // echo'<pre>';print_r($adv_user);echo'</pre>';//die; // echo'<pre>';print_r($order);echo'</pre>';die; $product_id_local = $cart->products[0]['ean']; $product_id = $cart->products[0]['product_id']; $category_id = $cart->products[0]['category_id']; $booking_date_info = $cart->products[0]['free_attributes_value']; //$date_from = '31-10-2015'; $date_from = str_replace('/', '-', $booking_date_info[0]->value); $date_to = str_replace('/', '-', $booking_date_info[1]->value); //проверяем только локальный сервер, так как на WuBook-е установлена нотификация каждого нового бронирования. $object_is_free_on_local = $this->chekBookingOnLocal($db_local, $product_id_local, $date_from, $date_to); //$object_is_free_on_local = true; //повторно проверяем по базе сайта, чтобы никто не забронил номер пока пользователь "копается" $object_is_free_on_site = $this->chekBookingOnSite($db, $product_id, $date_from, $date_to); if ($object_is_free_on_local == true && $object_is_free_on_site == true) { //заменяем разделитеть даты $date_from = str_replace('/', '-', $date_from); $date_to = str_replace('/', '-', $date_to); // echo'<pre>';print_r($product_id_local);echo'</pre>';//die; // echo'<pre>';print_r($date_from);echo'</pre>';//die; // echo'<pre>';print_r($date_to);echo'</pre>';//die; // echo'<pre>';print_r($order);echo'</pre>';die; // echo'<pre>';print_r($db_local);echo'</pre>';die; $k_zajav = VipLocalApi::addBookingOnLocalServer($db_local, $product_id_local, $date_from, $date_to, $order, VipLocalApi::ON_BOOKING_FROM_SITE_PRIM_PREFIX); //echo'<pre>';var_dump($k_zajav);echo'</pre>';die; $session = JFactory::getSession(); $session->set("k_zajav", $k_zajav); } else { $cart->clear(); $mainframe = JFactory::getApplication(); JError::raiseNotice(100, _JSHOP_OBJECT_IS_ALREADY_BOOKED); $contextfilter = "jshoping.list.front.product.cat." . $category_id; $date_from_ = $mainframe->getUserStateFromRequest($contextfilter . 'dfrom', 'dfrom', date('d/m/Y')); $date_to_ = $mainframe->getUserStateFromRequest($contextfilter . 'dto', 'dto', date('d/m/Y', time() + 60 * 60 * 24)); if ($date_from_ == '') { $date_from_ = date('d/m/Y'); } if ($date_to_ == '') { $date_to_ = date('d/m/Y', time() + 60 * 60 * 24); } $mainframe->redirect(SEFLink('index.php?option=com_jshopping&view=category&layout=category&task=view&category_id=' . $category_id . '&dfrom=' . $date_from_ . '&dto=' . $date_to_, 1, 1)); } }
public function onLoadStep5save(&$checkagb) { //echo'<pre>onLoadStep5save</pre>';die; $user = JFactory::getUser(); $adv_user = JSFactory::getUser(); $jshopConfig = JSFactory::getConfig(); $post = JRequest::get('post'); $adv_user->bind($post); $adv_user->store(); //echo'<pre>';print_r($adv_user);echo'</pre>';die; if ($user->guest) { $this->doRegAdv($adv_user, $user, 'step5save'); } //echo'<pre>';print_r($adv_user);echo'</pre>';die; }
/** * Return the cost for a given a weight and shipping type */ private function getFreightPrice($weight, $type) { if ($weight == 0) { return 0; } $client = JSFactory::getUser(); $cep2 = preg_replace('|[^\\d]|', '', $client->d_zip ? $client->d_zip : $client->zip); // Local cache (stores in an array so that no lookups are required for the same data in the same request) if (array_key_exists($type, $this->cost)) { return $this->cost[$type]; } // DB cache (costs for pac and sedex are stored in the database per weight and CEP for a day) $cost = $this->getCache($weight, $cep2); if ($cost) { return $cost[$type]; } // Not cached locally or in the database, get prices from the external API and store locally and in database $vendor = JSFactory::getTable('vendor', 'jshop'); $vendor->loadMain(); $cep1 = preg_replace('|[^\\d]|', '', $vendor->zip); // Get prices for both types since they're cached together if (is_numeric($result = $this->correios($cep1, $cep2, $weight, 1))) { $this->cost[1] = $result; } else { return JError::raiseWarning('', "Error: {$result}"); } if (is_numeric($result = $this->correios($cep1, $cep2, $weight, 2))) { $this->cost[2] = $result; } else { return JError::raiseWarning('', "Error: {$result}"); } // Store the price pair in the cache $this->setCache($weight, $cep2, $this->cost); // Return just the requested price return $this->cost[$type]; }
public function onLoadStep5save(&$checkagb) { $mainframe = JFactory::getApplication(); $cart = JSFactory::getModel('cart', 'jshop'); $cart->load(); $user = JFactory::getUser(); $adv_user = JSFactory::getUser(); //echo'<pre>$user ';print_r($user);echo'</pre>';//die; //echo'<pre>$adv_user ';print_r($adv_user);echo'</pre>';die; $payment_method = JRequest::getVar('payment_method', ''); //class payment method if ($payment_method == '') { $session = JFactory::getSession(); $payment_method = $session->get("payment_method", ''); } //echo'<pre>';var_dump($payment_method);echo'</pre>';//die; $params = JRequest::getVar('params', array()); if (isset($params[$payment_method])) { $params_pm = $params[$payment_method]; } else { $params_pm = ''; } $paym_method = JSFactory::getTable('paymentmethod', 'jshop'); $paym_method->class = $payment_method; $payment_method_id = $paym_method->getId(); $paym_method->load($payment_method_id); //echo'<pre>';print_r($paym_method);echo'</pre>';die; $pmconfigs = $paym_method->getConfigs(); $paymentsysdata = $paym_method->getPaymentSystemData(); $payment_system = $paymentsysdata->paymentSystem; //echo'<pre>';print_r($paymentsysdata->paymentSystemError);echo'</pre>';//die; //echo'<pre>';print_r($paym_method->payment_publish);echo'</pre>';//die; if ($paymentsysdata->paymentSystemError || $paym_method->payment_publish == 0) { //echo'<pre>';print_r('_JSHOP_ERROR_PAYMENT');echo'</pre>';die; $cart->setPaymentParams(''); JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT); $mainframe->redirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step3', 0, 1, $jshopConfig->use_ssl)); return 0; } if ($payment_system) { if (!$payment_system->checkPaymentInfo($params_pm, $pmconfigs)) { $cart->setPaymentParams(''); JError::raiseWarning("", $payment_system->getErrorMessage()); $mainframe->redirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step3', 0, 1, $jshopConfig->use_ssl)); return 0; } } $paym_method->setCart($cart); $cart->setPaymentId($payment_method_id); $price = $paym_method->getPrice(); $cart->setPaymentDatas($price, $paym_method); if (isset($params[$payment_method])) { $cart->setPaymentParams($params_pm); } else { $cart->setPaymentParams(''); } //echo'<pre>$adv_user ';var_dump($payment_method_id);echo'</pre>';die; $db = JFactory::getDbo(); $query = "UPDATE `#__jshopping_users` SET payment_id = {$payment_method_id} WHERE user_id = " . $user->id; $db->setQuery($query); $result = $db->execute(); }
function step5save() { $session = JFactory::getSession(); $jshopConfig = JSFactory::getConfig(); $db = JFactory::getDBO(); $checkout = JSFactory::getModel('checkout', 'jshop'); $mainframe = JFactory::getApplication(); $checkout->checkStep(5); $checkagb = JRequest::getVar('agb'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onLoadStep5save', array(&$checkagb)); $lang = JSFactory::getLang(); $user = JFactory::getUser(); $adv_user = JSFactory::getUser(); $cart = JSFactory::getModel('cart', 'jshop'); $cart->load(); $cart->setDisplayItem(1, 1); $cart->setDisplayFreeAttributes(); if ($jshopConfig->check_php_agb && $checkagb != 'on') { JError::raiseWarning("", _JSHOP_ERROR_AGB); $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl)); return 0; } if (!$cart->checkListProductsQtyInStore()) { $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=cart&task=view', 1, 1)); return 0; } if (!$session->get('checkcoupon')) { if (!$cart->checkCoupon()) { $cart->setRabatt(0, 0, 0); JError::raiseWarning("", _JSHOP_RABATT_NON_CORRECT); $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=cart&task=view', 1, 1)); return 0; } $session->set('checkcoupon', 1); } $orderNumber = $jshopConfig->getNextOrderNumber(); $jshopConfig->updateNextOrderNumber(); $payment_method_id = $cart->getPaymentId(); $pm_method = JSFactory::getTable('paymentMethod', 'jshop'); $pm_method->load($payment_method_id); $payment_method = $pm_method->payment_class; if ($jshopConfig->without_payment) { $pm_method->payment_type = 1; $paymentSystemVerySimple = 1; } else { $paymentsysdata = $pm_method->getPaymentSystemData(); $payment_system = $paymentsysdata->paymentSystem; if ($paymentsysdata->paymentSystemVerySimple) { $paymentSystemVerySimple = 1; } if ($paymentsysdata->paymentSystemError) { $cart->setPaymentParams(""); JError::raiseWarning("", _JSHOP_ERROR_PAYMENT); $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step3', 0, 1, $jshopConfig->use_ssl)); return 0; } } $order = JSFactory::getTable('order', 'jshop'); $arr_property = $order->getListFieldCopyUserToOrder(); foreach ($adv_user as $key => $value) { if (in_array($key, $arr_property)) { $order->{$key} = $value; } } $sh_mt_pr = JSFactory::getTable('shippingMethodPrice', 'jshop'); $sh_mt_pr->load($cart->getShippingPrId()); $order->order_date = $order->order_m_date = getJsDate(); $order->order_tax = $cart->getTax(1, 1, 1); $order->setTaxExt($cart->getTaxExt(1, 1, 1)); $order->order_subtotal = $cart->getPriceProducts(); $order->order_shipping = $cart->getShippingPrice(); $order->order_payment = $cart->getPaymentPrice(); $order->order_discount = $cart->getDiscountShow(); $order->shipping_tax = $cart->getShippingPriceTaxPercent(); $order->setShippingTaxExt($cart->getShippingTaxList()); $order->payment_tax = $cart->getPaymentTaxPercent(); $order->setPaymentTaxExt($cart->getPaymentTaxList()); $order->order_package = $cart->getPackagePrice(); $order->setPackageTaxExt($cart->getPackageTaxList()); $order->order_total = $cart->getSum(1, 1, 1); $order->currency_exchange = $jshopConfig->currency_value; $order->vendor_type = $cart->getVendorType(); $order->vendor_id = $cart->getVendorId(); $order->order_status = $jshopConfig->default_status_order; $order->shipping_method_id = $cart->getShippingId(); $order->payment_method_id = $cart->getPaymentId(); $order->delivery_times_id = $sh_mt_pr->delivery_times_id; if ($jshopConfig->delivery_order_depends_delivery_product) { $order->delivery_time = $cart->getDelivery(); } if ($jshopConfig->show_delivery_date) { $order->delivery_date = $cart->getDeliveryDate(); } $order->coupon_id = $cart->getCouponId(); $pm_params = $cart->getPaymentParams(); if (is_array($pm_params) && !$paymentSystemVerySimple) { $payment_system->setParams($pm_params); $payment_params_names = $payment_system->getDisplayNameParams(); $order->payment_params = getTextNameArrayValue($payment_params_names, $pm_params); $order->setPaymentParamsData($pm_params); } $sh_params = $cart->getShippingParams(); if (is_array($sh_params)) { $sh_method = JSFactory::getTable('shippingMethod', 'jshop'); $sh_method->load($cart->getShippingId()); $shippingForm = $sh_method->getShippingForm(); if ($shippingForm) { $shipping_params_names = $shippingForm->getDisplayNameParams(); $order->shipping_params = getTextNameArrayValue($shipping_params_names, $sh_params); } $order->setShippingParamsData($sh_params); } $name = $lang->get("name"); $order->ip_address = $_SERVER['REMOTE_ADDR']; $order->order_add_info = JRequest::getVar('order_add_info', ''); $order->currency_code = $jshopConfig->currency_code; $order->currency_code_iso = $jshopConfig->currency_code_iso; $order->order_number = $order->formatOrderNumber($orderNumber); $order->order_hash = md5(time() . $order->order_total . $order->user_id); $order->file_hash = md5(time() . $order->order_total . $order->user_id . "hashfile"); $order->display_price = $jshopConfig->display_price_front_current; $order->lang = $jshopConfig->getLang(); if ($order->client_type) { $order->client_type_name = $jshopConfig->user_field_client_type[$order->client_type]; } else { $order->client_type_name = ""; } if ($order->order_total == 0) { $pm_method->payment_type = 1; $jshopConfig->without_payment = 1; $order->order_status = $jshopConfig->payment_status_paid; } if ($pm_method->payment_type == 1) { $order->order_created = 1; } else { $order->order_created = 0; } if (!$adv_user->delivery_adress) { $order->copyDeliveryData(); } $dispatcher->trigger('onBeforeCreateOrder', array(&$order, &$cart)); $order->store(); $dispatcher->trigger('onAfterCreateOrder', array(&$order, &$cart)); if ($cart->getCouponId()) { $coupon = JSFactory::getTable('coupon', 'jshop'); $coupon->load($cart->getCouponId()); if ($coupon->finished_after_used) { $free_discount = $cart->getFreeDiscount(); if ($free_discount > 0) { $coupon->coupon_value = $free_discount / $jshopConfig->currency_value; } else { $coupon->used = $adv_user->user_id; } $coupon->store(); } } $order->saveOrderItem($cart->products); $dispatcher->trigger('onAfterCreateOrderFull', array(&$order, &$cart)); $session->set("jshop_end_order_id", $order->order_id); $order_history = JSFactory::getTable('orderHistory', 'jshop'); $order_history->order_id = $order->order_id; $order_history->order_status_id = $order->order_status; $order_history->status_date_added = $order->order_date; $order_history->customer_notify = 1; $order_history->store(); if ($pm_method->payment_type == 1) { if ($jshopConfig->order_stock_removed_only_paid_status) { $product_stock_removed = in_array($order->order_status, $jshopConfig->payment_status_enable_download_sale_file); } else { $product_stock_removed = 1; } if ($product_stock_removed) { $order->changeProductQTYinStock("-"); } if ($jshopConfig->send_order_email) { $checkout->sendOrderEmail($order->order_id); } } $dispatcher->trigger('onEndCheckoutStep5', array(&$order, &$cart)); $session->set("jshop_send_end_form", 0); if ($jshopConfig->without_payment) { $checkout->setMaxStep(10); $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl)); return 0; } $pmconfigs = $pm_method->getConfigs(); $task = "step6"; if (isset($pmconfigs['windowtype']) && $pmconfigs['windowtype'] == 2) { $task = "step6iframe"; $session->set("jsps_iframe_width", $pmconfigs['iframe_width']); $session->set("jsps_iframe_height", $pmconfigs['iframe_height']); } $checkout->setMaxStep(6); $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=' . $task, 0, 1, $jshopConfig->use_ssl)); }
function step5save() { $session = JFactory::getSession(); $jshopConfig = JSFactory::getConfig(); $checkoutStep = JSFactory::getModel('checkoutStep', 'jshop'); $checkout = JSFactory::getModel('checkoutOrder', 'jshop'); $checkout->checkStep(5); $checkagb = JRequest::getVar('agb'); $post = JRequest::get('post'); $back_url = $checkoutStep->getCheckoutUrl('5'); $cart_url = SEFLink('index.php?option=com_jshopping&controller=cart&task=view', 1, 1); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onLoadStep5save', array(&$checkagb)); $adv_user = JSFactory::getUser(); $cart = JSFactory::getModel('cart', 'jshop')->init(); $cart->setDisplayItem(1, 1); $checkout->setCart($cart); if (!$checkout->checkAgb($checkagb)) { JError::raiseWarning("", $checkout->getError()); $this->setRedirect($back_url); return 0; } if (!$cart->checkListProductsQtyInStore()) { $this->setRedirect($cart_url); return 0; } if (!$checkout->checkCoupon()) { JError::raiseWarning("", $checkout->getError()); $this->setRedirect($cart_url); return 0; } $order = $checkout->orderDataSave($adv_user, $post); $dispatcher->trigger('onEndCheckoutStep5', array(&$order, &$cart)); $checkout->setSendEndForm(0); if ($jshopConfig->without_payment || $order->order_total == 0) { $checkout->setMaxStep(10); $this->setRedirect($checkoutStep->getCheckoutUrl('finish')); return 0; } $pmconfigs = $checkout->getPaymentMethod()->getConfigs(); $task = "step6"; if (isset($pmconfigs['windowtype']) && $pmconfigs['windowtype'] == 2) { $task = "step6iframe"; $session->set("jsps_iframe_width", $pmconfigs['iframe_width']); $session->set("jsps_iframe_height", $pmconfigs['iframe_height']); } $checkout->setMaxStep(6); $this->setRedirect($checkoutStep->getCheckoutUrl($task)); }