2013-09-30 31 views
0

我使用此代碼,以便在Magento編程更改產品佈局Magento的02年7月1日

,並創建編程產品我有2個約產品標籤產品頁面佈局有關問題。

<?php 

    //$product = Mage::getModel('catalog/product'); 
    $product = new Mage_Catalog_Model_Product(); 

    // Build the product 
    $product->setSku('some-sku-value-here'); 
    $product->setAttributeSetId('9');# 9 is for default 
    $product->setTypeId('simple'); 
    $product->setName('Some cool product name'); 
    $product->setCategoryIds(array(42)); # some cat id's, 
    $product->setWebsiteIDs(array(1)); # Website id, 1 is default 
    $product->setDescription('Full description here'); 
    $product->setShortDescription('Short description here'); 
    $product->setPrice(39.99); # Set some price 

    //Default Magento attribute 
    $product->setWeight(4.0000); 

    $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); 
    $product->setStatus(1); 
    $product->setTaxClassId(0); # default tax class 
    $product->setStockData(array( 
    'is_in_stock' => 1, 
    'qty' => 99999 
    )); 

    $product->setCreatedAt(strtotime('now')); 

    try { 
    $product->save(); 
    } 
    catch (Exception $ex) { 
    //Handle the error 
    } 

    ?> 

1)我想也改變programmaticaly產品頁面佈局 - 它應該總是「1頁面佈局」。

那麼,如何設置programmaticaly的ID = page_layout成 「1個頁面佈局」?

2)我已知道,我不能添加標籤的品有些相反的是可能的。

因此,如何對產品ID添加到一個標籤編程的關係?

回答

1

試試這個頁面佈局

$product->setPageLayout('one_column'); 

而對於標籤試試這個: 假設你已經有了標籤與標識$tagId

$productsIds = array(1,4,5,6);//put here your product ids. 
$tag = Mage::getModel('tag/tag')->load($tagId); 
$tagRelationModel = Mage::getModel('tag/tag_relation'); 
$tagRelationModel->addRelations($tag, $productIds); 
$model->save();//not sure if this line is needed.