cancel
Showing results for 
Search instead for 
Did you mean: 

Review Request Script sending wrong product url on multistore, how to pass storeID in items.phtml?

Review Request Script sending wrong product url on multistore, how to pass storeID in items.phtml?

Hiya, this has been absorbing my entire day, it's not working for me.

We have this script that sends review requests, but we noticed the URLs are wrong, they look like this (causing 404 errors + a whole other teststore)

[https://www.installurl.com]/magento/index.php/catalog/product/view/id/284/s/xyzmedium/?___store=admin

 It should go here:
 

[https://www.multistoreurl.com/]collection/xyzmedium.html

 

The URL in the items.phtml is this:

 

<?php echo $_item->getUrlInStore(); ?>

 

I now know that with this change it will work fine:

 

<?php echo $_item->setStoreId(2)->getProductUrl(); ?>

BUT, how do i get this setStoreId(2) to be the dynamic storeID?

I have tried just about everything.

 

This is the email template line that calls the items:

 

{{block type="core/template" template="scrpt/email/items.phtml" products=$data}}

This is a block from the Helper file:

 

protected function _sendEmail($email, $customer, $data, $emailTemplateId, $store, $storeId)
{
if ($this->_config->isBlacklisted($email, $store)) {
return true;
}
/* @var $translate Mage_Core_Model_Translate */
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
$sender = $this->getSender(
$this->_config->getEmailSender($store),
$store->getId()
);
$storeId = $store->getId();
try {
/* @var $tpl Mage_Core_Model_Email_Template */
$tpl = Mage::getModel('core/email_template');
$tpl->getTemplateFilter()->setStoreId($store->getId());
$tpl->sendTransactional(
$emailTemplateId,
$sender,
$email,
$customer,
array(
'customer_name' => $customer,
'data' => $data,
'sender' => $sender,
'url' => Mage::getBaseUrl(),
//'url' => Mage::app()->getStore($store->getId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK),
),
$store->getId()
);
$translate->setTranslateInline(true);
$ret = true;
} catch(Mage_Core_Exception $exc) {
$ret = false;
}
//echo "Sore is " . $store->getId();exit;
return $ret;
}

 

I have no idea where to look next, if anywhere.

 

Please help.

 

ps/edit:

 

Here's acopy of the actual items.phtml

<?php $_products = $this->getProducts() ?>
<?php if ($_products): ?>
<table cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
    <?php $i = 0;
    foreach ($_products as $_item): ?>
        <?php $_item->load() ?>
        <tbody<?php echo $i % 2 ? ' bgcolor="#F6F6F6"' : '' ?>>
        <tr>
			<td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
                <img src="<?php echo $_item->getImageUrl(); ?>" style="width: 85px;"/>
            </td>
            <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
                <a href="<?php echo $_item->setStoreId(2)->getProductUrl(); ?>"><strong style="font-size:11px;"><?php echo $this->escapeHtml($_item->getName()) ?></strong></a>
            </td>
            <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;"><?php echo $this->escapeHtml($_item->getSku()) ?></td>
        </tr>
        </tbody>
        <?php endforeach; ?>

    <tbody>
    </tbody>
</table>

<?php echo "TEST: ST2 = ".$storeId; ?>

<?php endif; ?>

 

 

Tags (2)
2 REPLIES

Re: Review Request Script sending wrong product url on multistore, how to pass storeID in items.phtm

I haven't seen your entire script but it's wise to emulate the environment when sending email templates. Emulating an environment involves telling Magento what store context to consider for any requests. It essentially sets the storeId in the belly of Magento so you don't need to setStoreId on everything. 

 

This is something that Magento does for most of it's email sending approaches so you can take inspiration from them. See the product alert template here: https://github.com/OpenMage/magento-mirror/blob/505e8e982ad5f4fd22005060564cad210aab7b6f/app/code/co...

 

It emulates the environment, taking note of the initial environment:

 

 

$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

and then restores the original environment after:

 

$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Review Request Script sending wrong product url on multistore, how to pass storeID in items.phtm

I'll read up on that, thank you.