久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

以編程方式添加的捆綁產品未顯示在前端

Programatically added bundle product isn#39;t showing up in frontend(以編程方式添加的捆綁產品未顯示在前端)
本文介紹了以編程方式添加的捆綁產品未顯示在前端的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試通過 PHP 腳本將捆綁產品插入 Magento 數據庫.有問題的版本是 Community 1.5.1.0.

I am trying to insert bundled products to the Magento database from a PHP script. The version in question is Community 1.5.1.0.

我嘗試了問題使用簡單商品的 SKU/ID 以編程方式在 Magento 中添加捆綁商品".插入的產品在管理部分很好地顯示 - 我可以編輯它們,添加新選項和選擇等.但是,無論我嘗試什么,它們都沒有出現在 Magento 前端 - 例如重建索引或從后端重新保存它們.通過管理界面添加包工作正常.

I tried the method described in the question "Programmatically add Bundle Products in Magento, using the SKU / ID of Simple Items". The inserted products show up nicely in the administration section -- I can edit them, add new options and selections etc. However, they are not showing up at all in the Magento frontend no matter what I try - e.g. rebuilding indexes or re-saving them from the back-end. Adding bundles through the administration interface works fine.

在對數據庫進行一些挖掘后,我注意到在使用我的腳本時 catalog_product_index_pricecatalog_product_index_price_bundle_idx 表中沒有必要的條目,同時通過后臺添加包 -end 正常更新索引.就這些表而言,重新索引只會忽略添加的捆綁產品.

After some digging through the database, I noticed there are no necessary entries in the catalog_product_index_price and catalog_product_index_price_bundle_idx tables when using my script, while adding the bundle through the back-end updates the indexes normally. Re-indexing simply ignores the added bundle product as far as those tables are concerned.

我翻遍了 Magento 源文件,但找不到任何關于我做錯了什么的提示.所有緩存都被禁用,選擇有庫存,我試圖包括我在研究 Magento 在后端插入產品時發送的 POST 請求時挖掘出的所有數據.

I dug through the Magento source files and can't find any hints on what I'm doing wrong. All caches are disabled, selections are in stock, and I tried to include all data I dug up while studying the POST request Magento sends while inserting the product in the back-end.

這是我用于測試的完整腳本,以及底部注釋掉的一些絕望的嘗試:

Here's the complete script I use for testing, along with some desperate attempts commented out at the bottom:

$magentoPath = '/home/nikola/bin/magento-1.5/';
require_once($magentoPath . 'includes/config.php');
require_once($magentoPath . 'app/Mage.php');

$storeID = 1;
$websiteIDs = array(1);

$mageObj = Mage::app()->setCurrentStore($storeID);

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

$cats = array("210");
$p = array(
  'sku_type' => 0, 
  'sku' => 687, 
  'name' => "BarProduct", 
  'description' => 'Foo', 
  'short_description' => 'Bar',
  'type_id' => 'bundle', 
  'attribute_set_id' => 4, 
  'weight_type' => 0, 
  'visibility' => 4, 
  'price_type' => 0, 
  'price_view' => 0, 
  'status' => 1, 
  'created_at' => strtotime('now'), 
  'category_ids' => $cats, 
  'store_id' => $storeID, 
  'website_ids' => $websiteIDs
);

$product->setData($p);

$product->setCanSaveBundleSelections(true);
$product->setCanSaveCustomOptions(true);

Mage::register('product', $product);
Mage::register('current_product', $product);

$optionRawData = array();
$selectionRawData = array();

$optionRawData[0] = array(
  'required' => 1,
  'option_id' => '', 
  'position' => 0,
  'type' => 'select',
  'title' => 'FooOption',
  'default_title' => 'FooOption', 
  'delete' => ''
);
$selectionRawData[0] = array(); 
$selectionRawData[0][] = array(
  'product_id' => 1810,
  'position' => 0,
  'is_default' => true,
  'selection_id' => '', 
  'option_id' => '', 
  'selection_price_type' => 0,
  'selection_price_value' => 0.0,
  'selection_qty' => 1,
  'selection_can_change_qty' => 1,
  'delete' => ''
);

$product->setBundleOptionsData($optionRawData);
$product->setBundleSelectionsData($selectionRawData);

$product->save();

/*
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->loadByProduct($product->getId());
if (!$stockItem->getId()) {
  $stockItem->setProductId($product->getId())->setStockId(1);
}
$stockItem->setData('is_in_stock', 1);
$stockItem->save();

$pi = Mage::getSingleton('bundle/price_index');
$pi->addPriceIndexToProduct($product);
$pi->save();
*/

?>

推薦答案

請嘗試使用以下代碼 &看看會發生什么:-

Please try using the following code & see what happens:-

<?php
$magentoPath = '/home/nikola/bin/magento-1.5/';
require_once($magentoPath . 'includes/config.php');
require_once($magentoPath . 'app/Mage.php');

$storeID = 1;
$websiteIDs = array(1);
$cats = array("210");

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

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

$p = array(
  'sku_type' => 0,
  'sku' => '687',
  'name' => "BarProduct",
  'description' => 'Foo',
  'short_description' => 'Bar',
  'type_id' => 'bundle',
  'attribute_set_id' => 4,
  'weight_type' => 0,
  'visibility' => 4,
  'price_type' => 0,
  'price_view' => 0,
  'status' => 1,
  'created_at' => strtotime('now'),
  'category_ids' => $cats,
  'store_id' => $storeID,
  'website_ids' => $websiteIDs
);

$product->setData($p);
Mage::register('product', $product);
Mage::register('current_product', $product);

/**
 * Section of Bundle Options
 * 
 * Required Properties of Bundle Options are:-
 * 1. title
 * 2. option_id
 * 3. delete
 * 4. type
 * 5. required
 * 6. position
 * 7. default_title
 */
$optionRawData = array();
$optionRawData[0] = array(
  'required' => 1,
  'option_id' => '',
  'position' => 0,
  'type' => 'select',
  'title' => 'FooOption',
  'default_title' => 'FooOption',
  'delete' => '',
);

/**
 * Section of Bundle Selections
 * 
 * Required Properties of Bundle Selections
 * 1.   selection_id
 * 2.   option_id
 * 3.   product_id
 * 4.   delete
 * 5.   selection_price_value
 * 6.   selection_price_type
 * 7.   selection_qty
 * 8.   selection_can_change_qty
 * 9.   position
 * 10.  is_default
 */
$selectionRawData = array();
$selectionRawData[0] = array();
$selectionRawData[0][] = array(
  'product_id' => 1810,
  'selection_qty' => 1,
  'selection_can_change_qty' => 1,
  'position' => 0,
  'is_default' => 1,
  'selection_id' => '',
  'selection_price_type' => 0,
  'selection_price_value' => 0.0,
  'option_id' => '',
  'delete' => ''
);

$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);

// Set the Bundle Options & Selection Data
$product->setBundleOptionsData($optionRawData);
$product->setBundleSelectionsData($selectionRawData);
$product->setCanSaveBundleSelections(true);
$product->setAffectBundleProductSelections(true);

$product->save();
?>

希望有幫助.

這篇關于以編程方式添加的捆綁產品未顯示在前端的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 成人av电影网 | 青青久草 | 午夜小视频在线播放 | 中文字幕一区二区三区精彩视频 | 一级毛片播放 | 亚洲欧美日韩激情 | 91手机精品视频 | 久久久久久久一区二区 | 亚洲国产精品91 | 久久久久久亚洲精品 | 精品欧美一区二区三区久久久 | 国产一区二区久久 | 欧美激情久久久 | 国产精品3区 | 91青青草视频 | 99国产精品99久久久久久 | 91精品一区 | 亚洲精品日韩综合观看成人91 | 日韩一区二区在线视频 | 一区二区三区高清 | 久久久国产精品一区 | 久久精品成人 | 国产精品区二区三区日本 | 日韩一区在线观看视频 | 综合第一页 | 精品国产乱码久久久 | 国产精品一二区 | 91精品国产综合久久久久久 | 亚洲精品视频久久 | 久久久精| 久久久久久成人 | 一级做a爰片性色毛片16美国 | 国产高清久久 | 久久机热 | 三级av免费 | 欧洲av一区 | 中国一级毛片免费 | 国产精品久久免费观看 | 一区二区三区免费 | 欧美日韩精品一区 | 伊人网在线综合 |