guys sorry for bad English.
I am using in Magento enterprise I am working in wishlist there is a function in core at path
C:\xampp\htdocs\projects\baab.bh\app\code\core\Mage\Wishlist\Helper\Data.php
getWishlist()
When I am calling this function to get wishlist from front-end phtml file it's giving me correct wishlist but when I am calling this function from controller it's giving me default wishlist only not the current wishlist here is the code of this function
public function getWishlist()
{
if (is_null($this->_wishlist)) {
if (Mage::registry('shared_wishlist')) {
$this->_wishlist = Mage::registry('shared_wishlist');
} elseif (Mage::registry('wishlist')) {
$this->_wishlist = Mage::registry('wishlist');
} else {
$this->_wishlist = Mage::getModel('wishlist/wishlist');
if ($this->getCustomer()) {
$this->_wishlist->loadByCustomer($this->getCustomer());
}
}
}
return $this->_wishlist;
}
I am calling it with the same code but it behaves differently from front-end phtml file and from controller. How can I get current wishlist from the controller as well?
For this, you will get all customers wishlist:
public function getWishlist()
{
$customer = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
$wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
$wishListAllItem = $wishList->getItemCollection();
if (count($wishListAllItem)) {
$arrOfProductIds = array();
foreach ($wishListAllItem as $item) {
$arrOfProductIds[] = $item->getProductId();
}
}
return $arrOfProductIds;
}
For this, you can get current user wishlist:
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer)
$wishListAllItem = $wishList->getItemCollection();
if (count($wishListAllItem)) {
$arrOfProductIds = array();
foreach ($wishListAllItem as $item) {
$product = $item->getProduct();
$arrOfProductIds[] = $product->getId();
}
}
Related
I'm trying to follow the instructions on this docs page, but I seem to be missing something:
https://docs.joomla.org/Supporting_SEF_URLs_in_your_component
The URI that needs to be corrected is: index.php?com_component&view=legal&page=customermasteragreement
It seems like the routing function should be simple, but the page is just displaying default instead of the sub-view.
Here's my current code:
function ComponentBuildRoute(&$query)
{
$segments = array();
if (isset($query['view'])) {
$segments[] = $query['view'];
unset($query['view']);
}
if (isset($query['page'])) {
$segments[] = $query['page'];
unset($query['page']);
}
return $segments;
}
function ComponentParseRoute($segments)
{
$vars = array();
switch($segments[0])
{
case 'legal':
$vars['view'] = 'legal';
break;
case 'customermasteragreement':
$vars['page'] = 'customermasteragreement';
break;
}
return $vars;
}
Update
This code works to display the subpage, but it gives me a URI like: legal-agreements/legal?page=customermasteragreement
class ComponentRouter extends JComponentRouterBase {
public function build(&$query) {
$segments = array();
$view = null;
if (isset($query['view'])) {
$segments[] = $query['view'];
$view = $query['view'];
unset($query['view']);
}
if (isset($query['id'])) {
if ($view !== null) {
$segments[] = $query['id'];
} else {
$segments[] = $query['id'];
}
unset($query['id']);
}
return $segments;
}
public function parse(&$segments) {
$vars = array();
// View is always the first element of the array
$vars['view'] = array_shift($segments);
return $vars;
}
}
EDIT 2
If it helps, here's my model and views
models/legal.php
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
class ComponentModelLegal extends JModelItem {
public function __construct($config = array())
{
JLoader::register('ComponentHelper', JPATH_COMPONENT_ADMINISTRATOR . '/helpers/component.php');
parent::__construct($config);
}
/**
*
* #return string
*/
public function getLegal() {
$app = JFactory::getApplication();
$page = $app->input->get('page', '', 'STRING');
if ($page) {
ComponentHelper::add('type', $page); //This is an API request to an external service, returning JSON formatted data
$legal = ComponentHelper::getData('commons/legal-agreements.json', TRUE);
if (isset($legal[0]['status'])) {
JError::raiseError(400, $legal[0]['ERROR']);
return false;
} else {
if (!isset($this->legal)) {
$this->legal = $legal;
}
return $this->legal;
}
}
}
}
views/legal/view.html.php
class ComponentViewLegal extends JViewLegacy {
function display($tpl = null) {
// Assign data to the view
$this->legal = $this->get('legal');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
return false;
}
// Display the view
parent::display($tpl);
}
}
views/legal/tmpl/default.php
$page = JRequest::getVar('page');
$pages = array(
'resellermasteragreement',
'customermasteragreement',
'resellerdomainagreement',
'customerdomainagreement',
'resellerwebserviceagreement',
'customerwebserviceagreement',
'resellerdigicertagreement',
'customerdigicertagreement',
'registraragreement',
'customerhostingproductagreement',
'resellerhostingproductagreement'
);
?>
<div class="col-lg-12">
<?php
echo in_array($page, $pages) ? $this->loadTemplate('legal') : $this->loadTemplate('home');
?>
</div>
views/legal/tmpl/default_legal.php
$page = JRequest::getVar('page');
echo nl2br(htmlspecialchars($this->legal[$page]['defaultagreement'], ENT_NOQUOTES, "UTF-8"));
?>
<a type="button" class="btn btn-primary" href="<?php echo JROUTE::_("index.php?option=com_component&view=legal"); ?>">Back</a>
EDIT 3
This works because I wasn't navigating directly to the page from a menu item. There's a top level menu, then a page a links to the agreements. I have a hidden menu to each item, but that wasn't the link I followed.
$app = JFactory::getApplication()->getMenu();
$customermaster = $app->getItems( 'link', 'index.php?option=com_component&view=legal&page=customermasteragreement', true );
JRoute::_('index.php?Itemid='.$customermaster->id);
You have one view but you're not actually set the page argument correctly when you catch a view argument, but you treat page as some king of another view. Can you please try this and check if it works:
function [componentname]ParseRoute($segments)
{
$vars = array();
switch($segments[0])
{
case 'legal':
$vars['view'] = 'legal';
$vars['page'] = $segments[1];
break;
}
return $vars;
}
Also the functions ComponentBuildRoute, ComponentParseRoute must have your components name instead of Component at the beginning.
EDIT
[componentname]BuildRoute and [componentname]ParseRoute are deprecated, you should stick the the class that extends JComponentRouterBase as you have it in your updated second example. Try this one here and see if it works:
class ComponentRouter extends JComponentRouterBase {
public function build(&$query) {
$segments = array();
$view = null;
if (isset($query['view'])) {
$segments[] = $query['view'];
$view = $query['view'];
unset($query['view']);
}
if (isset($query['page'])) {
$segments[] = $query['page'];
unset($query['page']);
}
return $segments;
}
public function parse(&$segments) {
$vars = array();
// View is always the first element of the array
$vars['view'] = array_shift($segments);
if(count($segments) > 0)
$vars['page'] = array_shift($segments);
return $vars;
}
}
EDIT 2
I have a test Joomla 3 site with a simple component named Ola.
Non SEO component URL: http://j3.dev.lytrax.net/index.php?option=com_ola&page=test_page&view=ola
URL generated by JRoute before Router class added to router.php: http://j3.dev.lytrax.net/index.php/component/ola/?page=test_page&view=ola
SEO URL returned by JRoute::_('index.php?option=com_ola&page=test_page&view=ola'); after creating router.php and used the Router class above: http://j3.dev.lytrax.net/index.php/component/ola/ola/test_page
If you visit the links, you'll see that all are working and you can even see the page, view and JRoute results of the calling component Ola.
Unless I've completely misunderstood Joomla (I've been developing with it for four five years now), there is no "sub-view" concept implemented. Trying to use the idea is what's getting you into trouble I think.
I'm astounded that the idea of using a visual debugger is so unpopular.
Get yourself something like Netbeans (there are others too), set up a local web and database server, and watch the code run. Very (well, relatively very) quickly you'll start to understand how the structure hangs together.
You may put code in your view that picks up the extra params you've set and displays or hides things accordingly, but there is no "sub-view".
I am using Magento 1.9.x and I would like to create an order via quote and I can do that like this:
private function createOrder()
{
$orderId = $session->getTransactionId();
$quote = $this->_getCheckout()->getQuote();
$quote->setReservedOrderId($orderId);
$quote->collectTotals()->getPayment()->setMethod($this->_getPaymentMethod());
$quoteId = $quote->getId();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
$order->setStatus('complete');
$order->save();
$checkoutSession = Mage::getSingleton('checkout/type_onepage')->getCheckout();
$checkoutSession->setLastSuccessQuoteId($quoteId);
$checkoutSession->setLastQuoteId($quoteId);
$checkoutSession->setLastOrderId($order->getIncrementId());
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
But my problem is the success page. When I redirect to the success page just appear like
this
Not appear order id or print detail like this
How can I fix it?
Thank you
Edit:
I want to create a custom payment method. If the customer choose my method I delete the "Place Order" button and I create iframe at order review.
app\design\frontend\base\default\layout\mymodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_review>
<reference name="checkout.onepage.review.button">
<action method="setTemplate">
<template helper="mymodule/data/getReviewButtonTemplate">
<name>mymodule/onepage/iframe.phtml</name>
<block>checkout.onepage.review.button</block>
</template>
</action>
</reference>
</checkout_onepage_review>
</layout>
app\code\local\Mycompany\Mymodule\Helper\data.php
<?php
class Mycompany_Mymodules_Helper_Data extends Mage_Core_Helper_Abstract
{
public function getHostedUrl()
{
//get iframe url from soap
}
public function GetHostedPaymentProcessStatusResult()
{
//check from soap response is correct
}
public function getReviewButtonTemplate($name, $block)
{
$paymentcode = $this->_getPaymentMethod();
if ($paymentcode == 'mymodule')
return $name;
if ($blockObject = Mage::getSingleton('core/layout')->getBlock($block))
return $blockObject->getTemplate();
return '';
}
public function getConfigData($configName)
{
return Mage::getStoreConfig('payment/mymodule/' . $configName, Mage::app()->getStore());
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
}
Payment is complete at in iframe and calls my module response page with some parameters.
app\code\local\Mycompany\Mymodule\controllers\PaymentController.php
<?php
class Mycompany_Mymodule_PaymentController extends Mage_Core_Controller_Front_Action
{
public function responseAction()
{
$session = Mage::getSingleton('core/session');
$transactionId = $_GET['TransactionId'];
$orderId = $session->getTransactionId();
$mymoduleTransId = $_GET['MymoduleTransId'];
$helper = Mage::helper('mymodule');
if ($_GET['Result'] == 'PaymentOk' && $transactionId == $orderId) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$result = $helper->getHostedPaymentProcessStatus($transactionId, $mymoduleTransId);
if ($result) {
$result = $result->GetHostedPaymentProcessStatusResult;
$resultCode = $result->ResultCode;
if ($resultCode === "Success") {
$quote->setReservedOrderId($orderId);
$quoteId = $quote->getId();
$quote->collectTotals()->getPayment()->setMethod($this->_getPaymentMethod());
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
$order->setStatus(Mage::helper('mymodule')->getConfigData('after_pay_status'));
$order->save();
$checkoutSession = Mage::getSingleton('checkout/type_onepage')->getCheckout();
$checkoutSession->setLastSuccessQuoteId($quoteId);
$checkoutSession->setLastQuoteId($quoteId);
$checkoutSession->setLastOrderId($order->getIncrementId());
$this->_clearQuote($quoteId);
$returnUrl = Mage::getUrl('checkout/onepage/success', array('_secure' => true));
} else
$returnUrl = Mage::getUrl('checkout/onepage/failure', array('_secure' => true));
} else {
$returnUrl = Mage::getUrl('checkout/onepage/failure', array('_secure' => true));
}
echo '<script> window.top.location.href = "' . $returnUrl . '";</script>';
}
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
protected function _clearQuote($quoteID)
{
$quote = Mage::getModel("sales/quote")->load($quoteID);
$quote->setIsActive(0)->save();
$quote->delete();
$quote->save();
$cart = Mage::getSingleton('checkout/cart');
$quoteItems = Mage::getSingleton('checkout/session')
->getQuote()
->getItemsCollection();
foreach ($quoteItems as $item) {
$cart->removeItem($item->getId());
}
$cart->save();
}
}
The best way (and actually I believe this is the way magento uses) is to pass the order ID into session. To do that, use Mage::getSingleton('core/session')->setIncrementId($order->getIncrementId());.
Then on success page just use Mage::getSingleton('core/session')->getIncrementId($order->getIncrementId()); to retrieve order's Increment ID.
I do not know how to set a callback function for the view record page in codeigniter.
I use the callback_column function and it does what I need in the grid view, but on the view record page it does not work.
I searched their site and forum and did not found anything that could help me.
My code looks like:
$zeus = new grocery_CRUD();
$zeus->set_theme('bootstrap');
// $zeus->set_language('romanian');
$zeus->set_table('programari');
$zeus->columns(array('id_client', 'id_sala', 'denumire', 'numar_persoane', 'observatii'));
$zeus->callback_column('id_sala',array($this,'_test_function'));
$cod = $zeus->render();
$this->_afiseaza_panou($cod);
public function _test_function($row, $value)
{
return '0';
}
write this lines in \libraries\Grocery_CRUD.php
at line number 3530
protected $callback_read_field = array();
than put this function after constructor call
public function callback_read_field($field, $callback = null)
{
$this->callback_read_field[$field] = $callback;
return $this;
}
//Now update this function to manage the field outputs using callbacks if they are defined for the same
protected function get_read_input_fields($field_values = null)
{
$read_fields = $this->get_read_fields();
$this->field_types = null;
$this->required_fields = null;
$read_inputs = array();
foreach ($read_fields as $field) {
if (!empty($this->change_field_type)
&& isset($this->change_field_type[$field->field_name])
&& $this->change_field_type[$field->field_name]->type == 'hidden') {
continue;
}
$this->field_type($field->field_name, 'readonly');
}
$fields = $this->get_read_fields();
$types = $this->get_field_types();
$input_fields = array();
foreach($fields as $field_num => $field)
{
$field_info = $types[$field->field_name];
if(isset($field_info->db_type) && ($field_info->db_type == 'tinyint' || ($field_info->db_type == 'int' && $field_info->db_max_length == 1))) {
$field_value = $this->get_true_false_readonly_input($field_info, $field_values->{$field->field_name});
} else {
$field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null;
}
if(!isset($this->callback_read_field[$field->field_name]))
{
$field_input = $this->get_field_input($field_info, $field_value);
}
else
{
$primary_key = $this->getStateInfo()->primary_key;
$field_input = $field_info;
$field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values);
}
switch ($field_info->crud_type) {
case 'invisible':
unset($this->read_fields[$field_num]);
unset($fields[$field_num]);
continue;
break;
case 'hidden':
$this->read_hidden_fields[] = $field_input;
unset($this->read_fields[$field_num]);
unset($fields[$field_num]);
continue;
break;
}
$input_fields[$field->field_name] = $field_input;
}
return $input_fields;
}
than call same as other callback functions
As far as I'm aware GroceryCRUD doesn't provide callbacks or another means of overriding the default output in the view state.
The solution to customising this would be to create a custom view to which you will insert the data from your record. This way you can customise the layout and other presentation.
What you would then do is unset the default read view with:
$crud->unset_read();
And add a new action where there are details on how to do this here.
What to do with the new action is point it to a URL that you map in routes.php if necessary and handle it with a new function in your controller. You'll either have to write a model function to retrieve the data since this isn't passed from GC or you can use the action to target a callback and feed $row to it via POST or something so that the data for the record is accessible in the view. (Look at the example in the link above).
Is it possible to get a record of my model by another field of my model?
The normal way
$model = Mage::getModel('foo_bar/baz');
$model->load($id);
// do something with the loaded record
But i need something like this
$model = Mage::getModel('foo_bar/baz');
$model->loadByAnotherFieldOfModel($value)
// do something with the loaded record
is that possible?
$model = Mage::getModel('foo_bar/baz');
$model->load('field_value', 'field_name');
use this
$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'computer');
$_product = Mage::getModel('catalog/product')->loadByAttribute('name', 'hp2312');
// Load by SKU
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'computer123');
Goto model file
NameSpace/Yourmodule/Model/YourModel.php
add below code
public function loadByField($fieldvalue)
{
$this->_getResource()->loadByField($this, $fieldvalue);
return $this;
}
AND
NameSpace/YourModule/Model/Resource/YourModel.php
and code is
public function loadByField(NameSpace_YourModule_Model_YourModel $Object, $fieldvalue)
{
$adapter = $this->_getReadAdapter();
$bind = array('fieldname' => $fieldvalue);
$select = $adapter->select()
->from($this->getMainTable(), 'tablePrimaryKey')
->where('fieldname = :fieldname');
$modelId = $adapter->fetchOne($select, $bind);
if ($modelId) {
$this->load($Object, $modelId );
} else {
$Object->setData(array());
}
return $this;
}
Hello Magento Experts,
I developed a Magento Extension which is working fine on Version 1.6 and 1.7, but when i installed it on Version 1.5, it is giving me an error :
Fatal error: Call to a member function getData() on a non-object in /home/broadcas/public_html/app/code/community/Gwb/Magecrmsync/controllers/Adminhtml/OrdersController.php on line 18
Below is my OrderController.php Code.
<?php
class Gwb_Magecrmsync_Adminhtml_OrdersController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$model = Mage::getModel('sales/order');
$collection = $model->getCollection()
->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing')));
$data = array();
$orderArr = array();
// getting order details
$records = 0;
foreach($collection as $order)
{
$data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details
$data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details
$data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount
$data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount();
$data[$records]['order_data']['order_details'] = $order->toArray();
$records++;
}
// getting order details
}
}
Can anyone please guide me what am i doing wrong which doesn't work in Version 1.5.
Any help would be appreciated.
Thanks
Check my answer. You should check $order->getShippingAddress() is object or not. because if product is virtual. The shipping address will be set.
class Gwb_Magecrmsync_Adminhtml_OrdersController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$model = Mage::getModel('sales/order');
$collection = $model->getCollection()
->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing')));
$data = array();
$orderArr = array();
// getting order details
$records = 0;
foreach($collection as $order)
{
if(is_object($order->getShippingAddress()))
{
$data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details
}
else
{
$data[$records]['order_data']['shipping_address'] = array(); // no shipping details
}
if(is_object($order->getBillingAddress()))
{
$data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details
}
else
{
$data[$records]['order_data']['billing_address'] = array(); // no billing details
}
$data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount
$data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount();
$data[$records]['order_data']['order_details'] = $order->toArray();
$records++;
}
// getting order details
}
}