Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 2
How to embed a block from magento shop on another website
 
iguru
Guru
 
Avatar
Total Posts:  331
Joined:  2007-11-01
Děčín, Czech Republic
 

i change product_list to call getImageURL

<div>
    
<?=$this->helper('catalog/product')->getProductUrl($_prod)."\n"
   
.$this->helper('catalog/product')->getPriceHtml($_prod)."\n"
   
.$this->helper('catalog/product')->getImageURL($_prod)."\n"
;?>
  
</div>
but i got this message

Fatal error: Call to undefined method Mage_Catalog_Helper_Product::getData() in /home/mimo/Documents/www/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php on line 33

where is problem?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 
iguru - 29 February 2008 03:36 PM

i change product_list to call getImageURL

but i got this message


Fatal error: Call to undefined method Mage_Catalog_Helper_Product::getData() in /home/mimo/Documents/www/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php on line 33

where is problem?

Try getImageUrl… case matters.

I think this could be a bug.  Helpers do not subclass Varien_Object, but yet they obey the same magic method calls for get*() ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

Go ahead and change some code, the proper way to get images will change in the next release, so you’ll have to find a different way.

But to solve your immediate problem, change the following code:

from (app/code/core/Mage/Catalog/Helper/Product.php at line 88)

81     public function getImageUrl($product)
   
82     {
   83         $url 
false;
   
84         if (!$product->getImage()) {
   85             $url 
Mage::getDesign()->getSkinUrl('images/no_image.jpg');
   
86         }
   87         
elseif ($attribute $product->getResource()->getAttribute('image')) {
   88             $url 
$attribute->getFrontend()->getUrl($this);
   
89         }
   90         
return $url;
   
91     }

to

81     public function getImageUrl($product)
   
82     {
   83         $url 
false;
   
84         if (!$product->getImage()) {
   85             $url 
Mage::getDesign()->getSkinUrl('images/no_image.jpg');
   
86         }
   87         
elseif ($attribute $product->getResource()->getAttribute('image')) {
   88             $url 
$attribute->getFrontend()->getUrl($product);
   
89         }
   90         
return $url;
   
91     }
(change $this to $product in one spot).  Do that for the function “getSmallImageUrl” too.
 
Magento Community Magento Community
Magento Community
Magento Community
 
iguru
Guru
 
Avatar
Total Posts:  331
Joined:  2007-11-01
Děčín, Czech Republic
 

it’s work!!!! grin Thanks thanks thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_magento
Jr. Member
 
Total Posts:  10
Joined:  2008-03-27
 

Hi - I was following the thread about embedding a block from Magento on another page (a non-Magento CMS page), but was unable to properly implement it. I was wondering if someone can list out the proper code snippets for making this work (or attach the proper files).

I basically have a home page that’s outside of Magento. I have created a category called “featured_home_category” in Magento, and have added a product to it (the featued product). I have set the category as “not active” in the Admin, so it doesn’t show up on the store frontend.

I have created a CMS page (via Manage Pages), and inserted the following in the content:
{{block type="catalog/product_list" template="custom/home_export/product_list.phtml" category_id="13"}}

I called that page “home_export”, and set the SEF to “home_export”. I set the status of the page to “Enabled”.

I then created a product_list.phtml file in:
app/design/frontend/my_interface/my_theme/template/custom/home_export/product_list.phtml

and added the following code in it:
<?php
$prods = $this->getLoadedProductCollection();
foreach ($prods as $_prod):?>
<?= $_prod->getName();?>

<div>
<?=$this->helper('review/product')->getSummaryHtml($_prod);?>
</div>
<? endforeach;?>

Then, on my home page, I am making this call:

<?php
require_once ‘/magento/app/Mage.php’;
Mage::app(’base’);
$block = Mage::getSingleton(’core/layout’)
->createBlock("catalog/product_list", “home_export”, array(’category_id’=>13))
->setTemplate("custom/home_export/product_list.phtml");
echo $block->toHtml();
?>

However, nothing is happening.

Can anyone please show me the code for this to work?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_magento
Jr. Member
 
Total Posts:  10
Joined:  2008-03-27
 

Oops, accidentally double-posted. Sorry.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Cacpro
Jr. Member
 
Total Posts:  3
Joined:  2007-10-31
 

I would like to see the complete code step by step directions for this also. If somebody wouldn’t mind posting.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_magento
Jr. Member
 
Total Posts:  10
Joined:  2008-03-27
 

It works. I just had to replace Mage::app(’base’) with Mage::app(’default’). This changed in v1.0

Many thanks to Mark Kimsal for pointing this out to me.

Now, on a related note, how can I show Magento’s cart and newsletter blocks on a non-Magento page (i.e., on another website)? If anyone can post the code snippet here, I’ll make sure that it works and share it with the community.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
DaMoose
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2008-08-04
Los Angeles
 

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($customertrue);

        
$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-

 
Magento Community Magento Community
Magento Community
Magento Community
 
DaMoose
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2008-08-04
Los Angeles
 

I just wanted to add two more things regarding my post (above).

1) the current working directory at the start of the code is DOCUMENT_ROOT. Even though the Drupal path is /users/pedro, the code is executing relative to /. So, the store is in a subdirectory “store”. That is why I chdir into ./store/.

2) I know that I could use the Magento session to determine who the current Magento user is, but this code will eventually change based on the node (node->uid not user->uid).

Cheers,

-ped-

 
Magento Community Magento Community
Magento Community
Magento Community
 
Senunits
Jr. Member
 
Total Posts:  10
Joined:  2009-11-22
 

hey you guys.. i have a problem when i do your example. Do you know how i can manage to fix the issue? 

Warning: Mage_Core_Block_Template::include(/home/hmcmotorcykler/domains/shop.hmcmotorcykler.dk/public_html/app/design/frontend/default/default/template/mystuff/wp_export/product_list.phtml) [mage-core-block-template.include]: failed to open stream: No such file or directory in /home/hmcmotorcykler/domains/shop.hmcmotorcykler.dk/public_html/app/code/core/Mage/Core/Block/Template.php on line 144
Trace:
#0 /home/hmcmotorcykler/domains/shop.hmcmotorcykler.dk/public_html/app/code/core/Mage/Core/Block/Template.php(144): mageCoreErrorHandler(2, ‘Mage_Core_Block...’, ‘/home/hmcmotorc...’, 144, Array)
#1 /home/hmcmotorcykler/domains/shop.hmcmotorcykler.dk/public_html/app/code/core/Mage/Core/Block/Template.php(144): Mage_Core_Block_Template::fetchView()

 
Magento Community Magento Community
Magento Community
Magento Community
 
DaMoose
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2008-08-04
Los Angeles
 

Senunits -

Not sure if you are using my example or on of the others above. I doubt that my sample code still works with a recent version of Magento. I was developing with version 1.2. Magento made a lot of changes between 1.2 and 1.3.

BTW: I stopped using my home grown solution and opted to use the better solution from Maxime Topolov.

http://drupal.org/project/magento
http://www.magentocommerce.com/extension/1020/drupal

 
Magento Community Magento Community
Magento Community
Magento Community
 
bxck75
Jr. Member
 
Total Posts:  9
Joined:  2012-02-29
 

i did the following

Create a new CMS page called “WP export” and do not link to it anywhere.

inside this page, put this in the content

{{block type="catalog/product_list" template="mystuff/wp_export/product_list.phtml" category_id="3"}}

Replace the category_id="3" with your category ID of the products that you want to spit across.

Create this file and/or directories.

app/design/frontend/[yourtheme]/default/template/mystuff/wp_export/product_list.phtml

Inside this product_list.phtml file, you can add whatever code you want to format your products as HTML.  Start with this code:

<?php
$prods 
$this->getLoadedProductCollection();
foreach (
$prods as $_prod):?>

<h3><?$_prod->getName();?></h3>
<
div>
<?=$this->helper('review/product')->getSummaryHtml($_product);?>
</div>
<? endforeach;?>

On the WP-side, you can get this HTML with a network include or fsockopen like this:

include("http://mymagentoinstall/cms/wp_export.html");

The wp part did not work because of include security of server so i used.

<? //beginning of magento product include
$a file_get_contents("http://www.mysite.nl/magento/wp_export.html");
echo (
$a);
//end of magento product include
?>

The magento page shows in wordpress but with the following error

Fatal error: Class â€˜Mage_Review_Helper_Product’ not found in public_html/magento/app/Mage.php on line 546

if i view the same page in magento it also give me the same error msg.
please help.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 2