/** * Add the page title and toolbar. */ protected function addToolbar() { JFactory::getApplication()->input->set('hidemainmenu', true); $user = JFactory::getUser(); $isNew = $this->item->id == 0; if (isset($this->item->checked_out)) { $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); } else { $checkedOut = false; } $canDo = DZProductHelper::getActions(); JToolBarHelper::title(JText::_('COM_DZPRODUCT_TITLE_ORDER'), 'order.png'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { JToolBarHelper::apply('order.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('order.save', 'JTOOLBAR_SAVE'); } if (!$checkedOut && $canDo->get('core.create')) { JToolBarHelper::custom('order.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::custom('order.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false); } if (empty($this->item->id)) { JToolBarHelper::cancel('order.cancel', 'JTOOLBAR_CANCEL'); } else { JToolBarHelper::custom('order.mailadmin', 'mail', 'mail', 'COM_DZPRODUCT_TOOLBAR_SEND_ADMIN', false); JToolBarHelper::custom('order.mailcustomer', 'mail', 'mail', 'COM_DZPRODUCT_TOOLBAR_SEND_CUSTOMER', false); JToolBarHelper::cancel('order.cancel', 'JTOOLBAR_CLOSE'); } }
public function mailcustomer() { $cid = JFactory::getApplication()->input->get('cid', array(), 'array'); $error_ids = array(); if (!is_array($cid) || count($cid) < 1) { JLog::add(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), JLog::WARNING, 'jerror'); } else { foreach ($cid as $id) { if (!DZProductHelper::sendOrder($id, DZProductHelper::EMAIL_CUSTOMER)) { $error_ids[] = $id; } } } if (count($error_ids)) { $message = JText::sprintf('COM_DZPRODUCT_MAILS_SENT_FAIL', implode(', ', $error_ids)); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message, 'error'); return false; } else { $message = JText::_('COM_DZPRODUCT_MAILS_SENT_SUCCESSFULLY'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message); return true; } }
public function mailCustomer($key = null, $urlVar = null) { $model = $this->getModel(); $table = $model->getTable(); // Determine the name of the primary key for the data. if (empty($key)) { $key = $table->getKeyName(); } // To avoid data collisions the urlVar may be different from the primary key. if (empty($urlVar)) { $urlVar = $key; } $recordId = $this->input->getInt($urlVar); if ($result = DZProductHelper::sendOrder($recordId, DZProductHelper::EMAIL_CUSTOMER)) { $message = JText::_('COM_DZPRODUCT_MAILS_SENT_SUCCESSFULLY'); } else { $message = JText::sprintf('COM_DZPRODUCT_MAILS_SENT_FAIL', $recordId); } // Redirect back to the edit screen. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $urlVar), false), $message, $result ? 'message' : 'error'); return $result; }
/** * Method to save a user's profile data. * * @return void * @since 1.6 */ public function save() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $response = recaptcha_check_answer($this->privatekey, $_SERVER["REMOTE_ADDR"], $this->input->post->get('recaptcha_challenge_field', '', 'string'), $this->input->post->get('recaptcha_response_field', '', 'string')); if (!$response->is_valid) { throw new RuntimeException(JText::_('COM_DZPRODUCT_ERROR_INVALID_CAPTCHA')); } // Initialise variables. $app = JFactory::getApplication(); $model = $this->getModel('Order', 'DZProductModel'); // Get the user data. $data = JFactory::getApplication()->input->get('jform', array(), 'array'); $cart = JFactory::getApplication()->input->post->getArray(array('jform' => array('products' => 'array'))); if (empty($cart)) { throw new RuntimeException(JText::_('COM_DZPRODUCT_EMPTY_CART')); } // Validate the posted data. $form = $model->getForm(); if (!$form) { JError::raiseError(500, $model->getError()); return false; } // Validate the posted data. $data = $model->validate($form, $data); // Check for errors. if ($data === false) { // Get the validation messages. $errors = $model->getErrors(); $messages = array(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $messages[] = $errors[$i]->getMessage(); } else { $messages[] = $errors[$i]; } } throw new RuntimeException(join(',', $messages)); } // Attempt to save the data // Check for errors. if (!$model->save($data)) { throw new RuntimeException(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', join(',', $model->getErrors()))); } $order_id = $model->getState($model->getName() . '.id'); /* --- CART PROCESSING --- */ JModelLegacy::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/models/'); // Get the products model $products_model = JModelLegacy::getInstance('Items', 'DZProductModel'); $filter_ids = array(); foreach ($cart['jform']['products'] as $id => $value) { $filter_ids[] = $id; } $products_model->setState('filter.ids', $filter_ids); $products = $products_model->getItems(); // Prevent customer from hacking the price foreach ($products as $product) { $cart['jform']['products'][$product->id]['price'] = $product->saleoff ? $product->saleoff : $product->price; } foreach ($cart['jform']['products'] as $item) { $item['order_id'] = $order_id; $item['id'] = 0; $model = JModelLegacy::getInstance('OrderItem', 'DZProductModel'); $form = $model->getForm($item, false); if (!$form) { continue; } $validItem = $model->validate($form, $item); if ($validItem === false) { continue; } if (!$model->save($validItem)) { continue; } } // Send email require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/dzproduct.php'; JFactory::getLanguage()->load('com_dzproduct', JPATH_ADMINISTRATOR); DZProductHelper::sendOrder($order_id, DZProductHelper::EMAIL_CUSTOMER); DZProductHelper::sendOrder($order_id, DZProductHelper::EMAIL_ADMIN); // Exit with success jexit($this->encodeMessage(JText::_('COM_DZPRODUCT_ORDER_SUCCESSFULLY'))); }
?> <span class="product-new"> <?php echo $product->new_arrival; ?> </span> <?php } ?> <?php if ($this->params->get('category_show_item_availability_label', 1)) { ?> <span class="product-avail"> <?php echo DZProductHelper::availabilityText($product->availability); ?> </span> <?php } ?> </div> <?php if ($this->params->get('order_enabled', 1)) { ?> <button class="btn btn-primary btn-order" data-info='<?php echo $product->data; ?> '><i class="icon-shopping-cart icon-white"></i><?php echo JText::_('COM_DZPRODUCT_BTN_ADD_TO_CART'); ?>