laravel-bladeebay-apiebay-design-templates

Ebay item description destroy my page structure


I'm using ebay api to fetch items to my site with callname=GetSingleItem and everything is OK.

Please see the below code segments that I used to fetch details of the item

    $res = $api -> get ( "http://open.api.ebay.com/shopping?"
                        . "callname=GetSingleItem&"
                        . 
   "IncludeSelector=Description,ItemSpecifics,Details&"
                        . "ItemID=" . $listing -> platform_key . '&'
                        . "appid=$ebayAppId&"
                        . "version=".$version ) ;

                    $xml = simplexml_load_string ( $res -> getBody () ) ;
                    $json = json_encode ( $xml ) ;
                    $jsonResult = json_decode ( $json , TRUE ) ;

Then I fetch Its details via below code segment

     $ebayItemArray[ "description" ] = ( $jsonResult[ "Item" ][ "Description" ] 
   )

Please note that above code segments are just sample codes

So I use this description via below code segment in Laravel blade.php

      <div class=container text-left">
                            {!!$ebayItemArray[ "description" ]!!}
                        </div>

So this works well without any errors for some products but for some products when I try to display description it destroy my layout styles like below

snip 01 snip 02

WHEN I REMOVE THE DESCRITION VARIALBE FROM THE BLADE FILE THEN THINGS WORK FINE AS THEY SHOULD BE


Solution

  • As per documentation:

    If the Description value is used, the full description is returned, with all HTML, XML, or CSS markup used in the listing (if any) by the seller. To only view the actual text of the listing description (no markup tags), the TextDescription value shall be used instead.

    So it's probably the additional CSS that destroys your page structure.

    You have the options

    1. convert Description value to plain text
    // Not tested...
    $description = $jsonResult[ "Item" ][ "Description" ];
    $doc = new DOMDocument();
    $doc->loadHTML($description); // Load as HTML
    removeElementsByTagName('style', $doc); // Remove the <style> Tag
    $description = strip_tags($doc->textContent); // To plain Text
    $ebayItemArray[ "description" ] = $description;
    
    1. use IncludeSelector=TextDescription
    $res = $api -> get ( "http://open.api.ebay.com/shopping?"
                            . "callname=GetSingleItem&"
                            . 
       "IncludeSelector=TextDescription,ItemSpecifics,Details&"
                            . "ItemID=" . $listing -> platform_key . '&'
                            . "appid=$ebayAppId&"
                            . "version=".$version ) ;
    
    1. use an iFrame where you insert the description
    <iframe 
      title="Description" 
      srcdoc="{!!$ebayItemArray[ "description" ]!!}"
      width="300px" height="300px"
    ></iframe>
    

    With iFrame, you also need to auto resize the height of the iFrame.