本文整理汇总了PHP中CitruscartHelperBase::elementsToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP CitruscartHelperBase::elementsToArray方法的具体用法?PHP CitruscartHelperBase::elementsToArray怎么用?PHP CitruscartHelperBase::elementsToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CitruscartHelperBase
的用法示例。
在下文中一共展示了CitruscartHelperBase::elementsToArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPassword2
/**
* Checks that a password and password2 match
* return unknown_type
*/
function checkPassword2()
{
$input = JFactory::getApplication()->input;
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$helper = CitruscartHelperBase::getInstance();
$response = array();
$response['msg'] = '';
$response['error'] = '';
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements')));
// convert elements to array that can be binded
$values = CitruscartHelperBase::elementsToArray($elements);
$password = $values['password'];
$password2 = $values['password2'];
if (empty($password)) {
$response['msg'] = $helper->validationMessage("COM_CITRUSCART_PASSWORD_CANNOT_BE_EMPTY", 'fail');
$response['error'] = '1';
echo json_encode($response);
return;
}
if (empty($password2)) {
$response['msg'] = $helper->validationMessage("COM_CITRUSCART_PASSWORD_VERIFY_CANNOT_BE_EMPTY", 'fail');
$response['error'] = '1';
echo json_encode($response);
return;
}
$message = "";
if ($password != $password2) {
$message .= $helper->validationMessage('COM_CITRUSCART_PASSWORD_DO_NOT_MATCH', 'fail');
} else {
// no error
$message .= $helper->validationMessage('COM_CITRUSCART_PASSWORD_VALID', 'success');
}
$response['msg'] = $message;
$response['error'] = '1';
echo json_encode($response);
return;
}
示例2: validateReview
/**
* Verifies the fields in a submitted form. Is expected to be called via Ajax
*
* @return unknown_type
*/
function validateReview()
{
$input = JFactory::getApplication()->input;
$response = array();
$response['msg'] = '';
$response['error'] = '';
$errors = array();
Citruscart::load('CitruscartHelperBase', 'helpers._base');
Citruscart::load('CitruscartHelperProduct', 'helpers.product');
$helper = CitruscartHelperBase::getInstance();
$user = JFactory::getUser();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements')));
// 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 (!Citruscart::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 = CitruscartHelperBase::elementsToArray($elements);
if (!$user->id) {
if (empty($values['user_name'])) {
$errors[] = '<li>' . JText::_('COM_CITRUSCART_NAME_FIELD_IS_REQUIRED') . '</li>';
}
jimport('joomla.mail.helper');
if (!JMailHelper::isEmailAddress($values['user_email'])) {
$errors[] = '<li>' . JText::_('COM_CITRUSCART_PLEASE_ENTER_A_CORRECT_EMAIL_ADDRESS') . '</li>';
}
if (in_array($values['user_email'], CitruscartHelperProduct::getUserEmailForReview($values['product_id']))) {
$errors[] = '<li>' . JText::_('COM_CITRUSCART_YOU_ALREADY_SUBMITTED_A_REVIEW_CAN_ONLY_SUBMIT_REVIEW_ONCE') . '</li>';
}
} else {
if (in_array($user->email, CitruscartHelperProduct::getUserEmailForReview($values['product_id']))) {
$errors[] = '<li>' . JText::_('COM_CITRUSCART_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_CITRUSCART_RATING_IS_REQUIRED') . '</li>';
}
if (empty($values['productcomment_text'])) {
$errors[] = '<li>' . JText::_('COM_CITRUSCART_COMMENT_FIELD_IS_REQUIRED') . '</li>';
}
if (count($errors)) {
$response['error'] = 1;
$response['msg'] = $helper->generateMessage(implode("\n", $errors), false);
}
echo json_encode($response);
return;
}
示例3: 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()
{
$input = JFactory::getApplication()->input;
$response = array();
$response['msg'] = '';
$response['error'] = '';
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$helper = CitruscartHelperBase::getInstance();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements')));
// 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 (!Citruscart::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 = CitruscartHelperBase::elementsToArray($elements);
$attributes_csv = '';
$product_id = !empty($values['product_id']) ? (int) $values['product_id'] : $input->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";
}
Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
$carthelper = new CitruscartHelperCarts();
$cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type);
// TODO get the children
// loop thru each child,
// get the list
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
$model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel');
$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 = Citruscart::getClass('CitruscartHelperProduct', '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_CITRUSCART_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', 'CitruscartTable');
$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);
//.........这里部分代码省略.........
示例4: addToCart
/**
* Adds an item to a User's shopping cart
* whether in the session or the db
*
*/
function addToCart()
{
$input = JFactory::getApplication()->input;
if (!Citruscart::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', $input->getString('elements')));
// convert elements to array that can be binded
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$values = CitruscartHelperBase::elementsToArray($elements);
$product_id = !empty($values['product_id']) ? $values['product_id'] : $input->getInt('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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv);
if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_CITRUSCART_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
$results = JFactory::getApplication()->triggerEvent("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();
$results = JFactory::getApplication()->triggerEvent("onBeforeAddToCart", array($item, $values));
for ($i = 0; $i < count($results); $i++) {
$result = $results[$i];
if (!empty($result->error)) {
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$helper = CitruscartHelperBase::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
Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
$cart_helper = new CitruscartHelperCarts();
$cartitem = $cart_helper->addItem($item);
// fire plugin event
JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($cartitem, $values));
// update the cart module, if it is enabled
$this->displayCart();
}
示例5: validate
/**
* (non-PHPdoc)
* @see Citruscart/site/CitruscartController::validate()
*/
function validate()
{
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$helper = new CitruscartHelperBase();
$response = array();
$response['msg'] = '';
$response['error'] = '';
/* Get the application */
$app = JFactory::getApplication();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $app->input->get('elements', '')));
// 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_CITRUSCART_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()
{
$app = JFactory::getApplication();
// get elements from post
$elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $app->input->getString('elements')));
// convert elements to array that can be binded
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$values = CitruscartHelperBase::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;
}