Question

Following this tutorial (Link) I created a custom product type that exends \Magento\Catalog\Model\Product\Type\Simple for myself.

I can choose custom options, quantity etc. in the backend but nothing is showing up in my frontend page, just the name and price are displaying, not even an "add to cart" button.

Where did I go wrong?

MyVendor/MyModule/etc/product_types.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
    <type name="print_default" label="Print [Standard]" modelInstance="MyVendor\MyModule\Model\Product\Type\printDefault"></type>
</config>

MyVendor/MyModule/Model/Product/Type/printDefault.php

<?php

namespace MyVendor\MyModule\Model\Product\Type;

class printDefault extends \Magento\Catalog\Model\Product\Type\Simple
{
    /**
     * Product type code
     */
    const TYPE_CODE = 'print_default';


    public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
    {
    }
}

MyVendor/MyModule/Setup/InstallData.php

<?php

namespace MyVendor\MyModule\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;

class InstallData implements InstallDataInterface
{
    /**
     * EAV setup factory
     *
     * @var EavSetupFactory
     */
    protected $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]);

        //associate these attributes with new product type
        $fieldList = [
            'price',
            'special_price',
            'special_from_date',
            'special_to_date',
            'minimal_price',
            'cost',
            'tier_price',
            'weight',
        ];

        // make these attributes applicable to new product type
        foreach ($fieldList as $field) {
            $applyTo = explode(
                ',',
                $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
            );
            if (!in_array(\MyVendor\MyModule\Model\Product\Type\printDefault::TYPE_CODE, $applyTo)) {
                $applyTo[] = \MyVendor\MyModule\Model\Product\Type\printDefault::TYPE_CODE;
                $eavSetup->updateAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    $field,
                    'apply_to',
                    implode(',', $applyTo)
                );
            }
        }
    }
}
Was it helpful?

Solution

Oh my, I just needed to reindex.

php bin/magento indexer:reindex 

I'll leave the question as it is, maybe it can help someone else.

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