本文整理汇总了PHP中TiendaHelperBase::elementsToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP TiendaHelperBase::elementsToArray方法的具体用法?PHP TiendaHelperBase::elementsToArray怎么用?PHP TiendaHelperBase::elementsToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiendaHelperBase
的用法示例。
在下文中一共展示了TiendaHelperBase::elementsToArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateChildren
/**
* Verifies the fields in a submitted form. Uses the table's check() method.
* Will often be overridden. Is expected to be called via Ajax
*
* @return unknown_type
*/
function validateChildren()
{
$response = array();
$response['msg'] = '';
$response['error'] = '';
Tienda::load('TiendaHelperBase', 'helpers._base');
$helper = TiendaHelperBase::getInstance();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
// validate it using table's ->check() method
if (empty($elements)) {
// if it fails check, return message
$response['error'] = '1';
$response['msg'] = $helper->generateMessage("Could not process form");
echo json_encode($response);
return;
}
if (!Tienda::getInstance()->get('shop_enabled', '1')) {
$response['msg'] = $helper->generateMessage("Shop Disabled");
$response['error'] = '1';
echo json_encode($response);
return false;
}
// convert elements to array that can be binded
$values = TiendaHelperBase::elementsToArray($elements);
$attributes_csv = '';
$product_id = !empty($values['product_id']) ? (int) $values['product_id'] : JRequest::getInt('product_id');
$quantities = !empty($values['quantities']) ? $values['quantities'] : array();
$items = array();
// this will collect the items to add to the cart
$attributes_csv = '';
$user = JFactory::getUser();
$cart_id = $user->id;
$id_type = "user_id";
if (empty($user->id)) {
$session = JFactory::getSession();
$cart_id = $session->getId();
$id_type = "session";
}
Tienda::load('TiendaHelperCarts', 'helpers.carts');
$carthelper = new TiendaHelperCarts();
$cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type);
// TODO get the children
// loop thru each child,
// get the list
JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
$model = JModel::getInstance('ProductRelations', 'TiendaModel');
$model->setState('filter_product', $product_id);
$model->setState('filter_relation', 'parent');
if ($children = $model->getList()) {
foreach ($children as $child) {
$product_qty = $quantities[$child->product_id_to];
// 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($child->product_id_to, $attributes_csv);
if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
$response['msg'] = $helper->generateMessage(JText::sprintf("COM_TIENDA_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $product_qty));
$response['error'] = '1';
echo json_encode($response);
return false;
}
// do the item's charges recur? does the cart already have a subscription in it? if so, fail with notice
$product = JTable::getInstance('Products', 'TiendaTable');
$product->load(array('product_id' => $child->product_id_to));
// if product notforsale, fail
if ($product->product_notforsale) {
$response['msg'] = $helper->generateMessage("Product Not For Sale");
$response['error'] = '1';
echo json_encode($response);
return false;
}
if ($product->product_recurs && $cart_recurs) {
$response['msg'] = $helper->generateMessage("Cart Already Recurs");
$response['error'] = '1';
echo json_encode($response);
return false;
}
if ($product->product_recurs) {
$product_qty = '1';
}
// create cart object out of item properties
$item = new JObject();
$item->user_id = JFactory::getUser()->id;
$item->product_id = (int) $child->product_id_to;
$item->product_qty = (int) $product_qty;
$item->product_attributes = $attributes_csv;
$item->vendor_id = '0';
// vendors only in enterprise version
// does the user/cart match all dependencies?
$canAddToCart = $carthelper->canAddItem($item, $cart_id, $id_type);
if (!$canAddToCart) {
//.........这里部分代码省略.........
示例2: addToCart
/**
* Adds an item to a User's shopping cart
* whether in the session or the db
*
*/
function addToCart()
{
if (!Tienda::getInstance()->get('shop_enabled', '1')) {
return false;
}
// saving the session id which will use to update the cart
$session = JFactory::getSession();
// After login, session_id is changed by Joomla, so store this for reference
$session->set('old_sessionid', $session->getId());
$response = array();
$response['msg'] = '';
$response['error'] = '';
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
// convert elements to array that can be binded
Tienda::load('TiendaHelperBase', 'helpers._base');
$values = TiendaHelperBase::elementsToArray($elements);
$product_id = !empty($values['product_id']) ? $values['product_id'] : JRequest::getVar('product_id');
$product_qty = !empty($values['product_qty']) ? $values['product_qty'] : '1';
$attributes = array();
foreach ($values as $key => $value) {
if (substr($key, 0, 10) == 'attribute_') {
$attributes[] = $value;
}
}
$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) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_TIENDA_NOT_AVAILABLE_QUANTITY_NOTICE", $availableQuantity->product_name, $product_qty));
$product_qty = $availableQuantity->quantity;
}
// create cart object out of item properties
$item = new JObject();
$item->user_id = JFactory::getUser()->id;
$item->product_id = (int) $product_id;
$item->product_qty = (int) $product_qty;
$item->product_attributes = $attributes_csv;
$item->vendor_id = '0';
// vendors only in enterprise version
// onAfterCreateItemForAddToCart: plugin can add values to the item before it is being validated /added
// once the extra field(s) have been set, they will get automatically saved
$dispatcher = JDispatcher::getInstance();
$results = $dispatcher->trigger("onAfterCreateItemForAddToCart", array($item, $values));
foreach ($results as $result) {
foreach ($result as $key => $value) {
$item->set($key, $value);
}
}
// no matter what, fire this validation plugin event for plugins that extend the checkout workflow
$results = array();
$dispatcher = JDispatcher::getInstance();
$results = $dispatcher->trigger("onBeforeAddToCart", array($item, $values));
for ($i = 0; $i < count($results); $i++) {
$result = $results[$i];
if (!empty($result->error)) {
Tienda::load('TiendaHelperBase', 'helpers._base');
$helper = TiendaHelperBase::getInstance();
$response['msg'] = $helper->generateMessage($result->message);
$response['error'] = '1';
echo json_encode($response);
return;
} else {
// if here, all is OK
$response['error'] = '0';
}
}
// add the item to the cart
Tienda::load('TiendaHelperCarts', 'helpers.carts');
$cart_helper = new TiendaHelperCarts();
$cartitem = $cart_helper->addItem($item);
// fire plugin event
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onAfterAddToCart', array($cartitem, $values));
// update the cart module, if it is enabled
$this->displayCart();
}
示例3: checkPassword2
/**
* Checks that a password and password2 match
* @return unknown_type
*/
function checkPassword2()
{
Tienda::load('TiendaHelperBase', 'helpers._base');
$helper = TiendaHelperBase::getInstance();
$response = array();
$response['msg'] = '';
$response['error'] = '';
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string', 'string')));
// convert elements to array that can be binded
$values = TiendaHelperBase::elementsToArray($elements);
$password = $values['password'];
$password2 = $values['password2'];
if (empty($password)) {
$response['msg'] = $helper->validationMessage("COM_TIENDA_PASSWORD_CANNOT_BE_EMPTY", 'fail');
$response['error'] = '1';
echo json_encode($response);
return;
}
if (empty($password2)) {
$response['msg'] = $helper->validationMessage("COM_TIENDA_PASSWORD_VERIFY_CANNOT_BE_EMPTY", 'fail');
$response['error'] = '1';
echo json_encode($response);
return;
}
$message = "";
if ($password != $password2) {
$message .= $helper->validationMessage('COM_TIENDA_PASSWORD_DO_NOT_MATCH', 'fail');
} else {
// no error
$message .= $helper->validationMessage('COM_TIENDA_PASSWORD_VALID', 'success');
}
$response['msg'] = $message;
$response['error'] = '1';
echo json_encode($response);
return;
}
示例4: validateReview
/**
* Verifies the fields in a submitted form. Is expected to be called via Ajax
*
* @return unknown_type
*/
function validateReview()
{
$response = array();
$response['msg'] = '';
$response['error'] = '';
$errors = array();
Tienda::load('TiendaHelperBase', 'helpers._base');
Tienda::load('TiendaHelperProduct', 'helpers.product');
$helper = TiendaHelperBase::getInstance();
$user = JFactory::getUser();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
// validate it using table's ->check() method
if (empty($elements)) {
// if it fails check, return message
$response['error'] = '1';
$response['msg'] = $helper->generateMessage("Could not process form");
echo json_encode($response);
return;
}
if (!Tienda::getInstance()->get('shop_enabled', '1')) {
$response['msg'] = $helper->generateMessage("Shop Disabled");
$response['error'] = '1';
echo json_encode($response);
return false;
}
// convert elements to array that can be binded
$values = TiendaHelperBase::elementsToArray($elements);
if (!$user->id) {
if (empty($values['user_name'])) {
$errors[] = '<li>' . JText::_('COM_TIENDA_NAME_FIELD_IS_REQUIRED') . '</li>';
}
jimport('joomla.mail.helper');
if (!JMailHelper::isEmailAddress($values['user_email'])) {
$errors[] = '<li>' . JText::_('COM_TIENDA_PLEASE_ENTER_A_CORRECT_EMAIL_ADDRESS') . '</li>';
}
if (in_array($values['user_email'], TiendaHelperProduct::getUserEmailForReview($values['product_id']))) {
$errors[] = '<li>' . JText::_('COM_TIENDA_YOU_ALREADY_SUBMITTED_A_REVIEW_CAN_ONLY_SUBMIT_REVIEW_ONCE') . '</li>';
}
} else {
if (in_array($user->email, TiendaHelperProduct::getUserEmailForReview($values['product_id']))) {
$errors[] = '<li>' . JText::_('COM_TIENDA_YOU_ALREADY_SUBMITTED_A_REVIEW_CAN_ONLY_SUBMIT_REVIEW_ONCE') . '</li>';
}
}
if (count($errors)) {
$response['error'] = 1;
$response['msg'] = $helper->generateMessage(implode("\n", $errors), false);
echo json_encode($response);
return;
}
if (empty($values['productcomment_rating'])) {
$errors[] = '<li>' . JText::_('COM_TIENDA_RATING_IS_REQUIRED') . '</li>';
}
if (empty($values['productcomment_text'])) {
$errors[] = '<li>' . JText::_('COM_TIENDA_COMMENT_FIELD_IS_REQUIRED') . '</li>';
}
if (count($errors)) {
$response['error'] = 1;
$response['msg'] = $helper->generateMessage(implode("\n", $errors), false);
}
echo json_encode($response);
return;
}
示例5: validate
/**
* (non-PHPdoc)
* @see tienda/site/TiendaController::validate()
*/
function validate()
{
Tienda::load('TiendaHelperBase', 'helpers._base');
$helper = new TiendaHelperBase();
$response = array();
$response['msg'] = '';
$response['error'] = '';
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
// validate it using table's ->check() method
if (empty($elements)) {
// if it fails check, return message
$response['error'] = '1';
$response['msg'] = $helper->generateMessage(JText::_('COM_TIENDA_COULD_NOT_PROCESS_FORM'));
echo json_encode($response);
return;
}
// convert elements to array that can be binded
$values = $helper->elementsToArray($elements);
$values['sameasbilling'] = isset($values['_checked']['sameasbilling']) && !empty($values['_checked']['sameasbilling']);
// validate it based on the step
switch ($values['step']) {
case "step1":
$response = $this->validateStep1($values);
break;
case "step2":
$response = $this->validateStep2($values);
break;
case "step3":
$response = $this->validateStep3($values);
break;
case "step4":
break;
}
echo json_encode($response);
return;
}
示例6: getOrderTotals
/**
* Calculates the order total line items
* and returns formatted HTML
* Expects to be called by Ajax
*
* @return unknown_type
*/
function getOrderTotals()
{
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
// convert elements to array that can be binded
Tienda::load('TiendaHelperBase', 'helpers._base');
$values = TiendaHelperBase::elementsToArray($elements);
// get the order object so we can populate it
$order = $this->_order;
// a TableOrders object (see constructor)
// bind what you can from the post
$order->bind($values);
// set the currency
//TODO: Change this to currency_id in the form
$order->currency_id = $values['order_currency_id'];
// set the shipping method
$order->shipping_method_id = @$values['_checked']['shipping_method_id'];
// set the order's addresses based on the form inputs
$this->setAddresses($values);
// get the items and add them to the order
$items = $this->getProductsInfo($order->currency_id, $order->getBillingGeozone());
foreach ($items as $item) {
$order->addItem($item);
}
// get the order totals
$order->calculateTotals();
$model = $this->getModel($this->get('suffix'));
$view = $this->getView('orders', 'html');
$view->set('_controller', 'orders');
$view->set('_view', 'orders');
$view->setModel($model, true);
$view->assign('state', $model->getState());
$view->assign('row', $order);
$view->assign('shipping_total', $order->getShippingTotal());
$view->setLayout('ordertotals');
ob_start();
$view->setTask(true);
$view->display();
$html = ob_get_contents();
ob_end_clean();
$response = array();
$response['msg'] = $html;
$response['error'] = '';
echo json_encode($response);
return;
}