当前位置: 首页 > 面试题库 >

如何仅使用mysql在magento中提取所有产品ID,Skus,产品名称,说明?

楚奇逸
2023-03-14
问题内容

我如何使用Magento数据库中的mysql提取所有的产品目录ir,skus,产品名称(标题)和desxription?我使用以下查询并获得了除产品名称以外的所有属性。

SELECT e.entity_id, e.sku, eav.value AS 'description'
FROM catalog_product_entity e
JOIN catalog_product_entity_text eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE ea.attribute_code = 'description'

问题答案:

一个商店视图的标题可能与另一个商店视图的标题不同。相同的描述。另外,某些商店视图可以使用后端中设置的默认值。

这是有关如何获取特定商店视图(标识1)的所有产品所需的数据(SKU,名称,说明)的完整查询。

SELECT 
    `e`.`sku`, 
    IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
    IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

FROM 
   `catalog_product_entity` AS `e` 
    INNER JOIN 
         `catalog_product_entity_varchar` AS `at_name_default` 
               ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_name_default`.`store_id` = 0 
    LEFT JOIN 
          `catalog_product_entity_varchar` AS `at_name` 
               ON (`at_name`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_name`.`store_id` = 1) 
    INNER JOIN 
         `catalog_product_entity_text` AS `at_description_default` 
               ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_description_default`.`store_id` = 0 
    LEFT JOIN 
          `catalog_product_entity_text` AS `at_description` 
               ON (`at_description`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_description`.`store_id` = 1)

如果您希望将其用于其他商店视图,只需1在以下几行中将值替换为所需的ID

(`at_name`.`store_id` = 1)

(`at_description`.`store_id` = 1)

我不知道为什么您需要sql格式的文件。这是一个奇怪且大的错误源。您可以通过代码轻松获得它:

$collection = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToSelect(array('sku', 'name', 'description'));
foreach ($collection as $item) {
    $sku = $item->getSku();
    $name = $item->getName();
    $description = $item->getDescription(); 
    //do something with $sku, $name & $description
}


 类似资料:
  • 我想使用属性名称获取WooCommerce产品属性的ID。例如 我知道产品属性是分类法,但是get_taxonomy()不会返回分类法ID。我找不到一个可以这样做的Woocommerce函数。

  • 让我告诉你一个我遇到的问题的例子。例如,我们有一个名为“订单”的表,其中插入了所有订单和采购。 表A(订单): 现在我想订购并获得我们最畅销的产品,例如在最畅销产品列表中获得pro3排名。 查询输出: 我写了这个查询: 结果对我没用。例如,我需要让pro27在畅销产品中排名(我们有100000个产品!)

  • 问题内容: 我有以下代码: 尽管它可以完成预期的工作,但却大大减慢了页面加载时间。是否可以仅加载可配置产品并删除“可配置”检查?该商店有12000种产品,其中大约700种是可配置的,其余的是儿童简单产品。 我发现以下代码返回了所有可配置产品。我只需要当前类别中的产品: 问题答案: 问题在于它已经被加载- 产品的数据已经从数据库中检索到。仅使用当前类别的产品集合也不足够,这将忽略“图层”(属性过滤器

  • 本文向大家介绍magento 通过SKU获取产品,包括了magento 通过SKU获取产品的使用技巧和注意事项,需要的朋友参考一下 示例            

  • 功能简介 排队 排队功能是在高峰时段、高峰区域,乘客的数量大于司机的数量时,乘客端发出的用车需求进行排队,按照“先到先得”的原则顺序进行车辆的指派。 具体参见:排队 取消改派 司机接单后,由于司机原因取消订单,会为乘客进行订单改派,而不是直接关单。 具体参见:取消改派 最短接驾时间预估 最短接驾时间预估是在定位起点后,乘客下单前,获取的周边可接驾司机的预估接驾时间。信息可做乘客下单前参考。 具体参