【问题标题】:Programatically Generated Bundled Products Not Displaying on Category Page以编程方式生成的捆绑产品未显示在类别页面上
【发布时间】:2013-11-21 22:27:54
【问题描述】:

我正在使用 Magmi 和一些自定义代码生成许多捆绑产品:

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


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

error_reporting(E_ALL);
ini_set('display_errors',1);

//Get bundled products

$products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSelect('type')
    //->addAttributeToFilter('type_id', 'bundle') // simpler..
    ->addFieldToFilter('type_id', array('eq' => 'bundle')) // simple/configurable etc
;


foreach ($products as $product){

      $parentProduct = clone $product;

    // get all the options of your bundle product assumed as $bundle

    // remove the Selection/Bundle association from database, we need to pass all the others except the one we need to drop

    Mage::getModel('bundle/mysql4_bundle')->dropAllUnneededSelections();

    $options = $product->getTypeInstance()->getOptionsCollection();

    foreach ($options as $option){
          $option->delete();
    }



    $simple_skus = explode(",",$product->getBundledSkus());
    $items = array();
    $selections = array();

    $simple_skus = array_reverse($simple_skus);
    foreach ($simple_skus as $sku){
          if ($sku == '')continue;

          $selectionRawData = array();

          $pos = 0;
          $pos++;
          $productId = $product->getIdBySku($sku);
          $simple =   $product->load($productId);


                $items[] = array(
                'title' => $simple->getName(),
                'parent_id' => $parentProduct->getId(),
                'option_id' => '',
                'delete' => '',
                'type' => 'checkbox',
                'required' => ( strpos($sku,'harness') !== false ? 1 : 0),
                'position' => $pos);

            $selections[][] = array(
                'selection_id' => '',
                'option_id' => '',
                'product_id' => $simple->getEntityId(),
                'delete' => '',
                'selection_price_value' => $simple->getPrice(),
                'selection_price_type' => 0,
                'selection_qty' => 1,
                'selection_can_change_qty' => 0,
                'position' => 0);

    }


            Mage::unregister('product');
            Mage::unregister('current_product');
            Mage::register('product', $parentProduct);
            Mage::register('current_product', $parentProduct);
            $parentProduct->setCanSaveConfigurableAttributes(false);
            $parentProduct->setCanSaveCustomOptions(true);

如果您在后端查看它,一切似乎都设置正确,如果您输入 URL,您可以直接转到产品,一切正常,可以将其添加到购物篮等 - 请参阅 @987654321以@为例。

但是,即使产品已分配到正确的类别,它也不会返回任何类别或搜索的产品。

如果我在后端创建捆绑产品,使用与生成的捆绑包完全相同的值,它会按预期工作和显示。

我尝试过的一些事情:

  • 我已重新编制索引(很多次)
  • 我已清除缓存
  • 我已截断所有 magento 产品表、平面表等,并从头开始重新导入
  • 我尝试复制其中一个导入的产品并从中保存一个新产品
  • 产品都有现货
  • 捆绑的产品具有搜索可见性、目录
  • 简单产品的可见性为 Not Individually Visible

我确定我错过了一些明显的东西,我需要更新的表格或其他东西,但我不确定是什么!

【问题讨论】:

  • 如果您从管理员那里对这些新产品之一点击保存并启用保存时重新索引,它会显示吗?如果是这样,那是你错过的某个地方的缺失属性。需要在每个目录产品实体表和捆绑产品中比较好产品和坏产品以找到缺失的属性是我的赌注。
  • 嗨@AshleySwatton 感谢您的留言。不,可悲的是,从后端重新保存产品并没有帮助。
  • 可悲的是,解决方案将在某处的数据库中。手动创建与您在 admin 中生成的产品相同的产品,并通过数据库中以 catalog_ 开头的每个表对其进行跟踪。从 product_entity 表开始,然后从那里向外工作。记下用于工作产品与非工作产品的所有属性 ID 和值,直到您找到不同的东西并为坏产品手动添加或更改它,重新索引并重新测试。 catalog_product_website 之前就已经让我失望了。祝你好运。
  • 我也面临同样的问题,我能找到的区别是当我从后端保存产品时,它出现在搜索中,而且,从后端保存后,一个新的输入进入 catalogsearch_fulltext ,任何人可以告诉我如何克服这个问题,我不能简单地把条目放在表中..
  • 检查 catalog_product_index_price 值是否为空。在产品列表中,该表有一个内部联接。

标签: php magento


【解决方案1】:

我以编程方式创建的捆绑产品遇到了完全相同的问题:没有出现在目录或搜索结果中,但通过直接 url 访问时能够看到产品。

正如@MagePsycho 提到的,这是由于catalog_product_index_pricecatalog_product_index_price_bundle_idx 表中缺少条目造成的。

在保存捆绑产品之前添加对 $bundle_product->setData('price_type', 0); 的调用解决了该问题。

但是,我看到您通过克隆另一个捆绑产品来获得捆绑产品,因此我不确定此解决方案是否可行。请试一试。

【讨论】:

    猜你喜欢
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多