/** * (non-PHPdoc) * @see tienda/admin/TiendaController#display($cachable) */ function display($cachable = false, $urlparams = '') { if (empty(JFactory::getUser()->id)) { $url = JRoute::_("index.php?option=com_tienda&view=orders"); Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } $model = $this->getModel($this->get('suffix')); $this->_setModelState(); $config = Tienda::getInstance(); $model->setState('filter_orderstates', $config->get('orderstates_csv', '2, 3, 5, 17')); $list = $model->getList(); $view = $this->getView('orders', 'html'); $view->set('_controller', 'orders'); $view->set('_view', 'orders'); $view->set('_doTask', true); $view->set('hidemenu', false); $view->setModel($model, true); $view->setLayout('view'); JRequest::setVar('view', $this->get('suffix')); JRequest::setVar('layout', 'default'); parent::display($cachable, $urlparams); }
/** * @see plugins/tienda/payment_paypalpro/library/plgTiendaPayment_Paypalpro_Processor#validateData() */ function validateData() { /* * perform initial checks */ if (!count($this->_data)) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_NO_DATA_IS_PROVIDED')); return false; } if (!JRequest::checkToken()) { $this->setError(JText::_('COM_TIENDA_INVALID_TOKEN')); return false; } // if (!$this->getSubscrTypeObj()) { // $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_INVALID_ITEM_TYPE')); // return false; // } if (!$this->_getParam('api_username') || !$this->_getParam('api_password') || !$this->_getParam('api_signature')) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_MERCHANT_CREDENTIALS_ARE_INVALID')); return false; } /* * do form verification to make sure information is both present and valid */ // check required fields foreach ($this->_required as $required_field) { if (empty($this->_data[$required_field])) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_FILL_IN_REQUIRED_FIELDS')); return false; } } // check some specific fields if (JString::strlen($this->_data['state']) != 2) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_STATE_INVALID')); return false; } $user = JFactory::getUser(); if (!$user->id) { // require email address for guest users jimport('joomla.mail.helper'); if (empty($this->_data['email']) || !JMailHelper::isEmailAddress($this->_data['email'])) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_EMAIL_ADDRESS_REQUIRED')); return false; } if (TiendaHelperUser::emailExists($this->_data['email'])) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_EMAIL_EXISTS')); return false; } } if (JString::strlen($this->_data['cardexp_month']) != 2 || JString::strlen($this->_data['cardexp_year']) != 4) { $this->setError(JText::_('COM_TIENDA_PAYPALPRO_MESSAGE_EXPIRATION_DATE_INVALID=')); return false; } return true; }
/** * constructor */ function __construct() { if (empty(JFactory::getUser()->id)) { $url = JRoute::_("index.php?option=com_tienda&view=dashboard"); Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } parent::__construct(); $this->set('suffix', 'dashboard'); }
/** * constructor */ function __construct() { if (empty(JFactory::getUser()->id)) { $url = JRoute::_("index.php?option=com_tienda&view=addresses"); Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } parent::__construct(); $this->set('suffix', 'addresses'); $this->registerTask('flag_billing', 'flag'); $this->registerTask('flag_shipping', 'flag'); $this->registerTask('flag_deleted', 'flag'); }
/** * constructor */ function __construct() { parent::__construct(); $this->set('suffix', 'wishlists'); $user = JFactory::getUser(); if (empty($user->id)) { // redirect to login Tienda::load("TiendaHelperRoute", 'helpers.route'); $router = new TiendaHelperRoute(); $url = JRoute::_("index.php?option=com_tienda&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false); Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } }
/** * constructor */ function __construct() { if (empty(JFactory::getUser()->id)) { $url = JRoute::_("index.php?option=com_tienda&view=orders"); Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } parent::__construct(); $this->set('suffix', 'subscriptions'); $this->registerTask('subscription_enabled.enable', 'boolean'); $this->registerTask('subscription_enabled.disable', 'boolean'); $this->registerTask('lifetime_enabled.enable', 'boolean'); $this->registerTask('lifetime_enabled.disable', 'boolean'); $this->registerTask('update_subscription', 'update'); }
/** * Sets the model's state * * @return array() */ function _setModelState() { $state = parent::_setModelState(); $app = JFactory::getApplication(); $model = $this->getModel($this->get('suffix')); $ns = $this->getNamespace(); $session = JFactory::getSession(); $user = JFactory::getUser(); $state['filter_user'] = $user->id; if (empty($user->id)) { $state['filter_session'] = $session->getId(); } Tienda::load('TiendaHelperUser', 'helpers.user'); $filter_group = TiendaHelperUser::getUserGroup($user->id); $state['filter_group'] = $filter_group; foreach (@$state as $key => $value) { $model->setState($key, $value); } return $state; }
function getCart() { Tienda::load('TiendaHelperCarts', 'helpers.carts'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); // determine whether we're working with a session or db cart $suffix = TiendaHelperCarts::getSuffix(); $model = JModel::getInstance('Carts', 'TiendaModel'); $session = JFactory::getSession(); $user = JFactory::getUser(); $model->setState('filter_user', $user->id); if (empty($user->id)) { $model->setState('filter_session', $session->getId()); } $list = $model->getList(false, false); Tienda::load('Tienda', 'defines'); $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $this->using_default_geozone = false; if ($show_tax) { Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $this->using_default_geozone = true; $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } Tienda::load("TiendaHelperProduct", 'helpers.product'); foreach ($list as &$item) { $taxtotal = TiendaHelperProduct::getTaxTotal($item->product_id, $geozones); $item->product_price = $item->product_price + $taxtotal->tax_total; $item->taxtotal = $taxtotal; } } return $list; }
/** * Adding helpfulness of review * */ function reviewHelpfullness() { $user_id = JFactory::getUser()->id; $Itemid = JRequest::getInt('Itemid', ''); $id = JRequest::getInt('product_id', ''); $url = "index.php?option=com_tienda&view=products&task=view&Itemid=" . $Itemid . "&id=" . $id; if ($user_id) { $productcomment_id = JRequest::getInt('productcomment_id', ''); Tienda::load('TiendaHelperProduct', 'helpers.product'); $producthelper = new TiendaHelperProduct(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $productcomment = JTable::getInstance('productcomments', 'TiendaTable'); $productcomment->load($productcomment_id); $helpful_votes_total = $productcomment->helpful_votes_total; $helpful_votes_total = $helpful_votes_total + 1; $helpfulness = JRequest::getInt('helpfulness', ''); if ($helpfulness == 1) { $helpful_vote = $productcomment->helpful_votes; $helpful_vote_new = $helpful_vote + 1; $productcomment->helpful_votes = $helpful_vote_new; } $productcomment->helpful_votes_total = $helpful_votes_total; $report = JRequest::getInt('report', ''); if ($report == 1) { $productcomment->reported_count = $productcomment->reported_count + 1; } $help = array(); $help['productcomment_id'] = $productcomment_id; $help['helpful'] = $helpfulness; $help['user_id'] = $user_id; $help['reported'] = $report; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $reviewhelpfulness = JTable::getInstance('ProductCommentsHelpfulness', 'TiendaTable'); $reviewhelpfulness->load(array('user_id' => $user_id)); if ($report == 1 && !empty($reviewhelpfulness->productcommentshelpfulness_id) && empty($reviewhelpfulness->reported)) { $reviewhelpfulness->reported = 1; $reviewhelpfulness->save(); $productcomment->save(); JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_TIENDA_THANKS_FOR_REPORTING_THIS_COMMENT")); JFactory::getApplication()->redirect($url); return; } $reviewhelpfulness->bind($help); if (!empty($reviewhelpfulness->productcommentshelpfulness_id)) { JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_TIENDA_YOU_HAVE_ALREADY_COMMENTED_ON_THIS_REVIEW")); JFactory::getApplication()->redirect($url); return; } else { $reviewhelpfulness->save(); $productcomment->save(); JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_TIENDA_THANKS_FOR_YOUR_FEEDBACK_ON_THIS_COMMENT")); JFactory::getApplication()->redirect($url); return; } } else { Tienda::load("TiendaHelperUser", 'helpers.user'); $redirect = JRoute::_(TiendaHelperUser::getUserLoginUrl($url), false); JFactory::getApplication()->redirect($redirect); return; } }
/** * Returns the shipping rate for an item * Going through this helper enables product-specific flat rates in the future... * * @param int $shipping_method_id * @param int $geozone_id * @param int $product_id * @return object */ public function getRate($shipping_method_id, $geozone_id, $product_id = '', $use_weight = '0', $weight = '0') { $session = JFactory::getSession(); $isPOS = $session->get('user_type', '', 'tienda_pos') == ''; $user_id = JFactory::getUser()->id; if ($isPOS) { $user_id = $session->get('user_id', JFactory::getUser()->id, 'tienda_pos'); } Tienda::load('TiendaHelperUser', 'helpers.user'); $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id); // TODO Give this better error reporting capabilities JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('ShippingRates', 'TiendaModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_geozone', $geozone_id); $model->setState('filter_user_group', $filter_group); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $product = JTable::getInstance('Products', 'TiendaTable'); $product->load($product_id); if (empty($product->product_id)) { return JTable::getInstance('ShippingRates', 'TiendaTable'); } if (empty($product->product_ships)) { // product doesn't require shipping, therefore cannot impact shipping costs return JTable::getInstance('ShippingRates', 'TiendaTable'); } if (!empty($use_weight) && $use_weight == '1') { if (!empty($weight)) { $model->setState('filter_weight', $weight); } else { $model->setState('filter_weight', $product->product_weight); } } $items = $model->getList(); if (empty($items)) { return JTable::getInstance('ShippingRates', 'TiendaTable'); } return $items[0]; }
/** * Prepares vars for the recurring prepayment * * @param object vars * @return object vars */ function prepareSecondVars($order, $orderpayment) { $vars = new JObject(); $vars->action_url = $this->_getActionUrl(); // properties as specified in moneybookers gateway manual $vars->pay_to_email = $this->_getParam('receiver_email'); $vars->transaction_id = Tienda::getInstance()->get('order_number_prefix') . $orderpayment->orderpayment_id; // this need to be subscription id?? $vars->return_url = JURI::root() . "index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type={$this->_element}&paction=message&checkout=0"; $vars->return_url_text = 'Exit Secure Payment'; //A $vars->cancel_url = JURI::root() . "index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type={$this->_element}&paction=cancel"; $vars->status_url = JURI::root() . "index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type={$this->_element}&paction=process&tmpl=component"; $vars->status_url2 = 'mailto:bojan.programer@gmail.com'; $vars->language = $this->_getParam('language', 'EN'); $vars->confirmation_note = JText::_('TIENDA MONEYBOOKERS CONFIRMATION NOTE'); $vars->logo_url = JURI::root() . $this->_getParam('logo_image'); $vars->currency = $this->_getParam('currency', 'EUR'); $vars->detail1_description = $order->order_id; $vars->detail1_text = JText::_('TIENDA MONEYBOOKERS DETAIL1 DESCRIPTION'); $vars->detail2_description = $orderpayment->orderpayment_id; $vars->detail2_text = JText::_('TIENDA MONEYBOOKERS DETAIL2 DESCRIPTION'); //pay from email + All Customer Details to prefill MoneyBookers form //MD5 and other comparison $vars->user_id = JFactory::getUser()->id; $vars->order_id = $order->order_id; $vars->orderpayment_id = $orderpayment->orderpayment_id; $vars->orderpayment_type = $this->_element; $vars->is_recurring = $order->isRecurring(); $vars->mixed_cart = false; $billing_address = TiendaHelperUser::getPrimaryAddress($vars->user_id, 'billing'); $vars->first_name = $billing_address->first_name; $vars->last_name = $billing_address->last_name; $vars->phone_number = $billing_address->phone1; $vars->email = JFactory::getUser()->email; $vars->address = $billing_address->address_1; $vars->postal_code = $billing_address->postal_code; $vars->city = $billing_address->city; $vars->country = $billing_address->country; $vars->state = $billing_address->zone_name; $vars->rec_amount = $order->recurring_trial ? $order->recurring_trial_price : $order->order_total; $vars->rec_start_date = ''; $vars->rec_period = $order->recurring_trial ? $order->recurring_trial_period_interval : $order->recurring_period_interval; $vars->rec_cycle = $this->_getDurationUnit($order->recurring_trial ? $order->recurring_trial_period_unit : $order->recurring_period_unit); // (day | week | month) // a period of days during which the customer can still process the transaction in case it originally failed. $vars->rec_grace_period = 3; $vars->transaction_id = Tienda::getInstance()->get('order_number_prefix') . $orderpayment->orderpayment_id; // this need to be subscription id?? return $vars; }
/** * * @param $moneris_values * @return unknown_type */ function _verifyForm($data) { Tienda::load('TiendaHelperUser', 'helpers.user'); $object = new JObject(); $object->error = false; $object->message = ''; $user = JFactory::getUser(); $required = array('first_name', 'last_name', 'address_line_1', 'city', 'state', 'postal_code', 'card_type', 'card_number', 'expiration_month', 'expiration_year', 'cvv_number'); // verify the fields in the form // if any fail verification, set // $object->error = true // $object->message .= '<li>x item failed verification</li>' foreach ($data as $key => $value) { switch (strtolower($key)) { case "email": if (!$user->id) { if (!isset($data[$key]) || !JString::strlen($data[$key])) { $object->error = true; $object->message .= "<li>" . JText::_('Email Address Required') . "</li>"; } if ($emailExists = TiendaHelperUser::emailExists($data[$key])) { $object->error = true; $object->message .= '<li>' . JText::_('Email Exists') . '</li>'; } jimport('joomla.mail.helper'); if (!($isValidEmail = JMailHelper::isEmailAddress($data[$key]))) { $object->error = true; $object->message .= "<li>" . JText::_('Email Address Invalid') . "</li>"; } } break; default: if (in_array($key, $required) && empty($value)) { $object->error = true; $object->message .= "<li>" . JText::_("Invalid " . $key) . "</li>"; } break; } } return $object; }
function registerNewUser($values) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); // Register an User Tienda::load('TiendaHelperUser', 'helpers.user'); $userHelper = TiendaHelperUser::getInstance('User', 'TiendaHelper'); $response = array(); $response['msg'] = ''; $response['error'] = ''; if ($userHelper->emailExists($values['email_address'])) { // TODO user already exists $response['error'] = '1'; $response['msg'] = JText::_('COM_TIENDA_EMAIL_ALREADY_EXIST'); $response['key'] = 'email_address'; return $response; } else { Tienda::load('TiendaHelperUser', 'helpers.user'); $userHelper = TiendaHelperUser::getInstance('User', 'TiendaHelper'); $details = array('email' => $values['email_address'], 'name' => $values['name'], 'username' => $values['username'], 'password' => $values['password'], 'password2' => $values['password2']); // create the new user $msg = $this->getError(); $user = $userHelper->createNewUser($details, isset($values['guest'])); if (empty($user->id)) { // TODO what to do if creating new user failed? } // save the real user's info in the userinfo table also JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $userinfo = JTable::getInstance('UserInfo', 'TiendaTable'); $userinfo->load(array('user_id' => $user->id)); $userinfo->user_id = $user->id; if (isset($values['billing_input_first_name'])) { $userinfo->first_name = $values['billing_input_first_name']; } if (isset($values['billing_input_last_name'])) { $userinfo->last_name = $values['billing_input_last_name']; } if (isset($values['billing_input_company'])) { $userinfo->company = $values['billing_input_company']; } if (isset($values['billing_input_middle_name'])) { $userinfo->middle_name = $values['billing_input_middle_name']; } if (isset($values['billing_input_phone_1'])) { $userinfo->phone_1 = $values['billing_input_phone_1']; } if (isset($values['email_address'])) { $userinfo->email = $values['email_address']; } $userinfo->save(); // login the user $userHelper->login(array('username' => $user->username, 'password' => $details['password'])); return true; } }
/** * Sample use of the products model for getting products with certain properties * See admin/models/products.php for all the filters currently built into the model * * @param $parameters * @return unknown_type */ function getProducts() { // Check the registry to see if our Tienda class has been overridden if (!class_exists('Tienda')) { JLoader::register("Tienda", JPATH_ADMINISTRATOR . "/components/com_tienda/defines.php"); } // load the config class Tienda::load('Tienda', 'defines'); Tienda::load('TiendaHelperProduct', 'helpers.product'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); // get the model $model = JModel::getInstance('Products', 'TiendaModel'); // setting the model's state tells it what items to return $model->setState('filter_published', '1'); $date = JFactory::getDate(); $model->setState('filter_published_date', $date->toMysql()); $model->setState('filter_enabled', '1'); // Set category state if ($this->params->get('category', '1') != '1') { $model->setState('filter_category', $this->params->get('category', '1')); } // Set manufacturer state if ($this->params->get('manufacturer', '') != '') { $model->setState('filter_manufacturer', $this->params->get('manufacturer', '')); } // Set id set state if ($this->params->get('id_set', '') != '') { $params_id_set = $this->params->get('id_set'); $id_array = explode(',', $params_id_set); $id_set = "'" . implode("', '", $id_array) . "'"; $model->setState('filter_id_set', $id_set); } // set the states based on the parameters $model->setState('limit', $this->params->get('max_number', '10')); if ($this->params->get('price_from', '-1') != '-1') { $model->setState('filter_price_from', $this->params->get('price_from', '-1')); } if ($this->params->get('price_to', '-1') != '-1') { $model->setState('filter_price_to', $this->params->get('price_to', '-1')); } $order = $this->params->get('order'); $direction = $this->params->get('direction', 'ASC'); switch ($order) { case "2": case "name": $model->setState('order', 'tbl.product_name'); break; case "1": case "created": $model->setState('order', 'tbl.created_date'); break; case "0": case "ordering": default: $model->setState('order', 'tbl.ordering'); break; } if ($this->params->get('random', '0') == '1') { $model->setState('order', 'RAND()'); } $model->setState('direction', $direction); $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $default_user_group = Tienda::getInstance()->get('default_user_group'); $user_groups_array = $this->getUserGroups(); $overide_price = false; if (count($user_groups_array) > 1 && $user_groups_array[0] != $default_user_group) { $overide_price = true; } // using the set filters, get a list of products if ($products = $model->getList(true, false)) { if ($show_tax) { Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } foreach ($products as $product) { if ($overide_price) { $filter_group = TiendaHelperUser::getUserGroup(JFactory::getUser()->id, $product->product_id); $price = TiendaHelperProduct::getPrice($product->product_id, '1', $filter_group); $product->price = $price->product_price; } $product->taxtotal = 0; $product->tax = 0; if ($show_tax) { $taxtotal = TiendaHelperProduct::getTaxTotal($product->product_id, $geozones); $product->taxtotal = $taxtotal; $product->tax = $taxtotal->tax_total; } $product->filter_category = ''; $categories = TiendaHelperProduct::getCategories($product->product_id); if (!empty($categories)) { $product->link .= "&filter_category=" . $categories[0]; $product->filter_category = $categories[0]; } $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($product->filter_category, true); if (empty($itemid)) { $product->itemid = $this->params->get('itemid'); } else { $product->itemid = $itemid; } } } return $products; }
/** * Processes a new order * * @param $order_id * @return unknown_type */ function processOrder($order_id) { // get the order $model = JModel::getInstance('Orders', 'TiendaModel'); $model->setId($order_id); $order = $model->getItem(); if ($order->user_id < Tienda::getGuestIdStart()) { //load language from frontend so it has email language strings $lang = JFactory::getLanguage(); $lang->load('com_tienda', JPATH_SITE); $details = array(); $details['name'] = $order->billing_first_name . ' ' . $order->billing_last_name; $details['username'] = $order->userinfo_email; $details['email'] = $order->userinfo_email; jimport('joomla.user.helper'); $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $user = TiendaHelperUser::createNewUser($details); $order->user_id = $user->id; //update the order to the new user $table = $model->getTable(); $table->load($order->order_id); $table->user_id = $user->id; $table->save(); $model->clearCache(); // } // find the products in the order that are integrated foreach ($order->orderitems as $orderitem) { $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId($orderitem->product_id); $product = $model->getItem(); $core_user_change_gid = $product->product_parameters->get('core_user_change_gid'); $core_user_new_gid = $product->product_parameters->get('core_user_new_gid'); if (!empty($core_user_change_gid)) { DSCAcl::addgroup($order->user_id, $core_user_new_gid); } } }
/** Gets an existing user or creates a new one * * @param int $id * @param string $email * @param string $unique_gateway_id The ID that uniquely identifies the user to the payment system * @return JUser object * @access protected */ function &_getUser($id, $email, $unique_gateway_id = false) { $config = Tienda::getInstance(); $user = JFactory::getUser($id); if ($user->id) { return $user; } // try to find out if the email is registered jimport('joomla.user.helper'); if ($id = JUserHelper::getUserId($email)) { $user = JFactory::getUser($id); if ($user->id) { return $user; } } if ($unique_gateway_id) { // try to find a user in the payment_details if he ever made a payment if ($id = $this->_findUserId($unique_gateway_id, 'PAYERID')) { $user = JFactory::getUser($id); if ($user->id) { return $user; } } } // if no existing user found, create a new one $msg = new stdClass(); $msg->type = ''; $msg->message = ''; $newuser_email = $email; // create user from email jimport('joomla.user.helper'); $details['name'] = $newuser_email; $details['username'] = $newuser_email; $details['email'] = $newuser_email; $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $details['block'] = $config->get('block_automatically_registered') ? '1' : '0'; if ($user = TiendaHelperUser::createNewUser($details, $msg)) { if (!$config->get('block_automatically_registered')) { // login the new user $login = TiendaHelperUser::login($details, '1'); } // indicate that user was registed by AS automatically $user->set('automatically_registered', true); } return $user; }
/** * Generates a selectlist for the specified Product Attribute * * @param unknown_type $productattribute_id * @param unknown_type $selected * @param unknown_type $name * @param unknown_type $attribs * @param unknown_type $idtag * @return unknown_type */ public static function productattributeoptions($productattribute_id, $selected, $name = 'filter_pao', $attribs = array('class' => 'inputbox'), $idtag = null, $opt_selected = array(), $user_id = 0) { $uid = $user_id == 0 ? JFactory::getUser()->id : $user_id; $list = array(); $pid = !empty($attribs['pid']) ? $attribs['pid'] : null; $changed_attr = !empty($attribs['changed_attr']) ? $attribs['changed_attr'] : -1; $changed_pao = !empty($attribs['changed_pao']) ? $attribs['changed_pao'] : -1; if (empty($pid)) { $items = array(); } else { $items = TiendaHelperProduct::getAvailableAttributeOptions($pid, $productattribute_id, $changed_attr, $changed_pao, $opt_selected); } $geozones = array(); $shipping = false; if (count($items)) { $shipping = $items[0]->product_ships; if ($shipping) { Tienda::load('TiendaHelperProduct', 'helpers.product'); Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones($uid); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } } foreach (@$items as $item) { if ($shipping) { $tax = TiendaHelperProduct::getTaxTotal($item->product_id, $geozones, $item->productattributeoption_price); $item->productattributeoption_price += $tax->tax_total; } // Do not display the prefix if it is "=" (it's not good to see =�13, better �13) if ($item->productattributeoption_prefix != '=') { $display_suffix = $item->productattributeoption_price > '0' ? ": " . $item->productattributeoption_prefix . TiendaHelperBase::currency($item->productattributeoption_price) : ''; } else { $display_suffix = $item->productattributeoption_price > '0' ? ": " . TiendaHelperBase::currency($item->productattributeoption_price) : ''; } $display_name = JText::_($item->productattributeoption_name) . $display_suffix; if ($item->is_blank) { $list[] = self::option(0, $display_name); } else { $list[] = self::option($item->productattributeoption_id, $display_name); } } return self::genericlist($list, $name, $attribs, 'value', 'text', $selected, $idtag); }
/** * * Enter description here ... * @param $product_id * @param $values * @return unknown_type */ function getAddToCart($product_id, $values = array()) { $html = ''; DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('Products', 'TiendaModel'); $model->setId($product_id); $session = JFactory::getSession(); $user_id = $session->get('user_id', '', 'tienda_pos'); $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id); $view = $this->getView('pos', 'html'); $view->setModel($model, true); $model->setState('filter_group', $filter_group); $row = $model->getItem(false); $view->assign('product', $row); $view->setLayout('viewproduct'); $dispatcher = JDispatcher::getInstance(); ob_start(); $dispatcher->trigger('onDisplayProductAttributeOptions', array($product_id)); $view->assign('onDisplayProductAttributeOptions', ob_get_contents()); ob_end_clean(); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); return $html; }
<td><?php echo TiendaSelect::btbooleanlist('core_user_change_gid', 'class="inputbox"', $row->product_parameters->get('core_user_change_gid')); ?> </td> </tr> <tr> <td title="<?php echo JText::_('COM_TIENDA_NEW_JOOMLA_ACL') . '::' . JText::_('COM_TIENDA_NEW_JOOMLA_ACL_TIP'); ?> " style="width: 125px; text-align: right;" class="key hasTip"><?php echo JText::_('COM_TIENDA_NEW_JOOMLA_ACL'); ?> :</td> <td><?php Tienda::load('TiendaHelperUser', 'helpers.user'); $helper = new TiendaHelperUser(); echo $helper->getACLSelectList($row->product_parameters->get('core_user_new_gid')); ?> </td> </tr> </table> </div> </div> <?php // fire plugin event here to enable extending the form JDispatcher::getInstance()->trigger('onDisplayProductFormIntegrations', array($row)); ?> <div style="clear: both;"></div>
/** * Saves each individual item in the order to the DB * * @return unknown_type */ protected function saveOrderItems() { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $order = $this->_order; $items = $order->getItems(); if (empty($items) || !is_array($items)) { $this->setError("saveOrderItems:: " . JText::_('COM_TIENDA_ITEMS_ARRAY_INVALID')); return false; } $error = false; $errorMsg = ""; Tienda::load('TiendaHelperUser', 'helpers.user'); foreach ($items as $item) { $item->order_id = $order->order_id; if (!$item->save()) { // track error $error = true; $errorMsg .= $item->getError(); } else { //fire onAfterSaveOrderItem $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterSaveOrderItem', array($item)); // does the orderitem create a subscription? if (!empty($item->orderitem_subscription)) { $date = JFactory::getDate(); // these are only for one-time payments that create subscriptions // recurring payment subscriptions are handled differently - by the payment plugins $subscription = JTable::getInstance('Subscriptions', 'TiendaTable'); $subscription->user_id = $order->user_id; $subscription->order_id = $order->order_id; $subscription->product_id = $item->product_id; $subscription->orderitem_id = $item->orderitem_id; $subscription->transaction_id = ''; // in recurring payments, this is the subscr_id $subscription->created_datetime = $date->toMySQL(); $subscription->subscription_enabled = '0'; // disabled at first, enabled after payment clears switch ($item->subscription_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "I": // expiration date is not important (it's calculated on-the-fly) => create a seemingly lifetime subscription $period_unit = 'YEAR'; $item->subscription_period_interval = '100'; // we dont need to know the interval (we will know the last ID) break; case "D": default: $period_unit = "DAY"; break; } if (!empty($item->subscription_lifetime)) { // set expiration 100 years in future $period_unit = "YEAR"; $item->subscription_period_interval = '100'; $subscription->lifetime_enabled = '1'; } $database = JFactory::getDBO(); $query = " SELECT DATE_ADD('{$subscription->created_datetime}', INTERVAL {$item->subscription_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if ($this->defines->get('display_subnum', 0)) { $subscription->sub_number = TiendaHelperUser::getSubNumber($order->user_id); } if (!$subscription->save()) { $error = true; $errorMsg .= $subscription->getError(); } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'TiendaTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'creation'; $subscriptionhistory->created_datetime = $date->toMySQL(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('COM_TIENDA_NEW_SUBSCRIPTION_CREATED'); $subscriptionhistory->save(); } // Save the attributes also if (!empty($item->orderitem_attributes)) { $attributes = explode(',', $item->orderitem_attributes); foreach (@$attributes as $attribute) { unset($productattribute); unset($orderitemattribute); $productattribute = JTable::getInstance('ProductAttributeOptions', 'TiendaTable'); $productattribute->load($attribute); $orderitemattribute = JTable::getInstance('OrderItemAttributes', 'TiendaTable'); $orderitemattribute->orderitem_id = $item->orderitem_id; $orderitemattribute->productattributeoption_id = $productattribute->productattributeoption_id; $orderitemattribute->orderitemattribute_name = $productattribute->productattributeoption_name; $orderitemattribute->orderitemattribute_price = $productattribute->productattributeoption_price; $orderitemattribute->orderitemattribute_code = $productattribute->productattributeoption_code; $orderitemattribute->orderitemattribute_prefix = $productattribute->productattributeoption_prefix; $orderitemattribute->orderitemattribute_weight = $productattribute->productattributeoption_weight; $orderitemattribute->orderitemattribute_prefix_weight = $productattribute->productattributeoption_prefix_weight; if (!$orderitemattribute->save()) { // track error $error = true; $errorMsg .= $orderitemattribute->getError(); } } } } } if ($error) { $this->setError($errorMsg); return false; } return true; }
private function doSearch($keyword = '', $match = '', $ordering = '', $areas = null) { if (!$this->_isInstalled()) { return array(); } $search_products = $search_wishlists = false; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->doSearchAreas()))) { return array(); } else { if (in_array('tienda', $areas) !== false) { $search_products = true; } if (in_array('wishlist', $areas) !== false) { $search_wishlists = true; } } } else { $search_products = $search_wishlists = true; } $keyword = trim($keyword); if (empty($keyword)) { return array(); } $cache_key = base64_encode(serialize($keyword) . serialize($match) . serialize($ordering) . serialize($areas)) . '.search-results'; $classname = strtolower(get_class($this)); $cache = JFactory::getCache($classname . '.search-results', ''); $cache->setCaching($this->cache_enabled); $cache->setLifeTime($this->cache_lifetime); $list = $cache->get($cache_key); if (empty($list)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $list = array(); $match = strtolower($match); if ($search_products) { $model = JModel::getInstance('Products', 'TiendaModel'); $model->setState('filter_published', 1); $model->setState('filter_enabled', 1); $model->setState('filter_published_date', JFactory::getDate()->toMySQL()); switch ($match) { case 'any': $model->setState('filter_any', $keyword); break; case 'all': $model->setState('filter_all', $keyword); break; case 'exact': default: $model->setState('filter', $keyword); break; } // order the items according to the ordering selected in com_search switch ($ordering) { case 'newest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'DESC'); break; case 'oldest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); break; case 'alpha': case 'popular': default: $model->setState('order', 'tbl.product_name'); break; } // filter according to shopper group Tienda::load('TiendaHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; $model->setState('filter_group', TiendaHelperUser::getUserGroup($user_id)); //display_out_of_stock if (!$this->defines->get('display_out_of_stock')) { $model->setState('filter_quantity_from', '1'); } $items = $model->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->itemid_string = null; $item->itemid = (int) Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($item->product_id, null, true); if (!empty($item->itemid)) { $item->itemid_string = "&Itemid=" . $item->itemid; } $item->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id; $item->href = $item->link . $item->itemid_string; $item->title = $item->product_name; $item->created = $item->created_date; $item->section = $this->params->get('title', "Tienda"); $item->text = $item->product_description; $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'product'; } $list = array_merge($list, $items); } } if ($search_wishlists) { $model = JModel::getInstance('Wishlists', 'TiendaModel'); $model->setState('filter_accessible', 1); $model->setState('filter_user', JFactory::getUser()->id); $model_items = JModel::getInstance('WishlistItems', 'TiendaModel'); if (!empty(JFactory::getUser()->id)) { $model_items->setState('filter_user', JFactory::getUser()->id); } switch ($match) { case 'any': $model->setState('filter_any', $keyword); $model_items->setState('filter_search_any', $keyword); break; case 'all': $model->setState('filter_all', $keyword); $model_items->setState('filter_search_all', $keyword); break; case 'exact': default: $model->setState('filter', $keyword); $model_items->setState('filter_search', $keyword); break; } // order the items according to the ordering selected in com_search switch ($ordering) { case 'newest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'DESC'); break; case 'oldest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); break; case 'alpha': case 'popular': default: $model->setState('order', 'tbl.wishlist_name'); break; } $items = $model->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->href = $item->link = 'index.php?option=com_tienda&view=wishlists&task=view&id=' . $item->wishlist_id; $item->title = $item->wishlist_name; $item->created = $item->created_date; $item->section = $this->params->get('title_wishlist', "Tienda"); $item->text = ''; $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'wishlist'; } $list = array_merge($list, $items); } // now go through wishlist items $items = $model_items->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->customer = $item->first_name . ' '; if (empty($item->middle_name)) { $item->customer .= $item->middle_name . ' '; } $item->customer .= $item->last_name; if (!strlen(trim($item->customer))) { $item->customer = $item->user_joomla_name; } $item->customer_link = 'index.php?option=com_users&view=profile&id=' . $item->user_id; $item->href = $item->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id; $item->title = $item->product_name; $item->created = $item->created_date; $item->section = $this->params->get('title_wishlist', "Tienda"); if (strlen($item->product_attributes)) { $attributes = explode(',', $item->product_attributes); $tbl = JTable::getInstance('ProductAttributes', 'TiendaTable'); $tbl_opt = JTable::getInstance('ProductAttributeOptions', 'TiendaTable'); $attr_list = array(); for ($i = 0, $c = count($attributes); $i < $c; $i++) { $tbl_opt->load($attributes[$i]); $tbl->load($tbl_opt->productattribute_id); $item->href .= '&attribute_' . $tbl_opt->productattribute_id . '=' . $attributes[$i]; $attr_list[] = $tbl->productattribute_name . ': ' . $tbl_opt->productattributeoption_name; } $item->text = implode('<br>', $attr_list); } else { $item->text = $item->product_name; } $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'wishlistitem'; } $list = array_merge($list, $items); } } $cache->store($list, $cache_key); } return $list; }
public function submitOrder() { $this->setFormat(); $session = JFactory::getSession(); $response = $this->getResponseObject(); $values = JRequest::get('post'); // Prep the post if (!empty($this->user->id)) { $values["user_id"] = $this->user->id; $values["email_address"] = $this->user->email; $values["checkout_method"] = null; } else { $userHelper = new TiendaHelperUser(); $values["user_id"] = $userHelper->getNextGuestUserId(); } $values['ip_address'] = $_SERVER['REMOTE_ADDR']; $values["sameasbilling"] = !empty($values["shipping_input_same_as_billing"]) ? $values["shipping_input_same_as_billing"] : false; if ($shippingMethod = unserialize($session->get('tienda.opc.shippingMethod'))) { $values['shipping_plugin'] = $shippingMethod['element']; $values['shipping_price'] = $shippingMethod['price']; $values['shipping_extra'] = $shippingMethod['extra']; $values['shipping_name'] = $shippingMethod['name']; $values['shipping_tax'] = $shippingMethod['tax']; $values['shipping_code'] = $shippingMethod['code']; } $values['coupons'] = array(); if ($userCoupons = unserialize($session->get('tienda.opc.userCoupons'))) { foreach ($userCoupons as $coupon) { $values['coupons'][] = $coupon->coupon_id; } } if ($userCredit = unserialize($session->get('tienda.opc.userCredit'))) { $values['order_credit'] = $userCredit; } if (empty($values['currency_id'])) { Tienda::load('TiendaHelperCurrency', 'helpers.currency'); $values['currency_id'] = TiendaHelperCurrency::getCurrentCurrency(); } $model = $this->getModel('orders'); $errorMessage = ''; if (!($validate = $model->validate($values))) { $errorMessage = '<ul class="text-error">'; foreach ($model->getErrors() as $error) { $errorMessage .= "<li>" . $error . "</li>"; } $errorMessage .= '</ul>'; $response->goto_section = 'review'; $response->summary->html = $errorMessage; echo json_encode($response); return; } $options = array(); $options["save_addresses"] = true; if (!($order = $model->save($values, $options))) { $errorMessage = '<ul class="text-error">'; foreach ($model->getErrors() as $error) { $errorMessage .= "<li>" . $error . "</li>"; } $errorMessage .= '</ul>'; $response->goto_section = 'review'; $response->summary->html = $errorMessage; echo json_encode($response); return; } $this->_order = $order; if (!($html = $this->getPreparePaymentForm($values, $options, $order))) { $errorMessage = '<ul class="text-error">'; $errorMessage .= "<li>" . $this->getError() . "</li>"; $errorMessage .= '</ul>'; // get and return the error for display to the user $response->goto_section = 'review'; $response->summary->html = $errorMessage; echo json_encode($response); return; } if ($html == 'free') { $itemid = $this->router->findItemid(array('view' => 'opc')); if (empty($itemid)) { $itemid = $this->router->findItemid(array('view' => 'checkout')); if (empty($itemid)) { $itemid = JRequest::getInt('Itemid'); } } $response->redirect = JRoute::_('index.php?option=com_tienda&view=opc&task=confirmPayment&Itemid=' . $itemid); echo json_encode($response); return; } $response->summary->id = 'opc-payment-prepayment'; $response->summary->html = $html; $response->goto_section = 'prepare-payment'; echo json_encode($response); return; }
/** * Set basic properties for the item, whether in a list or a singleton * * @param unknown_type $item * @param unknown_type $key * @param unknown_type $refresh */ protected function prepareItem(&$item, $key = 0, $refresh = false) { Tienda::load("TiendaHelperProduct", 'helpers.product'); Tienda::load('TiendaHelperSubscription', 'helpers.subscription'); $helper_product = new TiendaHelperProduct(); if (!empty($item->product_recurs)) { $item->recurring_price = $item->price; if ($item->subscription_prorated) { Tienda::load('TiendaHelperSubscription', 'helpers.subscription'); $result = TiendaHelperSubscription::calculateProRatedTrial($item->subscription_prorated_date, $item->subscription_prorated_term, $item->recurring_period_unit, $item->recurring_trial_price, $item->subscription_prorated_charge); $item->price = $result['price']; $item->prorated_price = $result['price']; $item->prorated_interval = $result['interval']; $item->prorated_unit = $result['unit']; // $item->recurring_trial = $result['trial']; } else { if (!empty($item->recurring_trial)) { $item->price = $item->recurring_trial_price; } } } $user_id = $this->getState('user.id', 0); $qty = $this->getState('product.qty', -1); if ($qty > -1) { $user_group = TiendaHelperUser::getUserGroup($user_id, $item->product_id); $price = TiendaHelperProduct::getPrice($item->product_id, $qty, $user_group); $item->price = $price->product_price; } $item->product_parameters = new DSCParameter($item->product_params); $item->slug = $item->product_alias ? ":{$item->product_alias}" : ""; $item->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id; $item->link_edit = 'index.php?option=com_tienda&view=products&task=edit&id=' . $item->product_id; $item->product_categories = $this->getCategories($item->product_id); $item->default_attributes = $helper_product->getDefaultAttributes($item->product_id); $item->product_classes = null; foreach ($item->product_categories as $cat) { $item->product_classes .= " " . $cat->category_alias; } if (!empty($item->product_class_suffix)) { $item->product_classes .= " " . $item->product_class_suffix; } $item->product_classes = trim($item->product_classes); parent::prepareItem($item, $key, $refresh); }
/** * Gets an existing user or creates a new one * * @param array $submitted_values Data for a new user * @param int $user_id Existing user id (optional) * @return JUser object * @access protected */ function _getUser($submitted_values, $user_id = 0) { $config = Tienda::getInstance(); if ($user_id) { $user = JFactory::getUser($user_id); } else { $user = JFactory::getUser(); } if ($user->id) { return $user; } Tienda::load('TiendaHelperUser', 'helpers.user'); $newuser_email = $submitted_values['CustomerEMail']; // create user from email jimport('joomla.user.helper'); $details['name'] = $newuser_email; $details['username'] = $newuser_email; $details['email'] = $newuser_email; $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $details['block'] = $config->get('block_automatically_registered') ? '1' : '0'; if ($user = TiendaHelperUser::createNewUser($details)) { if (!$config->get('block_automatically_registered')) { // login the new user $login = TiendaHelperUser::login($details, '1'); } // indicate that user was registed by AS automatically $user->set('automatically_registered', true); } return $user; }
public function save($values, $options = array()) { $result = new stdClass(); $result->error = false; Tienda::load('TiendaHelperUser', 'helpers.user'); $userHelper = new TiendaHelperUser(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $userinfo = JTable::getInstance('UserInfo', 'TiendaTable'); $user_id = $values["user_id"]; $create_account = $values["checkout_method"] == 'register' ? true : false; $guest_checkout = $this->defines->get('guest_checkout_enabled', '1'); if ($values["checkout_method"] == "guest") { // save the real user info in the userinfo table $userinfo->user_id = $user_id; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } // save the billing and shipping addresses? //$this->setAddresses($submitted_values, true, true); } elseif ($values["checkout_method"] == "register") { // create a new user from billing info $details = array('email' => $values['email_address'], 'name' => @$values['billing_input_first_name'] . ' ' . @$values['billing_input_middle_name'] . ' ' . @$values['billing_input_last_name'], 'username' => $values['email_address']); if (strlen(trim($details['name'])) == 0) { $details['name'] = JText::_('COM_TIENDA_USER'); } $details['password'] = $values["register-new-password"]; $details['password2'] = $values["register-new-password2"]; if (!($user = $userHelper->createNewUser($details, false))) { $result->error = true; //$this->setError( $user->getError() ); } else { $userHelper->login(array('username' => $user->username, 'password' => $details['password'])); $user_id = $user->id; $userinfo->load(array('user_id' => $user_id)); $userinfo->user_id = $user_id; $userinfo->first_name = @$values['billing_input_first_name']; $userinfo->last_name = @$values['billing_input_last_name']; $userinfo->company = @$values['billing_input_company']; $userinfo->middle_name = @$values['billing_input_middle_name']; $userinfo->phone_1 = @$values['billing_input_phone_1']; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } } } $result->user_id = $user_id; $result->userinfo = $userinfo; $this->result = $result; DSCModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); $model = DSCModel::getInstance('Userinfo', 'TiendaModel'); $model->clearCache(); if ($result->error) { return false; } return $result; }
/** * Get the cart button form for a specific product * * @param int $product_id The id of the product * @return html The add to cart form */ public static function getCartButton($product_id, $layout = 'product_buy', $values = array(), &$callback_js = '') { if (is_array($values) && !count($values)) { $values = JRequest::get('request'); } $html = ''; $page = JRequest::getVar('page', 'product'); $isPOS = $page == 'pos'; if ($isPOS) { JLoader::register("TiendaViewPOS", JPATH_ADMINISTRATOR . "/components/com_tienda/views/pos/view.html.php"); $view = new TiendaViewPOS(); } else { JLoader::register("TiendaViewProducts", JPATH_SITE . "/components/com_tienda/views/products/view.html.php"); $view = new TiendaViewProducts(); } $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId($product_id); $model->setState('task', 'product_buy'); Tienda::load('TiendaHelperBase', 'helpers._base'); $helper_product = TiendaHelperBase::getInstance('Product'); Tienda::load('TiendaHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; if ($isPOS) { $user_id = JRequest::getInt('user_id', $user_id); } $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id); $qty = isset($values['product_qty']) && !empty($values['product_qty']) ? $values['product_qty'] : 1; $model->setState('filter_group', $filter_group); $model->setState('product.qty', $qty); $model->setState('user.id', $user_id); $row = $model->getItem(false, true, false); if ($row->product_notforsale || Tienda::getInstance()->get('shop_enabled') == '0') { return $html; } // This enable this helper method to be used outside of tienda if ($isPOS) { $view->set('_controller', 'pos'); $view->set('_view', 'pos'); } else { $view->addTemplatePath(JPATH_SITE . '/components/com_tienda/views/products/tmpl'); $view->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication('site')->getTemplate() . '/html/com_tienda/products/'); // add extra templates $view->addTemplatePath(Tienda::getPath('product_buy_templates')); $view->set('_controller', 'products'); $view->set('_view', 'products'); } $view->set('_doTask', true); $view->set('hidemenu', true); $view->setModel($model, true); $view->setLayout($layout); $view->product_id = $product_id; $view->values = $values; $filter_category = $model->getState('filter_category', JRequest::getInt('filter_category', (int) @$values['filter_category'])); $view->filter_category = $filter_category; if ($isPOS) { $view->validation = "index.php?option=com_tienda&view=pos&task=validate&format=raw"; } else { $view->validation = "index.php?option=com_tienda&view=products&task=validate&format=raw"; } $config = Tienda::getInstance(); // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $view->shipping_cost_link = $shipping_cost_link; } $quantity_min = 1; if ($row->quantity_restriction) { $quantity_min = $row->quantity_min; } $invalidQuantity = '0'; $attributes = array(); $attr_orig = array(); if (empty($values)) { $product_qty = $quantity_min; // get the default set of attribute_csv if (!isset($row->default_attributes)) { $default_attributes = $helper_product->getDefaultAttributes($product_id); } else { $default_attributes = $row->default_attributes; } sort($default_attributes); $attributes_csv = implode(',', $default_attributes); $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } $attr_orig = $attributes = $default_attributes; } else { $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : $quantity_min; // TODO only display attributes available based on the first selected attribute? foreach ($values as $key => $value) { if (substr($key, 0, 10) == 'attribute_') { if (empty($value)) { $attributes[$key] = 0; } else { $attributes[$key] = $value; } } } if (!count($attributes)) { // no attributes are selected -> use default if (!isset($row->default_attributes)) { $attributes = $helper_product->getDefaultAttributes($product_id); } else { $attributes = $row->default_attributes; } } $attr_orig = $attributes; sort($attributes); // Add 0 to attributes to include all the root attributes //$attributes[] = 0;//remove this one. its causing the getAvailableQuantity to not get quantity because of wrong csv // For getting child opts $view->selected_opts = json_encode(array_merge($attributes, array('0'))); $attributes_csv = implode(',', $attributes); // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } // adjust the displayed price based on the selected or default attributes TiendaHelperProduct::calculateProductAttributeProperty($row, $attr_orig, 'price', 'product_weight'); $show_tax = $config->get('display_prices_with_tax'); $show_product = $config->get('display_category_cartbuttons'); $view->show_tax = $show_tax; $row->tax = '0'; $row->taxtotal = '0'; if ($show_tax) { // finish TiendaHelperUser::getGeoZone -- that's why this isn't working Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones_user = TiendaHelperUser::getGeoZones($user_id); if (empty($geozones_user)) { $geozones = array(Tienda::getInstance()->get('default_tax_geozone')); } else { $geozones = array(); foreach ($geozones_user as $value) { $geozones[] = $value->geozone_id; } } Tienda::load('TiendaHelperTax', 'helpers.tax'); $product = new stdClass(); $product->product_price = $row->price; $product->product_id = $product_id; $tax = TiendaHelperTax::calculateGeozonesTax(array($product), 2, $geozones); $row->taxtotal = $tax->tax_total; $row->tax = $tax->tax_total; } $row->_product_quantity = $product_qty; if ($page == 'product' || $isPOS) { $display_cartbutton = Tienda::getInstance()->get('display_product_cartbuttons', '1'); } else { $display_cartbutton = Tienda::getInstance()->get('display_category_cartbuttons', '1'); } $view->page = $page; $view->display_cartbutton = $display_cartbutton; $view->availableQuantity = $availableQuantity; $view->invalidQuantity = $invalidQuantity; if ($isPOS) { $view->product = $row; } else { $view->item = $row; } $dispatcher = JDispatcher::getInstance(); ob_start(); $dispatcher->trigger('onDisplayProductAttributeOptions', array($row->product_id)); $view->onDisplayProductAttributeOptions = ob_get_contents(); ob_end_clean(); $html = $view->loadTemplate(); if (isset($view->callback_js) && !empty($view->callback_js)) { $callback_js = $view->callback_js; } return $html; }
/** * Gets a product's add to cart section * formatted for display * * @param int $address_id * @return string html */ private function getAddToCart($product_id, $values = array(), $params = array()) { $html = ''; Tienda::load('TiendaModelProducts', 'models.products'); $model = JModel::getInstance('Products', 'TiendaModel'); $user = JFactory::getUser(); Tienda::load('TiendaHelperUser', 'helpers.user'); $filter_group = TiendaHelperUser::getUserGroup($user->id, $product_id); $model->setState('filter_group', $filter_group); $model->setId($product_id); $row = $model->getItem(false); $vars = new JObject(); if (@$row->product_notforsale || Tienda::getInstance()->get('shop_enabled') == '0') { return $html; } $vars->item = $row; $vars->product_id = $product_id; $vars->values = $values; $vars->validation = "index.php?option=com_tienda&view=products&task=validate&format=raw"; $vars->params = $params; $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $vars->show_tax = $show_tax; $vars->tax = 0; $vars->taxtotal = ''; $vars->shipping_cost_link = ''; if ($show_tax) { // finish TiendaHelperUser::getGeoZone -- that's why this isn't working Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } $taxtotal = TiendaHelperProduct::getTaxTotal($product_id, $geozones); $tax = $taxtotal->tax_total; $vars->taxtotal = $taxtotal; $vars->tax = $tax; } // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $vars->shipping_cost_link = $shipping_cost_link; } $invalidQuantity = '0'; if (empty($values)) { $product_qty = '1'; // get the default set of attribute_csv $default_attributes = TiendaHelperProduct::getDefaultAttributes($product_id); sort($default_attributes); $attributes_csv = implode(',', $default_attributes); $availableQuantity = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } if (!empty($values)) { $product_id = !empty($values['product_id']) ? (int) $values['product_id'] : JRequest::getInt('product_id'); $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : '1'; // TODO only display attributes available based on the first selected attribute? $attributes = array(); foreach ($values as $key => $value) { if (substr($key, 0, 10) == 'attribute_') { $attributes[] = $value; } } sort($attributes); $attributes_csv = implode(',', $attributes); // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } $vars->availableQuantity = $availableQuantity; $vars->invalidQuantity = $invalidQuantity; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('tienda'); ob_start(); $dispatcher->trigger('onDisplayProductAttributeOptions', array($product_id)); $vars->onDisplayProductAttributeOptions = ob_get_contents(); ob_end_clean(); ob_start(); echo $this->_getLayout('product_buy', $vars); $html = ob_get_contents(); ob_end_clean(); return $html; }
Tienda::load('TiendaHelperCarts', 'helpers.carts'); $items = TiendaHelperCarts::getProductsInfo(); $num = count($items); // Convert the cart to a "fake" order, to show totals and others things JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderTable = JTable::getInstance('Orders', 'TiendaTable'); foreach ($items as $item) { $orderTable->addItem($item); } $items = $orderTable->getItems(); Tienda::load('Tienda', 'defines'); $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); if ($show_tax) { Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } $orderTable->setGeozones($geozones); } // order calculation can happen after all items are added to order object $orderTable->calculateTotals(); // format the subtotal //$order_subtotal = TiendaHelperBase::currency($orderTable->order_total); if (!empty($items) || empty($items) && $params->get('display_null')) { require JModuleHelper::getLayoutPath('mod_tienda_cart', $params->get('layout', 'default')); } else {
/** * Calculate taxes on list of products * * @param $products Array of products * @param $source Source of tax calculation (final_price '1', product_price '2', orderitem_price '3') * @param $billing_address Actual customer's billing address * @param $shipping_address Actual customer's shipping address * @param $tax_type for the future use * * @return Associative array with indexes product_id of products with arrays with list of their tax rates (names and rates) */ public static function calculateTax($products, $source = 1, $billing_address = null, $shipping_address = null, $tax_type = null) { $result = new stdClass(); $result->tax_total = 0.0; $result->tax_rate_rates = array(); $result->tax_class_rates = array(); $result->product_taxes = array(); if (!is_array($products)) { return $result; } Tienda::load('TiendaHelperShipping', 'helpers.shipping'); Tienda::load('TiendaQuery', 'library.query'); Tienda::load('TiendaTools', 'library.tools'); if ($billing_address) { $billing_zones = TiendaHelperShipping::getGeoZones($billing_address->zone_id, '1', $billing_address->postal_code); } else { $billing_zones = array(); } if (!empty($billing_zones)) { foreach ($billing_zones as $key => $value) { $billing_zones[$key] = $value->geozone_id; } } //load the default geozones when user is logged out and the config is to show tax if (empty($billing_zones)) { $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $billing_zones = array(Tienda::getInstance()->get('default_tax_geozone')); } else { foreach ($geozones as $key => $value) { $billing_zones[$key] = $value->geozone_id; } } } return TiendaHelperTax::calculateGeozonesTax($products, $source, $billing_zones); }
/** * Gets a product's add to cart section * formatted for display * * @param int $address_id * @return string html */ function getAddToCart($product_id, $values = array()) { $layout = 'product_buy'; Tienda::load('TiendaHelperProduct', 'helpers.product'); if (isset($values['layout'])) { $layout = $values['layout']; } JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId($product_id); $user_id = JFactory::getUser()->id; $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id); $qty = JRequest::getInt('product_qty', 1); $model->setState('filter_group', $filter_group); $model->setState('product.qty', $qty); $model->setState('user.id', $user_id); $row = $model->getItem(false, false, false); $buy_layout_override = $row->product_parameters->get('product_buy_layout_override'); if (!empty($buy_layout_override)) { $layout = $buy_layout_override; } $html = TiendaHelperProduct::getCartButton($product_id, $layout, $values, $this->_callback_js); return $html; }