【问题标题】:Table coupling the product attributes and the orders in magento将产品属性和magento中的订单耦合的表格
【发布时间】:2018-03-17 22:24:13
【问题描述】:

哪个表将订单和相关订单的产品属性(如尺寸、颜色和价格)耦合在一起?

例如,如果我的订单中包含一件衬衫,我需要通过查询获取衬衫的颜色和尺码。

【问题讨论】:

    标签: magento magento-1.7 magento-1.9 magento-1.8


    【解决方案1】:

    首先,您需要从订单中获取产品 ID 并获取该产品的超级属性。

    $order_id = 10002; // Your order ID;
    $order = Mage::getModel('sales/order')->load($order_id);
    $items = $order->getAllVisibleItems();
    foreach($items as $item) {
    $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql        = ("SELECT * FROM (
        SELECT 
            ce.sku,
            ea.attribute_id,
            ea.attribute_code,
            CASE ea.backend_type
               WHEN 'varchar' THEN ce_varchar.value
               WHEN 'int' THEN ce_int.value
               WHEN 'text' THEN ce_text.value
               WHEN 'decimal' THEN ce_decimal.value
               WHEN 'datetime' THEN ce_datetime.value
               ELSE ea.backend_type
            END AS value,
            ea.is_required AS required
        FROM catalog_product_entity AS ce
        LEFT JOIN eav_attribute AS ea 
            ON ce.entity_type_id = ea.entity_type_id
        LEFT JOIN catalog_product_entity_varchar AS ce_varchar 
            ON ce.entity_id = ce_varchar.entity_id 
            AND ea.attribute_id = ce_varchar.attribute_id 
            AND ea.backend_type = 'varchar'
        LEFT JOIN catalog_product_entity_int AS ce_int 
            ON ce.entity_id = ce_int.entity_id 
            AND ea.attribute_id = ce_int.attribute_id 
            AND ea.backend_type = 'int'
        LEFT JOIN catalog_product_entity_text AS ce_text 
            ON ce.entity_id = ce_text.entity_id 
            AND ea.attribute_id = ce_text.attribute_id 
            AND ea.backend_type = 'text'
        LEFT JOIN catalog_product_entity_decimal AS ce_decimal 
            ON ce.entity_id = ce_decimal.entity_id 
            AND ea.attribute_id = ce_decimal.attribute_id 
            AND ea.backend_type = 'decimal'
        LEFT JOIN catalog_product_entity_datetime AS ce_datetime 
            ON ce.entity_id = ce_datetime.entity_id 
            AND ea.attribute_id = ce_datetime.attribute_id 
            AND ea.backend_type = 'datetime'
        WHERE ce.entity_id = ".$item->getProductId()."
      ) AS tab
      WHERE tab.value != ''")
    $rows       = $connection->fetchAll($sql); 
    print_r($rows);
    }
    

    Reference link

    【讨论】:

    • 谢谢,这个 SQL 给出了给定产品的所有属性选项。但我只想获取特定于订单的属性选项。例如:如果订单是一件 T 恤,我想获取所订购 T 恤的尺寸和颜色
    • 确定您从该列中获得的特定订单 SELECT product_options FROM sales_flat_order_item 在magento中,您将从订单项中获得这样的信息。 $orderItem->getProductOptions()。在数据库中以序列化格式保存了此详细信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 2017-09-25
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    相关资源
    最近更新 更多