gpt4 book ai didi

mysql - 加入二手产品进行产品收集

转载 作者:行者123 更新时间:2023-11-29 01:56:11 25 4
gpt4 key购买 nike

我一直在为我的问题寻找没有效果的解决方案。

我想列出简单的可配置产品和可配置的二手产品。问题在于性能,因为要获得二手产品,我必须使用这种方法:

Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product)

只属于一个项目。您可以想象,对于很多产品,有大量的 SQL 查询。如何进行将 used_products 属性添加到集合中的查询?

最佳答案

getUsedProductCollection()@b.enoit.be建议是一个很好的起点。

原代码:

public function getUsedProductCollection($product = null)
{
$collection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')
->setFlag('require_stock_items', true)
->setFlag('product_children', true)
->setProductFilter($this->getProduct($product));
if (!is_null($this->getStoreFilter($product))) {
$collection->addStoreFilter($this->getStoreFilter($product));
}

return $collection;
}

你需要什么:

复制并调整以查找多个可配置产品的二手产品:

$collection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')
->setFlag('require_stock_items', true)
->setFlag('product_children', true);

$collection->getSelect()->where('link_table.parent_id in ?', $productIds);
$collection->getSelect()->group('e.entity_id');

$productIds 必须是一个包含所有可配置产品 ID 的数组。它是否也包含简单产品的 ID 并不重要。您可以改为构建 JOIN,但由于无论如何您都需要这些,我建议您首先加载原始集合,然后再加载使用过的关联产品。替代方案可能是使用 UNION 和 JOIN 的大型查询,如果没有显着的性能提升就很难理解。

group('e.entity_id') 确保每个产品只被选择一次,以避免由于集合中的重复项而导致异常。

关于mysql - 加入二手产品进行产品收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28281200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com