xml выгрузка товаров из drupal commerce

Отправлено planktun от пн, 04/09/2018 - 20:11

function ymlexport()
{
    $type = "goods"; 
    $nodes = node_load_multiple(NULL, array('type' => $type)); 
    
    $NODE=node_load($nodes[0]);
    // echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    // <head>
        // <meta name="viewport" content="width=device-width, initial-scale=1">
        // <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>';
        
        
        echo '<?xml version="1.0" encoding="utf-8"?>
<yml_catalog date="'. date("Y-m-d H:i").'">
<shop>
<name>ЭФСТО</name>
<company>ЭФСТО</company>
<url>http://ef100.ru</url>
<categories>
';

$tax=taxonomy_get_tree(2,  0);
//echo '<pre>1',print_r($tax,true),'</pre>';
foreach($tax as $tid)
{
    echo "<category id='{$tid->tid}'>{$tid->name}</category>
    ";
}

echo '</categories>
<offers>
';

        
    foreach($nodes as $products)
    {
        //echo '<offer>';
        //загружаем товар
        $prod=commerce_product_load($products->field_goods_shop['und'][0]['product_id']);
        $src =  file_create_url($prod->field_img_goods['und'][0]['uri']);
        //echo '<pre>1',print_r($prod,true),'</pre>';
        
        $patch = drupal_get_path_alias("node/{$products->nid}");
        echo '<offer id="'.$prod->sku . '" available="true">
<url>http://ef100.ru/'.$patch.'</url> 
<name>'.$products->title.'</name>
<price>'.$prod->commerce_price['und'][0]['amount'].'</price>
<categoryId>'.$products->field_goods_categories["und"][0]["tid"].'</categoryId>
<picture>'.$src .'</picture>
<vendor>ЭФСТО</vendor>
<vendorCode>1</vendorCode>
<description>'.$products->title.'</description>
</offer>

';
        
    }    
    
    
echo '
</offers>
</shop>
</yml_catalog>';    
    

Теги