public static function sendUserEmail($user_id, $order_id, $payment_status, $order_status, $order_state_id) { $mainframe = JFactory::getApplication(); $config = JFactory::getConfig(); $j2params = JComponentHelper::getParams('com_j2store'); if (version_compare(JVERSION, '3.0', 'ge')) { $sitename = $config->get('sitename'); } else { $sitename = $config->getValue('config.sitename'); } //now get the order table's id based on order id $order = J2StoreOrdersHelper::_getOrderKey($order_id); //inventory //TODO::move this function to the plugin. require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php'; require_once JPATH_ADMINISTRATOR . '/components/com_j2store/version.php'; J2StoreInventory::setInventory($order->id, $order_state_id); $mainframe->triggerEvent('onJ2StoreBeforeOrderNotification', array($order)); //now get the receipient $recipient = J2StoreOrdersHelper::_getRecipient($order->order_id); //check for email templates. If it is there, get the orderemail from there require_once JPATH_SITE . '/components/com_j2store/helpers/email.php'; $emailHelper = new J2StoreHelperEmail(); $orderObj = self::getOrder($order->id); if (count($emailHelper->getEmailTemplates($orderObj)) && J2STORE_PRO == 1) { $mailer = $emailHelper->getEmail($orderObj); } else { if ($user_id && empty($recipient->billing_first_name)) { $recipient->name = JFactory::getUser($user_id)->name; } else { $recipient->name = $recipient->billing_first_name . ' ' . $recipient->billing_last_name; } $body = J2StoreOrdersHelper::_getHtmlFormatedOrder($order->id, $user_id); $subject = JText::sprintf('J2STORE_ORDER_USER_EMAIL_SUB', $recipient->name, $sitename); $mailer = clone JFactory::getMailer(); $mailer->IsHTML(true); $mailer->CharSet = 'UTF-8'; $mailer->setSubject($subject); $mailer->setBody($body); } $admin_emails = $j2params->get('admin_email'); $admin_emails = explode(',', $admin_emails); if (version_compare(JVERSION, '3.0', 'ge')) { $mailfrom = $j2params->get('emails_defaultemail', $config->get('mailfrom')); $fromname = $j2params->get('emails_defaultname', $config->get('fromname')); } else { $mailfrom = $j2params->get('emails_defaultemail', $config->getValue('config.mailfrom')); $fromname = $j2params->get('emails_defaultname', $config->getValue('config.fromname')); } //send email if ($recipient) { $mailer->addRecipient($recipient->user_email); // $mailer->addBCC( $admin_emails ); $mailer->setSender(array($mailfrom, $fromname)); $mailer->send(); $mailer = null; } if ($admin_emails) { if (count($emailHelper->getEmailTemplates($orderObj)) && J2STORE_PRO == 1) { $mailer = $emailHelper->getEmail($orderObj); } else { $mailer = clone JFactory::getMailer(); $mailer->IsHTML(true); $mailer->CharSet = 'UTF-8'; $mailer->setSubject($subject); $mailer->setBody($body); } $mailer->addRecipient($admin_emails); $mailer->setSender(array($mailfrom, $fromname)); $mailer->send(); $mailer = null; } $mainframe->triggerEvent('onJ2StoreAfterOrderNotification', array($order)); return true; }
public function hasProductStock($product_id, $options = array(), $qty = 0, $key = '', $isTotal = false, $type = "update", $original_qty = 0) { $params = JComponentHelper::getParams('com_j2store'); $status = true; $inventory = new J2StoreInventory(); //check if backorder is enabled. If yes, then return true if ($params->get('allow_backorder', 0)) { return $status; } //get the existing cart items $products = $this->getDataNew(); //get existing items in a CSV format $allOptions = $this->getAllAttributes($products); if ($type == 'add' || $type == 'update') { //this request either comes from adding a product to cart or update if (count($options)) { $options = $this->cleanAttributes($options, $product_id); } } $attributes_csv = ''; if (count($options)) { $attribs = $options; sort($attribs); $attributes_csv = implode(',', $attribs); } //echo $attributes_csv; //when we recheck options, we need to get the correct quantity if ($type == 'update') { $difference = $qty - $original_qty; if (count($options)) { if (isset($allOptions[$attributes_csv])) { $existing_qty = $allOptions[$attributes_csv]; $qty = $existing_qty + $difference; } } } // get the right quantity for checking if ($type == 'add') { if (count($options)) { if (isset($allOptions[$attributes_csv])) { $qty = $allOptions[$attributes_csv] + $qty; } } else { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product_id) { $product_total += $product_2['quantity']; } } $qty = $product_total + $qty; } } $availableQuantity = J2StoreInventory::getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->manage_stock && $qty > $availableQuantity->quantity) { $status = false; } else { $status = true; } return $status; }
/** * Method to getItem * @params type int id * @result products */ public function getItem() { $id = $this->getId(); $product = J2StoreHelperCart::getItemInfo($id); //set the correct quantity if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) { $product->product_quantity = (int) $product->min_sale_qty; $product->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty); } else { $product->product_quantity = 1; } //include the model file path JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); //create obj for cartmodel class $cart_model = JModelLegacy::getInstance('Mycart', 'J2StoreModel'); //now get the productoptions based on the id $attributes = $cart_model->getProductOptions($id); //let calcuate the product option based on the stock if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1) { //get unavailable attribute options $attributes = $cart_model->processAttributeOptions($attributes, $product); } //assign the attributes $product->attributes = $attributes; //assign th prices $product->prices = J2StorePrices::getPrice($id, $product->product_quantity); if (J2STORE_PRO == 1 && $product->manage_stock == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel'); $qtyModel->setState('filter_product', $product->product_id); $qtyModel->setState('filter_productid', $product->product_id); $product->option_stock = $qtyModel->getList(); $product->product_stock = $qtyModel->getQuantityTotal(); } else { $product->product_stock = 99; } $product->product = $product; $product->inventory = J2StoreInventory::isAllowed($product); //get all tags if (version_compare(JVERSION, '3.0', 'ge')) { $product->product_tags = $this->getProductTags($id); } $this->executePlugins($product); return $product; }
require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php'; require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/select.php'; require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php'; $action = JRoute::_('index.php?option=com_j2store&view=mycart'); if ($item->attribs) { $registry = new JRegistry(); $registry->loadString($item->attribs); $attribs = $registry->toObject(); } if (isset($attribs->item_cart_text) && JString::strlen($attribs->item_cart_text) > 0) { $cart_text = $attribs->item_cart_text; } else { $cart_text = JText::_('J2STORE_ADD_TO_CART'); } //Check for stock before displaying $inventoryCheck = J2StoreInventory::isAllowed($item); ?> <div id="j2store-product-<?php echo $item->product_id; ?> " class="j2store j2store-product-info"> <?php if (count(JModuleHelper::getModules('j2store-addtocart-top')) > 0) { ?> <div class="j2store_modules"> <?php echo J2StoreHelperModules::loadposition('j2store-addtocart-top'); ?> </div> <?php
public static function isAllowed($item, $qty = 1, $attributes_csv = '') { $params = JComponentHelper::getParams('com_j2store'); //set the result object $result = new JObject(); $result->backorder = false; //we always want to allow users to buy. so initialise to 1. $result->can_allow = 1; //if basic version return true if (J2STORE_PRO != 1) { $result->can_allow = 1; return $result; } //first check if global inventory is enabled. if (!$params->get('enable_inventory', 0)) { //if not enabled, allow adding and return here $result->can_allow = 1; return $result; } //global inventory enabled. Now check at the product level. if (isset($item->product->stock) && is_object($item->product->stock)) { $stock = $item->product->stock; } elseif (isset($item->product->manage_stock) && is_object($item->product)) { $stock = $item->product; } else { $stock = J2StoreInventory::getStock($item->product_id); } if ((int) $stock->manage_stock < 1) { //Stock disabled. Return true $result->can_allow = 1; return $result; } if (empty($attributes_csv)) { $model = new J2StoreModelMyCart(); //get attributes $attributes = $model->getProductOptions($item->product_id); $list = array(); foreach ($attributes as $option) { if ($option['type'] == 'select' || $option['type'] == 'radio') { $option['product_option_id']; //get the default attributes foreach ($option['optionvalue'] as $optionvalue) { if ($optionvalue['product_optionvalue_default']) { //we have a default option $list[$option['product_option_id']] = $optionvalue['product_optionvalue_id']; } } if (empty($list[$option['product_option_id']])) { $list[$option['product_option_id']] = $option['optionvalue'][0]['product_optionvalue_id']; } } } sort($list); $attributes_csv = implode(',', $list); } $availableQuantity = J2StoreInventory::getAvailableQuantity($item->product_id, $attributes_csv); if ($availableQuantity->manage_stock && $qty > $availableQuantity->quantity) { $result->can_allow = 0; } $quantity_min = 1; if ($stock->min_out_qty) { $quantity_min = $stock->min_out_qty; } if ($quantity_min >= $availableQuantity->quantity) { $result->can_allow = 0; } if ($availableQuantity->quantity <= 0) { $result->can_allow = 0; } //TODO:: is there a better way of doing this. We are checking the product's total stock if ($item->product_stock > 0) { $result->can_allow = 1; } else { $result->can_allow = 0; } //if backorder is allowed, set it and override to allow adding if ($params->get('enable_inventory', 0) && $params->get('allow_backorder', 0)) { $result->backorder = true; } return $result; }
function billing_address() { $app = JFactory::getApplication(); $address = $this->getModel('address')->getSingleAddressByUserID(); $view = $this->getView('checkout', 'html'); $model = $this->getModel('checkout'); $cart_model = $this->getModel('mycart'); $link = JRoute::_('index.php?option=com_j2store&view=mycart'); $products = $cart_model->getDataNew(); try { J2StoreInventory::validateQuantityRestrictions($products); } catch (Exception $e) { $app->redirect($link, $e->getMessage()); } //get the billing address id from the session if ($this->session->has('billing_address_id', 'j2store')) { $billing_address_id = $this->session->get('billing_address_id', '', 'j2store'); } else { $billing_address_id = isset($address->id) ? $address->id : ''; } $view->assign('address_id', $billing_address_id); if ($this->session->has('billing_country_id', 'j2store')) { $billing_country_id = $this->session->get('billing_country_id', '', 'j2store'); } else { $billing_country_id = isset($address->country_id) ? $address->country_id : ''; } if ($this->session->has('billing_zone_id', 'j2store')) { $billing_zone_id = $this->session->get('billing_zone_id', '', 'j2store'); } else { $billing_zone_id = isset($address->zone_id) ? $address->zone_id : ''; } $view->assign('zone_id', $billing_zone_id); //get all address $addresses = $this->getModel('address')->getAddresses(); $view->assign('addresses', $addresses); $selectableBase = J2StoreFactory::getSelectableBase(); $view->assign('fieldsClass', $selectableBase); $address_table = JTable::getInstance('address', 'Table'); $fields = $selectableBase->getFields('billing', $address, 'address'); $view->assign('fields', $fields); $view->assign('address', $address_table); //get layout settings $view->assign('storeProfile', J2StoreHelperCart::getStoreAddress()); $view->setLayout('checkout_billing'); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); echo $html; $app->close(); }
function orderstatesave() { $app = JFactory::getApplication(); $id = $app->input->getInt('id', 0); $order_state_id = $app->input->getInt('order_state_id', 0); $notify_customer = $app->input->getInt('notify_customer', 0); if (isset($order_state_id) && $order_state_id > 0) { require_once JPATH_ADMINISTRATOR . '/components/com_j2store/models/orderstatuses.php'; $os_model = new J2StoreModelOrderstatuses(); $order_state = $os_model->getOrderStateByID($order_state_id)->orderstatus_name; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $order = JTable::getInstance('Orders', 'Table'); $order->load($id); if ($order->id == $id) { //lets change the status $order->order_state = $order_state; $order->order_state_id = $order_state_id; if ($order->store()) { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_SUCCESSFUL'); if (isset($notify_customer) && $notify_customer == 1) { require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id); } else { require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php'; J2StoreInventory::setInventory($order->id, $order_state_id); } } else { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_FAILED'); } } else { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_FAILED'); } } else { $msg = JText::_('J2STORE_CHOOSE_AN_ORDER_STATUS'); } $link = 'index.php?option=com_j2store&view=orders&task=view&id=' . $order->id; $return = $app->input->getString('return'); if (isset($return) && !empty($return)) { $json = array(); $json['success']['link'] = 'index.php?option=com_j2store&view=orders'; echo json_encode($json); $app->close(); } else { $this->setRedirect($link, $msg); } }