I am trying to customize a module, and need to call the cart items inside a model from the backend (adminhtml) while creating an order from backend. Calling Models('checkout/session'), ('checkout/cart'), and helper doesnot seem to work. Does getCustomercart() works or shall I try anything else ?
For backend orders you have access to the 'quote' object like this:
Mage::getSingleton('adminhtml/session_quote')->getQuote().
See what else you can use from the class Mage_Adminhtml_Model_Sales_Order_Create. That's the model that handles the backend order creation.
Related
I'm trying to follow a tutorial I found on youtube using bumbummen99's shopping cart package about storing instances into the database, but I'm getting an error that it can't store the cart using the same identifier.
Here's the code when I'm storing the instance:
public function render()
...
if(Auth::check()){
Cart::instance('cart')->store(Auth::user()->id);
}
Since the instance is getting stored before I can add a product to the cart, it doesn't save the product inside the cart after logging out.
With the fact i have only minor experiences with persistent shopping carts, i found it weird it didn't have an update() method.
In your case, i would assume you should erase() the cart before saving it again, to ensure the correct cart is in the database.
Cart::instance('cart')->erase(Auth::user()->id);
Cart::instance('cart')->store(Auth::user()->id);
In general saving the cart seems like a challenge, i would assume the best practice is to save on logouts, as the session will persist and this should not be done in context of render calls. Or with a button to actually save the state of the cart for later.
I'm working on ecommerce website, Stuck in nav bar, I have created routes something like this:
Route::get('/category/{slug}', 'Site\CategoryController#show')->name('category.show');
In slug i pass slug of Product,
but i want to change something like this
Route::get('/{slug}/{slug}', 'Site\CategoryController#show')->name('category.show');
i want to remove category prefix and pass main category slug as a first parameter and sub category if it exist as a second parameter otherwise it will be empty.
One more thing i am using TypiCMS, for creating Nestable menu and it is working will i have to modify that also to work with the dynamic route.
Sorry I don't know anything about your cms framework but in Laravel you cant use the same name for two bindings in your route, they must each be unique.
Route::get('/{categoyrySlug}/{subcategorySlug}', 'Site\CategoryController#show')->name('category.show');
And in Site\CategoryController you should be able to use :
public function show($categorySlug, $subcategorySlug){
...
}
and then handle them accodingly.
Json view of my paypal after payment is made
I am desperately trying to access the description which is under the transactions array but can't seem to find a way!
It's totally different if I want to access payment_method for instance all I do is this:
(By the way, I assigned this array to $method)
$method->payer->payment_method , but the same thing doesn't work if I want to access description. All I get is an error.
I'm using laravel 5.5, in case that makes a difference.
I'm doing this because I need to find a way to reference my product in the final page after the paypal payment has been made.
Looks like transactions in an array so if you would like the description of the first one that would look like this.
$method->transactions[0]->description
I'm pretty new to PHP programming and Magento. I wanna to pass the current ProductId from a form within a custom block to a controller (new action).
Yes I know that one method would be to add an input hidden (with my product id) in the custom block form and then to retrieve the Value through a regular:
$this->getRequest()->getPost('myvalue'))
Is there a better way in Magento to retrieve the value within the controller without having to declare extra secret input fields ?
Good for you for wanting to adhere to best practices within Magento! The passing of data to controllers is pretty standard, however. If we look at how the product is added from a product page, we'll actually see the product ID in the form action URL's parameters:
http://domain.com/checkout/cart/add/uenc/uenc_value/product/45573/
...where 45573 is the product ID. Of course this can also be sent to the controller via a hidden input field, which I use all the time. Note that the above is the same as http://domain.com/checkout/cart/add/?uenc=uenc_value&product=45573 in Magento.
Another way of storing data for use in controllers for future use is setting data into a session. For posting data to a controller I wouldn't recommend this method but it's something to keep in mind:
$session = Mage::getSingleton('core/session');
$session->setMyValue(true);
We can then retrieve the data from my_value later just by instantiating the session. Good luck!
Passing your data could be done in different ways :
You could use Magento's magic setters and getters.
So you would have to do this to set the value :
Mage::getSingleton('core/session')->setSomeVariable($value);
and this to retrieve it :
Mage::getSingleton('core/session')->getSomeVariable();
Or you could use the register.
Mage::register('key', $value); //to set your data
Mage::registry('key'); //to get your data
Magento provides a way to construct a URL with the necessary values, calculated against the configuration DOM. Blocks (and therefore block templates) can call Mage_Core_Block_Abstract::getUrl() directly:
$this->getUrl('some_handle/foo/test',array('id'=>'some_value'));
// Mage::getUrl() will work as well
The above would result in the following URL:
http://base_url/frontname/foo/action/id/some_value/
...which can be read in the FooController testAction() as
$this->getRequest()->getParam('id') // 'some_value'
I am trying to code my first codeigniter project. I have a login controller which basically filters the data inputed and calls a model function that checks if the user is found in the database.
What I am trying to do is reuse this controller on the index page. So basically I want to be able to do user login on the index page or on the normal controller page (index.php/login/) without code duplication.
I'm sure there is an easy way to do this, but I'm not sure what the best solution is. Make it a library?
Thanks!
For this I would simply make the form in your view post to the login controller.
As a more generic way to share code and logic throughout your application, take a look at this article:
CodeIgniter Base Classes: Keeping it DRY
You basically give each of your controllers a "type". Being logged in could be a criteria of one of your base controllers, which saves you trying to directly access any of your controllers which is bad mojo.
You can try creating a form on the index page and submit it to index.php/login/. This way you won't need two entry points.
Just do the same as you have done for the login View, specify the same action attribute of the form to the index View, and it will be sent to the same login controller with no need to create the two login controllers. You might want to append a query string in the action attribute of the form to distinguish from which View the request has come.