示例#1
0
文件: checkout.php 项目: A-Bush/pprod
 function guest()
 {
     $app = JFactory::getApplication();
     $cart_model = $this->getModel('mycart');
     $view = $this->getView('checkout', 'html');
     $model = $this->getModel('checkout');
     $this->session->set('uaccount', 'guest', 'k2store');
     //check inventory
     $products = $cart_model->getDataNew();
     try {
         K2StoreInventory::validateQuantityRestrictions($products);
     } catch (Exception $e) {
         $app->redirect($link, $e->getMessage());
     }
     //set guest varibale to session as the array, if it does not exist
     if (!$this->session->has('guest', 'k2store')) {
         $this->session->set('guest', array(), 'k2store');
     }
     $guest = $this->session->get('guest', array(), 'k2store');
     $data = array();
     $selectableBase = new K2StoreSelectableBase();
     $view->assign('fieldsClass', $selectableBase);
     $address = JTable::getInstance('address', 'Table');
     if (empty($guest['billing']['zip']) && $this->session->has('billing_postcode', 'k2store')) {
         $guest['billing']['zip'] = $this->session->get('billing_postcode', '', 'k2store');
     }
     if (empty($guest['billing']['country_id']) && $this->session->has('billing_country_id', 'k2store')) {
         $guest['billing']['country_id'] = $this->session->get('billing_country_id', '', 'k2store');
     }
     if (empty($guest['billing']['zone_id']) && $this->session->has('billing_zone_id', 'k2store')) {
         $guest['billing']['zone_id'] = $this->session->get('billing_zone_id', '', 'k2store');
     }
     //bind the guest data to address table if it exists in the session
     if (isset($guest['billing']) && count($guest['billing'])) {
         $address->bind($guest['billing']);
     }
     $fields = $selectableBase->getFields('guest', $address, 'address');
     $view->assign('fields', $fields);
     $view->assign('address', $address);
     //get layout settings
     $storeProfile = K2StoreHelperCart::getStoreAddress();
     $view->assign('storeProfile', K2StoreHelperCart::getStoreAddress());
     $showShipping = false;
     if ($this->params->get('show_shipping_address', 0)) {
         $showShipping = true;
     }
     if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) {
         $showShipping = true;
     }
     $view->assign('showShipping', $showShipping);
     $data['shipping_required'] = $showShipping;
     if (isset($guest['shipping_address'])) {
         $data['shipping_address'] = $guest['shipping_address'];
     } else {
         $data['shipping_address'] = true;
     }
     $view->assign('data', $data);
     $view->setLayout('checkout_guest');
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     echo $html;
     $app->close();
 }
示例#2
0
# Websites: http://k2store.org
# Technical Support:  Forum - http://k2store.org/forum/index.html
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');
$item = @$this->item;
$formName = 'k2storeadminForm_' . $item->product_id;
require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/select.php';
require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
if (isset($this->product->item_cart_text) && JString::strlen($this->product->item_cart_text) > 0) {
    $cart_text = $this->product->item_cart_text;
} else {
    $cart_text = JText::_('K2STORE_ADD_TO_CART');
}
$inventoryCheck = K2StoreInventory::isAllowed($item);
$action = JRoute::_('index.php?option=com_k2store&view=mycart');
?>

<div id="k2store-product-<?php 
echo $item->product_id;
?>
" class="k2store k2store-product-info">
<?php 
if (count(JModuleHelper::getModules('k2store-addtocart-top')) > 0) {
    ?>
	<div class="k2store_modules">
		<?php 
    echo K2StoreHelperModules::loadposition('k2store-addtocart-top');
    ?>
	</div>
示例#3
0
文件: orders.php 项目: A-Bush/pprod
 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);
     // $status_values = array(1 => JText::_('K2STORE_Confirmed'), 3 => JText::_('K2STORE_Failed'), 4 => JText::_('K2STORE_Pending'));
     if (isset($order_state_id) && $order_state_id > 0) {
         require_once JPATH_ADMINISTRATOR . '/components/com_k2store/models/orderstatuses.php';
         $os_model = new K2StoreModelOrderstatuses();
         $order_state = $os_model->getOrderStateByID($order_state_id)->orderstatus_name;
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/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::_('K2STORE_ORDER_STATUS_UPDATE_SUCCESSFUL');
                 if (isset($notify_customer) && $notify_customer == 1) {
                     require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
                     K2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id);
                 } else {
                     require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
                     K2StoreInventory::setInventory($order->id, $order_state_id);
                 }
             } else {
                 $msg = JText::_('K2STORE_ORDER_STATUS_UPDATE_FAILED');
             }
         } else {
             $msg = JText::_('K2STORE_ORDER_STATUS_UPDATE_FAILED');
         }
     } else {
         $msg = JText::_('K2STORE_CHOOSE_AN_ORDER_STATUS');
     }
     $link = 'index.php?option=com_k2store&view=orders&task=view&id=' . $order->id;
     $this->setRedirect($link, $msg);
 }
示例#4
0
文件: mycart.php 项目: A-Bush/pprod
 function hasMaximumQuantity($product, $qty = 1, $isTotal = false)
 {
     //first get the minimum restriction
     $stock = K2StoreInventory::getStock($product->product_id);
     //if not set return true
     if (!isset($stock->max_sale_qty) || $stock->max_sale_qty < 1) {
         return true;
     }
     $product_total = 0;
     $product_total = 0;
     $items = $this->getDataNew();
     foreach ($items as $product_2) {
         if ($product_2['product_id'] == $product->product_id) {
             $product_total += $product_2['quantity'];
         }
     }
     if ($isTotal) {
         //are we checking total qty from update? then override product total
         $new_product_total = $qty;
     } else {
         $new_product_total = $product_total + $qty;
     }
     if ($new_product_total > $stock->max_sale_qty) {
         throw new Exception(JText::sprintf('K2STORE_MAXIMUM_QUANTITY_WARNING', $product->product_name, (int) $stock->max_sale_qty, $product_total));
         return false;
     }
     return true;
 }
示例#5
0
 public static function isAllowed($item, $qty = 1, $attributes_csv = '')
 {
     $params = JComponentHelper::getParams('com_k2store');
     //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 (K2STORE_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 (is_object($item->product->stock)) {
         $stock = $item->product->stock;
     } else {
         $stock = K2StoreInventory::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 K2StoreModelMyCart();
         //get attributes
         $attributes = $model->getProductOptions($item->product_id);
         $list = array();
         foreach ($attributes as $option) {
             if ($option['type'] == 'select' || $option['type'] == 'radio') {
                 if (isset($option['manage_stock']) && $option['manage_stock'] == 1) {
                     $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 = K2StoreInventory::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 ($quantity_min >= $item->product_stock) {
         $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;
 }
示例#6
0
文件: orders.php 项目: A-Bush/pprod
 public static function sendUserEmail($user_id, $order_id, $payment_status, $order_status, $order_state_id)
 {
     $mainframe = JFactory::getApplication();
     jimport('joomla.filesystem.file');
     // grab config settings for sender name and email
     $config = JFactory::getConfig();
     $k2store_params = JComponentHelper::getParams('com_k2store');
     $k2params = JComponentHelper::getParams('com_k2');
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $mailfrom = $k2store_params->get('emails_defaultemail', $config->get('mailfrom'));
         $fromname = $k2store_params->get('emails_defaultname', $config->get('fromname'));
     } else {
         $mailfrom = $k2store_params->get('emails_defaultname', $config->getValue('config.mailfrom'));
         $fromname = $k2store_params->get('emails_defaultname', $config->getValue('config.fromname'));
     }
     $sitename = $k2store_params->get('sitename', $mainframe->getCfg('sitename'));
     $siteurl = $k2store_params->get('siteurl', JURI::root());
     //now get the order table's id based on order id
     $id = self::_getOrderKey($order_id);
     //inventory
     //TODO::move this function to the plugin.
     require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
     K2StoreInventory::setInventory($id, $order_state_id);
     //now get the receipient
     $recipient = self::_getRecipient($order_id);
     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;
     }
     $html = self::_getHtmlFormatedOrder($id, $user_id);
     $mailer = JFactory::getMailer();
     $mode = 1;
     $subject = JText::sprintf('K2STORE_ORDER_USER_EMAIL_SUB', $recipient->name, $sitename);
     $tags = array('[ORDER_ID]' => $id);
     foreach ($tags as $key => $value) {
         $subject = str_replace($key, $id, $subject);
     }
     $msg = '';
     $msg .= $html;
     //send attachments as well
     //allow_attachment_downloads
     //attachements
     //send attachments, only when the order state is confirmed and attachments are allowed
     if ($k2store_params->get('allow_attachment_downloads') && $order_state_id == 1) {
         $attachments = self::getAttachments($order_id);
         $path = $k2params->get('attachmentsFolder', NULL);
         if (is_null($path)) {
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
         } else {
             $savepath = $path;
         }
         if (count($attachments) > 0) {
             $msg .= '<br />----------------------------------------------------------------------------------------------------------- <br />';
             $msg .= JText::_('K2STORE_ATTACHED_FILES_TO_THIS_EMAIL') . ': <br />';
             foreach ($attachments as $attachment) {
                 $myfile = trim($attachment->filename);
                 $att = $savepath . DS . $myfile;
                 if (JFile::exists($att)) {
                     $msg .= 'File: ' . $myfile . '<br />';
                     $mailer->addAttachment($att);
                 }
             }
             //foreach
         }
         //if count
     }
     $admin_emails = trim($k2store_params->get('admin_email'));
     $admin_emails = explode(',', $admin_emails);
     //send email
     if ($recipient) {
         $mailer->addRecipient($recipient->user_email);
         //   $mailer->addCC( $config->get('admin_email'));
         //$mailer->addCC( $admin_emails );
         $mailer->setSubject($subject);
         $mailer->setBody($msg);
         $mailer->IsHTML($mode);
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
     }
     if ($admin_emails) {
         $mailer = JFactory::getMailer();
         $mailer->addRecipient($admin_emails);
         $mailer->setSubject($subject);
         $mailer->setBody($msg);
         $mailer->IsHTML($mode);
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
     }
     return true;
 }
示例#7
0
文件: cart.php 项目: A-Bush/pprod
 public static function getAjaxCart($item)
 {
     require_once JPATH_ADMINISTRATOR . '/components/com_k2store/helpers/strapper.php';
     K2StoreStrapper::addJS();
     K2StoreStrapper::addCSS();
     $app = JFactory::getApplication();
     $html = '';
     JLoader::register("K2StoreViewMyCart", JPATH_SITE . "/components/com_k2store/views/mycart/view.html.php");
     $layout = 'addtocart';
     $view = new K2StoreViewMyCart();
     //$view->_basePath = JPATH_ROOT.DS.'components'.DS.'com_k2store';
     $view->addTemplatePath(JPATH_SITE . '/components/com_k2store/views/mycart/tmpl');
     $view->addTemplatePath(JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_k2store/mycart');
     require_once JPATH_SITE . '/components/com_k2store/models/mycart.php';
     $model = new K2StoreModelMyCart();
     $product_id = $item->product_id = $item->id;
     $view->assign('_basePath', JPATH_SITE . DS . 'components' . DS . 'com_k2store');
     $view->set('_controller', 'mycart');
     $view->set('_view', 'mycart');
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->setLayout($layout);
     $view->assign('product_id', $product_id);
     $config = JComponentHelper::getParams('com_k2store');
     $show_tax = $config->get('show_tax_total', '1');
     //	$show_attributes = $config->get( 'show_product_attributes', 1);
     $view->assign('show_tax', $show_tax);
     $view->assign('params', $config);
     //$view->assign( 'show_attributes', $show_attributes );
     $item->product = $product = self::getItemInfo($product_id);
     $stock = $product->stock;
     if (isset($stock->min_sale_qty) && $stock->min_sale_qty > 1) {
         $item->product_quantity = (int) $stock->min_sale_qty;
         $item->item_minimum_notice = JText::sprintf('K2STORE_MINIMUM_QUANTITY_NOTIFICATION', $item->title, (int) $stock->min_sale_qty);
     } else {
         $item->product_quantity = 1;
     }
     //get attributes
     $attributes = $model->getProductOptions($product_id);
     if (count($attributes) && $product->stock->manage_stock == 1 && K2STORE_PRO == 1 && !$config->get('allow_backorder', 0)) {
         //get unavailable attribute options
         $attributes = $model->processAttributeOptions($attributes, $product);
         //print_r($attributes );
     }
     $item->attributes = $attributes;
     //get k2store product item
     $product = self::getItemInfo($product_id);
     $stock = K2StoreInventory::getStock($product_id);
     //quantity
     //get prices
     $item->prices = K2StorePrices::getPrice($product_id, $item->product_quantity);
     //base price
     $item->price = $item->prices->product_baseprice;
     //tax
     $t = new K2StoreTax();
     //assign tax class to the view. so that we dont have to call it everytime.
     $view->assign('tax_class', $t);
     $tax = $t->getProductTax($item->price, $item->product_id);
     $item->tax = isset($tax) ? $tax : 0;
     //special price
     $item->special_price = isset($item->prices->product_specialprice) ? (double) $item->prices->product_specialprice : null;
     $sp_tax = $t->getProductTax($item->special_price, $item->product_id);
     $item->sp_tax = isset($sp_tax) ? $sp_tax : 0;
     //now get the total stock
     if (K2STORE_PRO == 1) {
         JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/models');
         $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'K2StoreModel');
         $qtyModel->setState('filter_product', $item->product_id);
         $item->product_stock = $qtyModel->getQuantityTotal();
     } else {
         $item->product_stock = '';
     }
     $view->assign('attributes', $attributes);
     $view->assign('product', $product);
     $view->assign('params', $config);
     //trigger onBeforeAddtocart plugin event
     if (!is_object($item->event)) {
         $item->event = new stdClass();
     }
     $item->event->K2StoreBeforeCartDisplay = '';
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2store');
     $results = $dispatcher->trigger("onK2StoreBeforeCartDisplay", array($item));
     $item->event->K2StoreBeforeCartDisplay = trim(implode("\n", $results));
     $view->assign('item', $item);
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }