1

I am working on a custom product type for a Magento2 build that I am working on. I have followed the guide linked below and it has served as a brilliant base for me to work from.

How to add a new product type in Magento 2? (MageStackDay mystery question 1)

I am however having trouble in getting the price field show for my custom product type in the admin panel when adding/editing the custom product type and I can not see why, please see image below:

enter image description here

I think I may missed a price layout/model some where that adds the price field in but can not seem to track down where or what I have missed.

Any help/guidance would be greatly appreciated.

1
  • Can you give us some codes / examples that you have tried before to give us a lead to help you ? Thank you. – Matthéo Geoffray Feb 3 '16 at 16:55
2

Looks like you do not add you type to list of applicable in price attribute. Add it in install data script:

<?php
namespace SuperLLC\SuperType\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallData implements InstallDataInterface
{
    /**
     * EAV setup factory
     *
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * Init
     *
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(EavSetupFactory $eavSetupFactory)
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $fieldList = [
            'price',
            'special_from_date',
            'special_to_date',
            'cost',
            'tier_price',
            'weight',
        ];
        $newType = 'super_type';
        foreach ($fieldList as $field) {
            $applyTo = explode(
                ',',
                $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
            );
            if (!in_array($newType, $applyTo)) {
                $applyTo[] = $newType';
                $eavSetup->updateAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    $field,
                    'apply_to',
                    implode(',', $applyTo)
                );
            }
        }
    }
}
2
  • Thank you, I will try that out today and see where I get to with it. – Baber Feb 4 '16 at 9:13
  • Fantastic! More than enough for me to work with. I added the install script and updated field-list and type to what I needed and it worked :). I followed up its behaviour and I understand now why and what I was missing. For anyone that is having missing field issues, it is worth checking the "catalong_eav_aatribute" table, filter by "attribute_id" and check the field "apply_to" to make sure that your new product type is present in the comma separated field. – Baber Feb 4 '16 at 12: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.