마 젠토 2 : 적용된 맞춤 제품 할인 후 계층 탐색 가격 필터가 작동하지 않음


13

제품 할인 모듈을 작업 중입니다. 나는 플러그인과 관찰자를 통해 그것을했다. 제품 페이지와 목록 페이지에서 제대로 작동합니다. 그러나 업데이트 된 제품 가격에 따라 가격 필터가 작동하지 않습니다.

가격을 사용자 정의하는 데 사용하는 코드는 다음과 같습니다.

VendorName / ModuleName / etc / di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Pricing\Price\FinalPrice">
        <plugin name="custom_discount_catalog_pricing_price_finalprice" type="VendorName\ModuleName\Plugin\FinalPrice" />
    </type>
</config>

VendorName / ModuleName / etc / events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <event name='catalog_product_get_final_price'>
        <observer name='customdiscount_finalprice' instance='VendorName\ModuleName\Observer\ProcessFinalPrice'/>
    </event>
</config>

VendorName / 모듈 이름 /Observer/ProcessFinalPrice.php

<?php

namespace VendorName\ModuleName\Observer;

use Magento\Framework\Event\ObserverInterface;

class ProcessFinalPrice implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        $old = $product->getData('final_price');
        $discountedPrice = $old - ($old * 0.20);
        $product->setData('final_price',$discountedPrice);
    }
}

VendorName / ModuleName / Plugin / FinalPrice.php

<?php

namespace VendorName\ModuleName\Plugin;

class FinalPrice
{
    public function afterGetValue(\Magento\Catalog\Pricing\Price\FinalPrice $subject, $result)
    {
        $discountedPrice = $result - ($result * 0.20);
        return $discountedPrice;
    }
}

20 % 할인 적용

가격 필터가 할인 가격과 작동하지 않음

참고 : 할인 된 가격은 고객 수준입니다


HI 할인을 원한다면. "카탈로그 가격 규칙"
— Ravi Soni

@ravi Soni 우리는 커스텀 모듈을 만들었습니다. 이를 위해 카탈로그 가격 규칙을 사용할 수 없습니다.
— Dhairya Shah

@Rohan 동일한 버전을 사용하는데 작동하지 않습니다.
— Priyank

나는 당신이 하나를 찾을 희망, 모든 솔루션없이 거의 사년부터 솔루션을 찾고, 주요 문제는 계층 탐색의 가격은 직접 테이블에서 오는, 당신은 즉석에서 가격을 변경하는 것입니다
— WISAM 하킴

@WISAMHAKIM 아니요 적절한 해결책이 없습니다. 일부 마 젠토 핵심 팀원이 이것을 조사하고 해결책을 제안 할 수 있기를 바랍니다 :)
— Priyank

답변:


5

이것은 해결책이 아니지만 가격 필터의 작동 방식에 대한 설명 일 수 있습니다. 솔루션을 식별하는 데 도움이 될 수 있습니다.

제품 목록에 표시된 가격은 catalog_product_index_price표 에서 가져옵니다 .
제품 목록을 검색하는 선택 항목을 보면 다음과 같이 표시됩니다.

SELECT 
  `e`.*, 
  `cat_index`.`position` AS `cat_index_position`, 
  `price_index`.`price`, 
  `price_index`.`tax_class_id`, 
  `price_index`.`final_price`, 
  IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, 
  `price_index`.`min_price`, 
  `price_index`.`max_price`, 
  `price_index`.`tier_price` 
FROM `catalog_product_entity` AS `e` 
INNER JOIN `catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND ....
INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND ...

귀하의 경우, 제품을 판매 할 때 즉시 제품의 최종 가격을 변경하기 때문에 작동하지 않습니다. 그러나 가격 지수 표에는 여전히 원래 가격이 있습니다.

실제 색인 생성은 (최소한 간단한 제품의 경우)에서 이루어 Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice::reindex집니다.
나는 거기에서 어떤 일이 일어나는지 완전히 설명 할 수는 없지만, 당신은 뭔가를 걸 수 있습니다.

prepareFinalPriceDataForType동일한 클래스 의 메소드 는 색인 작성 프로세스 시작시 호출됩니다.
이 메소드는 $this->modifyPriceIndex($finalPriceTable);
가격 수정 자 클래스를 작성하여 가격 수정 자 목록에 첨부하여 구매할 수있는 항목입니다.
다음과 같이 가격 수정자를 만들 수 있습니다.

<?php
namespace Vendor\Module\Indexer\Price;

use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;

class CustomPriceModifier implements PriceModifierInterface
{
     public function modifyPrice(IndexTableStructure $priceTable, array $entityIds = []) : void
     {
         //code here that modifies your price.
     }
}

에서 가격 조정제의 예를 찾을 수 있습니다 Magento\CatalogInventory\Model\Indexer\ProductPriceIndexFilter. 재고가없는 제품을 숨기도록 설정하면 가격 지수에서 재고가없는 제품이 제거됩니다.

가격 수정자를 만들었습니다. 이제 기존 가격 수정 자 목록에 첨부해야합니다.

di.xml 파일에서 다음을 수행 할 수 있습니다.

<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceInterface">
    <arguments>
        <argument name="priceModifiers" xsi:type="array">
            <item name="customPriceModifier" xsi:type="object">Vendor\Module\Indexer\Price\CustomPriceModifier</item>
        </argument>
    </arguments>
</type>

이제 modifyPrice위 클래스 의 메소드 를 구현하여 인덱스 테이블의 가격을 적절하게 수정할 수 있습니다 .

그게 다야


좋은 설명입니다. 그러나 고객 수준의 할인 가격으로 인해 효과가 없습니다.
— Dhairya Shah

1
네. magento는 고객 수준의 가격과 잘 어울리지 않습니다. 반면에 고객 그룹을 사용할 수 있습니다. 이는 인덱싱 속도를 늦출 그룹이 많음을 의미 할 수 있습니다. 불행히도 다른 깨끗한 솔루션이 없습니다. 또는 그 문제에 대한 더러운 것.
— Marius

내가 찾고있는 솔루션을 얻지 못했습니다. 그러나 당신이 흐름에 대한 설명으로 당신이 처음으로 대답했기 때문에 당신에게 현상금 포인트를주고 싶습니다.
— Priyank

2

Magento 2 흐름 구조를 이해 했으므로 카탈로그 가격 규칙을 생성하고 해당 규칙을 저장 및 적용 할 때. 이후 업데이트 가격을 위해 데이터를 다시 색인화해야합니다. 이때 가격은 해당 제품에서 업데이트되고 catalog_product_index_price테이블에 저장됩니다 .

그러나이 모듈 흐름 구조를 이해하면 계층 탐색 필터 용으로 렌더링 된 제품 모음을 수정하지 않습니다. 여기서 vendor/magento/module-catalog/Model/Layer.php getProductCollection () 함수를 확인할 수 있습니다 . 따라서 플러그인 로직에 따라 프런트 엔드에 표시되는 값만 업데이트하면됩니다. 그러나 해당 제품 콜렉션 ( getProductCollection () 함수 데이터 ) 에서 final_price 및 min_price 필드 값을 업데이트하지 않았습니다 .

당신은 또한 당신의 사용자 지정 할인 가격 표시를 확인할 수 있습니다. 그러나 제품이 할인 된 가격으로 장바구니에 추가되지 않았습니다. 따라서 전체 솔루션이 아니라고 생각합니다.

따라서 카탈로그 가격 규칙이 업데이트하는 것처럼 콜렉션 오브젝트의 final_price 및 min_price 를 업데이트해야합니다.

희망이 당신에게 도움이 될 것입니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.