data-migration-tool icon indicating copy to clipboard operation
data-migration-tool copied to clipboard

Mismatch MRSP constant

Open mirkocesaro opened this issue 8 years ago • 3 comments

I have no problem during the migration but using the migrated data I found a problem with the attribute msrp_display_actual_price_type of the product. In the Magento 1 core the option for "Use config" has value 4 (Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type_Price::TYPE_USE_CONFIG) while the same option in Magento 2 has value 0 (\Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG).

mirkocesaro avatar May 20 '16 12:05 mirkocesaro

Hi @mirkocesaro

Thank you for posting this issue. We have created internal MAGETWO-53202 to resolve this one. But as quick fix you could check your Magento 2 catalog_product_entity_varchar table after migration and change value from 4 to 0 for all products with attribute id 114 (Msrp attribute)

victor-v-rad avatar May 20 '16 14:05 victor-v-rad

Thank you @victor-v-rad For now I found the same solution but I have applied it adding a new transform tag in my map.xml file.

I attached here the code

map.xml file:

        ...
        <transform>
            <field>catalog_product_entity_varchar.value</field>
            <handler class="Bitbull\MagentoPatch\Handler\Catalog\Product\Attribute\Type\Price\ConvertMsrpPriceType"/>
        </transform>
        ...

and this is my Handler in ConvertMsrpPriceType.php file

namespace Bitbull\MagentoPatch\Handler\Catalog\Product\Attribute\Type\Price;


use Migration\ResourceModel\Record;
use Migration\ResourceModel\Source;
use Migration\ResourceModel\Adapter\Mysql;



class ConvertMsrpPriceType extends \Migration\Handler\AbstractHandler
{
    const MAGENTO1_CONST_FOR_MSRP_DISPLAY_ACTUAL_PRICE_TYPE = 4;

    /**
     * @var int
     */
    protected $productAttributeId;

    /**
     * @var Source
     */
    protected $source;

    /**
     * @param Source $source
     */
    public function __construct( Source $source)
    {
        $this->source = $source;
    }

    /**
     * @param Record $recordToHandle
     * @param Record $oppositeRecord
     * @return mixed
     */
    public function handle(Record $recordToHandle, Record $oppositeRecord)
    {
        $value = $recordToHandle->getValue($this->field);
        $attributeId= $this->getProductAttributeSets();
        if( $value == self::MAGENTO1_CONST_FOR_MSRP_DISPLAY_ACTUAL_PRICE_TYPE
           && $recordToHandle->getValue('attribute_id') == $attributeId){
            $recordToHandle->setValue($this->field, \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG);
        }
        else{
            $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
        }

    }

    protected function getProductAttributeSets()
    {
        if (empty($this->productAttributeId)) {
            /** @var Mysql $adapter */
            $adapter = $this->source->getAdapter();
            $query = $adapter->getSelect()
                ->from(
                    ['eav_attr' => $this->source->addDocumentPrefix('eav_attribute')],
                    ['attribute_id']
                )->where('eav_attr.attribute_code = ?', 'msrp_display_actual_price_type');
            $this->productAttributeId = (int) $query->getAdapter()->fetchOne($query) ;
        }
        return $this->productAttributeId;
    }

}

mirkocesaro avatar May 20 '16 14:05 mirkocesaro

Well done @mirkocesaro !

victor-v-rad avatar May 20 '16 15:05 victor-v-rad