Question

Before moving to Magento, I had a princing logic inside a table that involved (customer, customer group, item, item group, etc)

There are some native features that I will take advantage of such as tier prices and some more.

But in the end I will have to add some custom funcionalities about princing. I was thinking about adding a custom layer at the end of calculating prices. What I mean is, Magento calculates prices by layers, aproximately:

Regular price > Tier price > Special Price

I would want to add my layer at the end.

For testing I only wanted to add this layer and set the price to 5€ for example. Just for know that is working. When I have this, for me it will be the solution

The documentation is not helping so much: http://devdocs.magento.com/guides/v2.1/architecture/behavior/pricing.html

What I've done:

  • Created my custom module.
  • Added my logic pricing class, based on:

vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php

vendor/magento/module-catalog/Pricing/Price/SpecialPriceInterface.php

namespace Gsp\SpecialPrices\Pricing\Price;

/**
 * Custom price interface
 */
interface CustomPriceInterface
{
    /**
     * Returns custom price
     *
     * @return float
     */
    public function getCustomPrice();

    /**
     * @return bool
     */
    public function isPercentageDiscount();
}


namespace Gsp\SpecialPrices\Pricing\Price;

class CustomPrice extends AbstractPrice implements CustomPriceInterface, BasePriceProviderInterface
{
    /**
     * Price type special
     */
    const PRICE_CODE = 'custom_price';

    /**
     * @return bool|float
     */
    public function getValue()
    {
        return 5;
    }

    /**
     * Returns special price
     *
     * @return float
     */
    public function getCustomPrice()
    {
        return 9;
    }

    /**
     * @return bool
     */
    public function isPercentageDiscount()
    {
        return false;
    }
}

Don't worry about the 5 or 9, I don't know what the heck am I doing. lul. I only want to set the prices the amount I want.

  • di.xml, adding my custom price:


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Catalog\Pricing\Price\Pool" type="Magento\Framework\Pricing\Price\Pool">
        <arguments>
            <argument name="prices" xsi:type="array">
                <item name="regular_price" xsi:type="string">Magento\Catalog\Pricing\Price\RegularPrice</item>
                <item name="final_price" xsi:type="string">Magento\Catalog\Pricing\Price\FinalPrice</item>
                <item name="tier_price" xsi:type="string">Magento\Catalog\Pricing\Price\TierPrice</item>
                <item name="special_price" xsi:type="string">Magento\Catalog\Pricing\Price\SpecialPrice</item>
                <item name="base_price" xsi:type="string">Magento\Catalog\Pricing\Price\BasePrice</item>
                <item name="custom_option_price" xsi:type="string">Magento\Catalog\Pricing\Price\CustomOptionPrice
                </item>
                <item name="configured_price" xsi:type="string">Magento\Catalog\Pricing\Price\ConfiguredPrice</item>
                <item name="custom_price" xsi:type="string">Gsp\SpecialPrices\Pricing\Price\CustomPrice</item>
            </argument>
        </arguments>
    </virtualType>
</config>

Now the website is broken when I go to a product list or product view. It breaks exactly when it has to render the price. So I guess is working what I did but I'm missing something.

The log is showing that error:

main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_56f1b068ec7ccf4878f9284dd1137afd1 and handles catalog_product_prices: Please correct the XML data and try again.  [] []

But I see this error is also displayed when I disable my module. I have porto theme, and there isn't any layout named catalog_product_prices.xml

Was it helpful?

Solution

I'm still with this, but I think the solution is overriding the modules catalogRule and salesRule.

With this functionalities you would do all price changes you want, with rules.

OTHER TIPS

This Code Didn't Work And Where to use this code in Magento Custom Extention or Custom Created Code in special price

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top