|
I’m taking a different path to include Magento directly in a Drupal page (block). I’ll post working code when I have it all figured out.
At the moment, I am seeing something that I cannot understand and it may be a bug in Magento.
When I call getProductUrl() from within a Drupal block, I get a result, but the URL is incorrect - the directory path in the URL does not include /store/ which is where my Magento install is located.
I get
http://www.mydomain.com/russell-um-crew-traditional
when the correct URL would be
http://www.mydomain.com/store/russell-um-crew-traditional
The block of code is included in a Drupal page at the URL
http://www.mydomain.com/users/pedro
Here is the code that I am using. I took most of this directly from Mage_Rss_Block_Wishlist
<?php $c = getcwd(); echo "<div style='background: #FFF;'>";
chdir('./store/'); // NOTE - though this would help but it didn't. require_once('app/Mage.php'); umask(0);
Mage::app('default');
global $user;
// Retrieve customer_id for Magento account (in Drupal DB) $sql = "SELECT customer_id FROM {magesso} WHERE uid = %d"; $result = db_fetch_array(db_query($sql, $user->uid));
if ($result !== false) { $cid = $result['customer_id']; echo "CUSTOMER ID - $cid <br />"; // DEBUG
$customer = Mage::getModel('customer/customer')->load($cid); if ($customer && $customer->getId()) {
$wishlist = Mage::getModel('wishlist/wishlist') ->loadByCustomer($customer, true);
$collection = $wishlist->getProductCollection() ->addAttributeToSelect('url_key') ->addAttributeToSelect('name') ->addAttributeToSelect('price') ->addAttributeToSelect('thumbnail') ->addAttributeToFilter('store_id', array('in'=> $wishlist->getSharedStoreIds())) ->load();
$product = Mage::getModel('catalog/product'); foreach($collection as $item){ $product->unsetData()->load($item->getProductId()); $description = '<table><tr>'. '<td><a href="'.$product->getProductUrl().'"><img src="' . $product->getThumbnailUrl() . '" border="0" align="left" height="75" width="75"></a></td>'. '<td style="text-decoration:none;">'. $product->getDescription(). '<p> Price:'.Mage::helper('core')->currency($product->getPrice()). ($product->getPrice() != $product->getFinalPrice() ? ' Special Price:'. Mage::helper('core')->currency($product->getFinalPrice()) : ''). ($item->getDescription() && $item->getDescription() != Mage::helper('wishlist')->defaultCommentString() ? '<p>Comment: '.$item->getDescription().'<p>' : ''). '</td>'. '</tr></table>';
echo $description; } } } else { echo 'ERROR: Wishlist not loaded'; }
chdir($c); spl_autoload_unregister('mage_autoload'); // I had to modify __autoload in funcitons.php and use spl_autoload_register in Mage.php to fix conflicts between Magento and Drupal
echo "</div>"; ?>
Is there something that I need to initialize to ensure that Magento returns the correct URLs for my store?
Any suggestions are greatly appreciated.
Sorry for not including the full working URL. The client does not want anyone to see the site during development.
So, in summary - the code works (no errors) but all of the image URLs, and product URLs are slightly incorrect due to the missing /store/ path. If I copy the URL results from the Drupal block and insert /store/ after the host name, they work - even the thumbnails, which are generated dynamically!
I must be pretty dan close to the correct solution.
-ped-
|