当前位置: 首页 > 知识库问答 >
问题:

Magento消除儿童产品以获得适用价格

漆雕欣德
2023-03-14

我有一个脚本,可以动态检索我编写的可配置产品的价格,现在我要返回并确保它考虑到可能存在的任何可配置属性。下面是通过ajax调用的,我已经将其调试到循环的最核心部分(因此所有magento方法都可以工作)。它应该删除与属性不匹配的子级。最终目标是只剩下一个孩子,并与价格相呼应。每个孩子确实包含一个独特的价格(这一点我知道)。你能明白为什么这现在不起作用吗?

<?php
require_once('/var/www/Staging/public_html/app/Mage.php');
umask(0);
Mage::app(); 

$product_id = $_POST['productID'];
$optionSelectionArray = $_POST['optionSelectionArray']; //the ids of configurable options selected


//var_dump($optionSelectionArray);

$product =  Mage::getModel('catalog/product')->load($product_id); // no need to use the _ here, it's not protected/private; additonally Mage::registry won't work because you're technically not on a product detail page
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product); 

//Gather all attribute ids for given product    
$availAttrs=[];
foreach($attributes as $attribute){ 
        $availAttrs[] = $attribute->getAttributeId();
}

foreach($availAttrs as $attr){//cycle available attributes
        foreach ($optionSelectionArray as $key => $value) {//cycle option for key
            if ($attr == $key){//if available attribute and key of optionSelectionArray match
                for($i=0; $i<sizeof($childProducts); $i++){//for each child in children
                    //get label of attribute code
                    foreach($attributes as $attribute){ 
                        if ($attr == $attribute->getAttributeId()){
                            $attrName = strtolower($attribute->getLabel());//get code name from attribute id
                        }//end if attribute matches attribute id
                    }//end attributes cycle

                    //CAITLIN LEFT OFF echoing the next line here to see if it is doing what it should

                    if($childProducts[$i]->getData($attrName) != $value){
                        array_splice($childProducts, $i, 1);
                    }//end if attribute values match
                    else{
                        echo("This is a match! : ");
                        echo('The vendor is ' . $childProducts[$i]->getData('vendor'). ";");
                        echo (" The price is " . $childProducts[$i]->getPrice());   
                    }
                }//end childproducts loop
            }//end if
        }//end foreach optionSelectionArray
    }//end foreach availattrs

//Echo final price $childProducts[0]
?>

共有1个答案

章阳波
2023-03-14

我把以下内容围绕在循环中,这确保我消除了所有不匹配的产品。

while(sizeof($childProducts)>1){
//Loops
}
 类似资料:
  • 大家好,我正在尝试从firebase检索数据,并根据我单击的RecyclerView显示它们,并将名称传递给下一个活动。 每当我尝试这样做时,它总是会关闭应用程序并再次打开。 但是,每当集合中没有“Dates_Log_In”时,它就会运行,但不会显示任何类型的数据。 这是我用来显示RecyclerView中所有数据的类 考勤班 AttendanceListAdapter 这就是我传递数据的地方,它

  • 我正试图从特价函数中删除“从”&“到”日期要求,但找不到正确的文件。我不确定它是在核心php文件中还是在模板PHTMLS中。 我使用的Magento商店集成了一个销售点系统,该系统导入包括“特价”字段在内的产品,这是每5分钟更新一次,但没有日期可以从POS系统中传递,所以我需要删除价格计算的起始和截止日期部分。 编辑:到目前为止,我已经找到了这些名为“get specialtodate()”的文件

  • 我试图使用继承创建一个银行系统,当子级BankAccount试图检索它的父值时,问题出现了,它得到了Bank类的初始值,numberAccounts = 0和空的registeredAccounts。 首先创建3个初始银行账户。 然后Bank类创建并生成它们给出的每个人的银行帐户和号码,numberAccounts和registeredAccounts的当前值应该已经更改。 当我尝试调用超类值来操

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

  • 有人知道我为什么会有这种行为吗?是我的代码出了bug还是什么问题?

  • 我正试图按价格对产品集合进行排序,但当我添加(粗体)时,这些产品消失了 我想把它们分类,虽然没有存货,但有人知道我能做到吗?