简体   繁体   English

通过特价以百分比形式获取Magento产品集合

[英]Get a Magento product collection by special price in percentage

in my Magento shop should be a page called sale with sub pages including 10% sale, 20% sale, 30% sale … 在我的Magento商店中,应该是一个名为sale的页面,其中子页面包括10%的销售,20%的销售,30%的销售……

So now I need to get a product collection with all products that contain at least a special price (final price including price rule discounts would be nicer but if too difficult the special price would be enough for filtering the discounted products). 因此,现在我需要获得一个包含至少包含特殊价格的所有产品的产品集合(包含价格规则折扣的最终价格会更好,但是如果过于困难,特殊价格将足以过滤折扣产品)。

Well basically I know how I can get a product collection and I know how to set a filter if there is any special price or special price is higher than a specific amount. 好吧,基本上,我知道如何获得产品集合,并且知道如果有任何特殊价格或特殊价格高于特定数量时如何设置过滤器。

But in this case I would need to do something like "$_discountPercentage = round((($_actualPrice-$_convertedFinalPrice)/$_actualPrice)*100);" 但是在这种情况下,我将需要执行以下操作:“ $ _ discountPercentage = round((((($ _ actualPrice-$ _ convertedFinalPrice)/ $ _ actualPrice)* 100);” first and than filter the selection < than 10 or < 20 or < 30 and so on. 首先,然后过滤选择<小于10或<20或<30等等。

So of course I could load the whole collection and just display the matching products within the for each in php but I think this is not necessary because it would load a lot of overhead that is not needed. 因此,我当然可以加载整个集合,并仅在php中为每个显示匹配的产品,但是我认为这是不必要的,因为这会加载很多不必要的开销。 If this would be just sql I could do this job within 5 minutes. 如果这只是sql,我可以在5分钟内完成此工作。 But I do not know how to filter a product collection per discount in percent. 但是我不知道如何按百分比过滤每个折扣的产品集合。

So any tips how I could get a product collection in Magento with products containing a discount higher than 20% of the original price for example? 那么,有什么技巧可以使我在Magento中获得产品折扣比原来价格高20%的产品呢?

Thank you very much 非常感谢你

-> where('ROUND((((price_index.price-price_index.final_price)/price_index.price)* 100,0)<='。$ nmaxmumDiscountPercentage)-> where('ROUND((((price_index.price-price_index.final_price )/price_index.price)* 100,0)> ='。$ nMinimumDiscountPercentage)

Well as often I was faster than the community and solved my problem on my own :) but if anybody is looking for a similar solution … here is the part of code what will do the job. 通常,我比社区要快,并且自己解决了我的问题:),但是如果有人在寻找类似的解决方案……这是代码的一部分,它将完成这项工作。

$_productCollection->getSelect()
->where('ROUND(((price_index.price - price_index.final_price)/price_index.price)*100,0) >= '.$nMinimumDiscountPercentage)

Sure you can cancel the formula. 当然可以取消公式。 However, this will give you a product collection with all products containing a discount (special price or price rule) at least as high as the specified minimum percentage. 但是,这将为您提供一个产品集合,其中包含折扣(特殊价格或价格规则)的所有产品至少与指定的最小百分比一样高。

But you may help me with an additional question. 但是您可能会向我提出另一个问题。 I added this over XML by "Custom Layout Update" and a custom .phtml. 我通过“自定义布局更新”和自定义.phtml在XML上添加了此代码。 Now I got (0) products on all sub categories in the sidebar what is no surprise at all. 现在,我在侧边栏中的所有子类别中都有(0)个产品,这一点也不奇怪。

Is there a easy way to alter this phtml that my custom selection in any sub category is setting the correct catalog count for the parent category? 有没有一种简单的方法可以更改此phtml,即我在任何子类别中的自定义选择都为父类别设置了正确的目录计数? I would like to keep the counter in the sidebar for each sub if possible because I like this feature. 如果可能的话,我希望将计数器保留在侧边栏中,因为我喜欢此功能。

Thank you so far ;) 到目前为止谢谢你;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM