1

I’m new to Magento and trying to develop an extension that will do the following.

I have a product with standard dimensions (like 600 x 2000 mm, 700 x 2000 mm) but the product can be also made in any custom size (like 654 x 2102 mm etc).

There must be an option to switch from drop-down window with a list of standard sizes to a text field, so a client can insert its desired dimensions.

And the most complicated part is calculating the price. The price is calculated according to the following logic: find nearest bigger standard size (by area) and add 10%.

What would be the best approach to doing this? Thanks in advance!

0

Using price modifier is likely the simplest way without changing your whole catalog:

In a custom module, you need in the etc folder a di.xml with the content below:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Ui\DataProvider\Modifier\Pool">
        <arguments>
            <argument name="modifiers" xsi:type="array">
                <item name="custom-pricing" xsi:type="array">
                    <item name="class" xsi:type="string">Mbs\PriceWidget\Model\PriceModifier</item>
                    <item name="sortOrder" xsi:type="number">90</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

then the class will be called for all your products (so be careful your calculations do not create overhead), but then if you only apply your customisation when standard dimensions has a value, you may have something working quickly.

<?php

namespace Mbs\PriceWidget\Model;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\PriceModifierInterface;

class PriceModifier implements PriceModifierInterface
{
    private static $chargeForRange600_2000 = 23;

    public function modifyPrice($price, Product $product)
    {
        if ($product->getStandardDimensions() === '600 x 2000') {
            return $price + self::$chargeForRange600_2000;
        }

        return $product->getPrice();
    }
}
| improve this answer | |
  • thanks again! will try this – antoniog Oct 8 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.