【问题标题】:Get product features using feature_id and id_feature_value in prestashop 1.7在 prestashop 1.7 中使用 feature_id 和 id_feature_value 获取产品功能
【发布时间】:2020-07-17 02:06:16
【问题描述】:

我想使用 prestashop 1.7 的核心文件自定义运输方式 在 php 上,我有一个数组 features。在产品数组中,功能只有 id。 id_featureid_feature_value。但我需要获取特征名称和值的实际值。

$products = Context::getContext()->cart->getProducts();
        foreach ($products as $key => $product) 
        {  
            foreach($product['features'] as $feature){
                $featuresvalue = FeatureValue::getFeatureValuesWithLang($this->context->language->id, $feature['id_feature']);
                echo "<pre>";
                print_r($featuresvalue['id_feature_value']);
                echo "/<pre>";
            }
       }

这是完整的产品数组

Array
(
    [id_product_attribute] => 0
    [id_product] => 1174
    [cart_quantity] => 100
    [id_shop] => 1
    [id_customization] => 
    [name] => Appalachian Flooring Canadian Solid Hardwood Red Oak Auburn 20 SqFt/Box Prestige
    [is_virtual] => 0
    [description_short] => Appalachian Flooring Canadian Solid Hardwood Red Oak Auburn (2-1/4" x 3/4" x RL) 20 SqFt/Box Prestige
    [available_now] => 
    [available_later] => 
    [id_category_default] => 23
    [id_supplier] => 0
    [id_manufacturer] => 44
    [manufacturer_name] => Appalachian Flooring
    [on_sale] => 0
    [ecotax] => 0.000000
    [additional_shipping_cost] => 0.00
    [available_for_order] => 1
    [show_price] => 1
    [price] => 5.8
    [active] => 1
    [unity] => 
    [unit_price_ratio] => 0.000000
    [quantity_available] => 0
    [width] => 0.000000
    [height] => 0.000000
    [depth] => 0.000000
    [out_of_stock] => 0
    [weight] => 61.4
    [available_date] => 2019-05-01
    [date_add] => 2020-03-30 17:23:02
    [date_upd] => 2020-05-27 16:06:25
    [quantity] => 100
    [link_rewrite] => canadian-solid-hardwood-red-oak-auburn-2-1-4-1
    [category] => hardwood
    [unique_id] => 000000117400000000001110
    [id_address_delivery] => 111
    [advanced_stock_management] => 0
    [supplier_reference] => 
    [customization_quantity] => 
    [reference] => 136-1194
    [ean13] => 
    [isbn] => 
    [upc] => 
    [minimal_quantity] => 10
    [wholesale_price] => 0.000000
    [id_image] => 1174-3020
    [legend] => 
    [reduction_type] => 0
    [is_gift] => 
    [reduction] => 0
    [reduction_without_tax] => 0
    [price_without_reduction] => 6.554
    [specific_prices] => 
    [stock_quantity] => 0
    [price_without_reduction_without_tax] => 5.8
    [price_with_reduction] => 6.554
    [price_with_reduction_without_tax] => 5.8
    [total] => 580
    [total_wt] => 656
    [price_wt] => 6.554
    [reduction_applies] => 
    [quantity_discount_applies] => 
    [allow_oosp] => 1
    [features] => Array
        (
            [0] => Array
                (
                    [id_feature] => 1
                    [id_product] => 1174
                    [id_feature_value] => 475
                )

            [1] => Array
                (
                    [id_feature] => 2
                    [id_product] => 1174
                    [id_feature_value] => 53
                )

            [2] => Array
                (
                    [id_feature] => 38
                    [id_product] => 1174
                    [id_feature_value] => 357
                )

            [3] => Array
                (
                    [id_feature] => 38
                    [id_product] => 1174
                    [id_feature_value] => 358
                )

            [4] => Array
                (
                    [id_feature] => 40
                    [id_product] => 1174
                    [id_feature_value] => 360
                )

            [5] => Array
                (
                    [id_feature] => 40
                    [id_product] => 1174
                    [id_feature_value] => 377
                )

            [6] => Array
                (
                    [id_feature] => 40
                    [id_product] => 1174
                    [id_feature_value] => 378
                )

            [7] => Array
                (
                    [id_feature] => 41
                    [id_product] => 1174
                    [id_feature_value] => 379
                )

            [8] => Array
                (
                    [id_feature] => 42
                    [id_product] => 1174
                    [id_feature_value] => 362
                )

            [9] => Array
                (
                    [id_feature] => 42
                    [id_product] => 1174
                    [id_feature_value] => 363
                )

            [10] => Array
                (
                    [id_feature] => 43
                    [id_product] => 1174
                    [id_feature_value] => 365
                )

            [11] => Array
                (
                    [id_feature] => 44
                    [id_product] => 1174
                    [id_feature_value] => 380
                )

            [12] => Array
                (
                    [id_feature] => 44
                    [id_product] => 1174
                    [id_feature_value] => 384
                )

            [13] => Array
                (
                    [id_feature] => 45
                    [id_product] => 1174
                    [id_feature_value] => 427
                )

            [14] => Array
                (
                    [id_feature] => 46
                    [id_product] => 1174
                    [id_feature_value] => 428
                )

        )

    [rate] => 0
    [tax_name] => 
    [price_without_specific_price] => 5.8
)

但我没有得到这些值。有人知道如何获取值吗?提前致谢

【问题讨论】:

    标签: php prestashop prestashop-1.7


    【解决方案1】:

    尝试像这样在特征数组中添加特征的值

           $productsCart = Context::getContext()->cart->getProducts();
         
            foreach ($productsCart as $product) {
            foreach ($product['features'] as &$feature) {    
                    $featureValueObj = new FeatureValue($feature['id_feature_value'],Context::getContext()->language->id);
                    $feature['value']= $featureValueObj->value;
    
                echo "<pre>";
                print_r($product['features']);
                echo "</pre>";
               }
             }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 2014-05-03
      • 1970-01-01
      相关资源
      最近更新 更多