I have a PDF file that has been generated in ./var/label/somefile.pdf that I want to provide access to in the shipment area of Magento (specific to an order) as a link, but I am not sure what path to provide for the tag. The preference would be for the link when clicked to start downloading the file to the browser and I only want this link accessible to someone that has been logged into admin.
I've attempted the direct path (http://domain.com/var/label/somefile.pdf) which fails with access error as it should and by trying different versions of getVarDir() to no avail.
Files hacked: sales/order/shipment/view/form.phtml
If you need to check if the visitor is logged into admin you need to pass by a Magento controller.
I assume you know the basis about development with Magento or, at worst, can be helped by someone knowing.
First of all, edit (or create, but you'll also need to create the route) a controller extending Mage_Adminhtml_Controller_Action and add a new method action downloadShipmentPdf
const SHIPMENT_PDF_BASE_DIRECTORY = "/var/www/magentorootfolder/var/label/";
public function downloadShipmentPdfAction() {
$pdfName = $this->getRequest()->getParam('pdf',false);
if ($pdfName) {
$pdfContent = file_get_contents(SHIPMENT_PDF_BASE_DIRECTORY . $pdfName . '.pdf')
if ($pdfContent) {
$this->getResponse()->setHeader('Content-type', 'application/pdf');
$this->getResponse()->setBody($pdfContent);
return;
}
}
}
Now you can generate the admin-compliant URL for your PDF by calling
Mage::helper("adminhtml")->getUrl("modulename/controllername/downloadShipmentPdf", array('pdf' => 'thepdfnamewithoutextension');
Related
How to direct user on certain page after successful payment on membership plan using velo code ? cause on wix the users was direct into thank you page
When you use pricing-plans you have one editable page but in fact you have three page.
First one is where you list your plans. /pricing-plans/ Second one is
where the payment made. /pricing-plans/payment/ Last one is where the
thank you page is. /pricing-plans/status/
What you need to do is use wix-location and when URL changes to /pricing-plans/status/ send user to another URL.
Here is an example code inside pricing-plans page in editor.
import wixLocation from 'wix-location';
$w.onReady(() => {
wixLocation.onChange((location) => {
if (wixLocation.url.includes("/pricing-plans/status/")) {
wixLocation.to("redirectedUrl");
}
});
})
pricing-plans can be different for your site it's the URL that you choose and you can change so check that before.
Hi i wanted to create a custom form to get input from the user, i can access the form from the url :
http://localhost/website/index.php/contest
but when i uploaded it to a server which has multiple website setup in the magento, i could not access the form like i used to on local server.
http://www.website.org/index.php/contest
i am stumped , i hit a wall i googled, i just don't know what to look for , any help will be greatly appreciated. Thanking anyone in advance
Magento routing is a sort of big topic to cover in a single Stack Overflow answer. You can read about the basics of setting up a controller here, and the probably in too much depth routing process here.
That said, here's some general debugging tips.
Can Magento see the module your controller is a part of? If not, you're probably missing your file in app/etc/modules. (look at the module list in `System -> Configuration -> Advanced -> Disable Module Output)
If your module is installed, Magento probably can't find your controller class. Eitehr because it's not there, of you have a case sensitivity issue. Add some temporary debugging code to the _validateControllerClassName function to determine why Magento can't find your controller.
You can find the _validateControllerClassName function here
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
return false;
}
return $controllerClassName;
}
Some var_dumps before the return false clauses should tell you why Magento can't find and/or include your controller class file.
Im using Magento EE version 1.12 with Full page cache enabled
a) my product detail page is cached
b) as a result my shopping cart in this page doesn't show dynamic item count
c) so i am not able to show valid cart item count in my product detail page
steps i followed
1) I created a block and called from header.phtml
2) trying to make that topcart.phtml block not to be cached
As im a newbie in magento , i got some links for cache hole punching
I followed below links but no success
my file structure
app- code - local - Enterprise - PageCache ->etc - cache.xml
and PageCache - model -container - TopCart.php
code as shown below
help link one
help link two
link three
i created files
cache.xml and cart.php container file
<page_html_topcart>
<block>page/html_topcart</block>
<name>topcart</name>
<placeholder>PAGE_HTML_HEADER_CART</placeholder>
<container>Enterprise_PageCache_Model_Container_TopCart</container>
<cache_lifetime>36400</cache_lifetime>
</page_html_topcart>
this is my topcart.php container file looks like
protected function _getIdentifier()
{
$cacheId = $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '')
. '_'
. $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER_LOGGED_IN, '');
return $cacheId;
}
protected function _getCacheId()
{
return 'CONTAINER_TOPCART_' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}
protected function _renderBlock()
{
$block = $this->_getPlaceHolderBlock(); //('page/html_header_cart');
Mage::dispatchEvent('render_block', array('block' => $block, 'placeholder' => $this->_placeholder));
return $block->toHtml();
}
kindly help me out with useful links and step
I faced the same issue. So, i think, the problem is, that we don't have cachable template in this case. So if you cache it the way you did (and as I did, too), you end up in a base64 encoded list of links in your cache file. To validate that, I uncompressed the files in var/full_page_cache - and here we go: the cart count is cached and won't be changed even if your cart changes, and it would be not replaceable on server side (at least not in a clean way).
The reason for this behaviour is a simple one: For FPC, you render templates only, passing some values. But the template only renders a list in that special case, accessing only one block method (getLinks). In your layout xml files, you will find some calls of "addLink", which feeds that block, that's why all the results become base64 encoded and end up in your cache file. They are not accessable by your container.
But I think, there is a way to fix that. Just collect the links you want to be rendered and create a custom template and a custom block for that. You'll now be able to cache it in a proper way.
I have a payment gateway integrated on my website. When user is done with payment he/she is redirected to a particular page say www.example.com/redirect. I want to prevent users from directly entering this url (www.example.com/redirect) in address bar and access the page. I want it asap.
Actually the page is protected from guest users but if logged in user types that url then it will redirect him to that page and hence the payment option will be skipped. I want the user must pay the amount first and then redirected to this page.
Hard to answer precisely since you only give a non-joomla url as an example, but at the top of every Joomla script is the following line:
defined('_JEXEC') or die( 'Restricted access' );
You obviously can't prevent a user from typing in the url, so this will at least detect if a session is already in place. If the user isn't in an active Joomla session, this will fire and prevent access. You could easily adapt it to do whatever you want to happen for your requirement, depending on whatever you have to check with, i.e. if the referrer is your payment gateway, etc.
I had a similar desire. I wanted the page to only display if the users was logged in and if they had filled out the order entry page.
What I decided to do was check to see if there was data in the POST.
controller/place_order.php (snipet)
public function submitOrder()
{
$post = JRequest::get('post');
$model = $this->getModel();
if($post != null && $post != ''){
if($model->placeOrder()){
}
}
JRequest::setVar('layout', 'submitOrder');
parent::display();
}
This prevents the task from executing my placeOder function anything in the model. Then I just add something similar to the submit order page. In your case "redirect".
view/place_order/tmpl/submitOrder.php (snipet)
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to access this page.</p>";
}
else if($_POST == "" || $_POST == null){
echo "<p>You can not directly access this page.</p>";
}else {
//Your order was submitted successfully HTML (don't forget to close it at the bottom ;)
There are a lot of ways you could do it... you probably don't even need to check in the controller if you don't want to but I do to save on time. With out seeing your code it's hard to tailor the answer but if you grasp the concept here it should help (I hope...).
You might also want to check out this page from Joomla on authorization and privileges.
this should be done in your component's base controller (controller.php). if you look at this code snippet:
// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403,
JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}
this block of code is present in most of core components intended to do exactly what you want. how ever how this actually dos what it does is explained through the $this->checkEditId() function. I hope you are familiar with the JControllerForm class and if you are not check out the API. because creating an edit id for a page and "authorizing user for access to a specific page based on his last page" is done by JControllerForm.
Currently I'm experiencing a problem after editing orders in the Magento admin. The page is always redirected to another URL, the base of which belongs to the store view that the order belongs to. And this page requires re-login to the admin.
For example, I have two base URLs, each belongs to one store view:
www.example.old.com //old store view (default)
www.example.new.com //new store view
The system uses www.example.old.com as the default base URL. So under www.example.old.com I create an order for the new store and invoice it. Then on submitting the invoice, the page is redirected from
http://www.example.old.com/index.php/admin/sales_order_invoice/new/order_id/1234/
to
http://www.example.new.com/admin/sales_order/view/order_id/1234/
And it requires login for another time.
I traced the redirection code to Mage_Core_Model_Url
public function getRouteUrl($routePath=null, $routeParams=null)
...
$url = $this->getBaseUrl().$this->getRoutePath($routeParams);
public function getBaseUrl($params = array())
....
if (isset($params['_store'])) {
$this->setStore($params['_store']);
}
....
return $this->getStore()->getBaseUrl($this->getType(), $this->getSecure());
Then I don't know what to do. There is no parameter _store but it seems that Magento determines which store view to run based on the order being treated, when it is supposed to stay on the same base URL throughout the admin.
Have you tried to enable customer data sharing between the stores in the backend?
Sorry for newbie answer, still learning magento
For those who may still show interests to this old entry, I share my solution. It is not a good one, indeed it is a hard-coded redirection to avoid going back to an uncertain URL, but it fixed the problem for me.
In the controller action where the redirection happens, modify
$this->_redirect(..., array(... => ...));
to
$this->_redirect(..., array(... => ..., '_store' => Mage::app()->getStore($storeId)));
This ensures that the redirection always goes to the specified store.
Reason is that Magento switchs context to store of order because it requires to translate the email template correctly.
Look at class Mage_Core_Model_Template there are two method _applyDesignConfig and _cancelDesignConfig. First function switches context and remember old context, second function should return all back. But, there is a bug. See more at: http://www.magthemes.com/magento-blog/magento-142-multiwebsite-admin-redirect-problem-quick-workaround/#comment-1084