my problem is, that i want to get a productUrl from productid (seems simple) BUT i need that productUrl in a file which is called by an ajax post. Ill show u some files to get an overview.
My test.phtml file which contains the link u can click and the ajaxpost which is calling my php file.
<?php
$product_id = Mage::registry('current_product')->getId();
$product = Mage::getModel('catalog/product')->load($product_id);
?>
<?php if(Mage::helper('core')->isModuleOutputEnabled('XXXXX_Productpdf')): ?>
<?php $displayFrontend = Mage::getStoreConfig('datasheet/general/dropdown'); ?>
<?php if($displayFrontend == 1): ?>
<div class="pdfdiv">
<i id="datasheetLoading" class="fa fa-spinner fa-spin"></i><a href="" id="createDatasheet"> <?php echo $product->getName();?> Datasheet </a><label id="generatingDatasheet">Generating Datasheet</label>
<input id="datasheetProductId" type="hidden" value="<?php echo $product_id?>">
</div>
<script>
jQuery("#datasheetLoading").css("display", "none");
jQuery("#generatingDatasheet").css("display", "none");
jQuery('#createDatasheet').click( function() {
var productid = jQuery("#datasheetProductId" ).val();
var myKeyVals = {"productid" : productid};
test = "test";
jQuery.ajax({
type: "POST",
data: myKeyVals,
url: "/app/code/local/XXXXX/Productpdf/pdf/createDatasheet.php",
beforeSend: function(xhr){
jQuery("#datasheetLoading").css("display", "");
jQuery("#createDatasheet").css("display", "none");
jQuery("#generatingDatasheet").css("display", "");
},
success: function(data) {
window.open(data,'_blank' );
jQuery("#datasheetLoading").css("display", "none");
jQuery("#generatingDatasheet").css("display", "none");
jQuery("#createDatasheet").css("display", "");
}
});
return false;
});
</script>
<?php endif ?>
<?php endif ?>
So as u can see this phtml contians a link which call my createDatasheet.php. In this file i need to get the product url all i got is the product id. createDatasheet.php:
<?php
require_once("../../../../../Mage.php");
umask(0);
Mage::app();
$productid = $_POST["productid"];
$product = Mage::getModel('catalog/product')->load($productid);
$productName = $product->getName();
?>
If i echo the $productName there comes the name of my product so this part works so what i need now is:
$productUrl = ?
what i have tried:
Mage::getUrl().$product->getUrlPath();
Mage::getUrl().$product->getUrlPath();
$product->getUrlInStore();
$product->getProductUrl();
Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'attribute_code', $storeId);
What it should return
http://magento2.dev/index.php/categoryName/productName.html
What it actually return
http://magento2.dev/createDatasheet.php/productName.html?SID=s8v4n82sotc3tv7dpot8dq6df6
If i call the $product->getProductUrl(); in my test.phtml file i get the url i need.