Custom product saves in custom table but not listed in product list

Hello,

I created a custom product bij extending the comProduct and added 2 field as test based on the doodle product:

(public_html/core/components/miconfiguratorproducts/model/miconfiguratorproducts/miproductproduct.class.php)

<?php
global $modx;

use modmore\Commerce\Admin\Widgets\Form\SelectField;
use modmore\Commerce\Admin\Widgets\Form\TextField;
use modmore\Commerce\Admin\Widgets\Form\Tab;

if (!class_exists('comProduct')) {
    /** @var Commerce $commerce */
    $commerce = $modx->getService('commerce', 'Commerce', MODX_CORE_PATH . 'components/commerce/model/commerce/', []);
}


class MiProductProduct extends comProduct
{

    public function getModelFields()
    {
        $fields = parent::getModelFields();

        foreach ($fields as $idx => $field) {
            // We don't need weight or weight unit on digital products.
            if ($field->getName() === 'weight' || $field->getName() === 'weight_unit') {
                unset($fields[$idx]);
            }
        }

        $newFields = [];

// Add a new tab

        $newFields[] = new Tab($this->commerce, [
            'label' => 'Configurator fields'
        ]);

// Add a select field
        $newFields[] = new SelectField($this->commerce, [
            'label' => 'Room size',
            'name' => 'properties[room_size]',
            'value' => $this->getProperty('room_size'),
            'options' => [
                ['value' => 'S', 'label' => 'Small'],
                ['value' => 'M', 'label' => 'Middle'],
                ['value' => 'L', 'label' => 'Large'],
            ]
        ]);

// Add a text field
        $newFields[] = new TextField($this->commerce, [
            'label' => 'M2',
            'name' => 'properties[room_m2]',
            'value' => $this->getProperty('room_m2'),
        ]);

        return array_merge($fields, $newFields);
    }
}

and the public_html/core/components/miconfiguratorproducts/src/Modules/MiProduct.php:

<?php
namespace miconfiguratorproducts\Modules;

use modmore\Commerce\Dispatcher\EventDispatcher;
use modmore\Commerce\Modules\BaseModule;

class MiProduct extends BaseModule
{
    public function initialize(EventDispatcher $dispatcher): void
    {
        // Load our lexicon
        $this->adapter->loadLexicon('miconfiguratorproducts:default');
      
        // Add the xPDO package, so Commerce can detect the derivative classes
        $root = dirname(__DIR__, 2);
        $path = $root . '/model/';
        $this->adapter->loadPackage('miconfiguratorproducts', $path);
//
        // Add template path to the Commerce view
        $this->commerce->view()->addTemplatesPath($root . '/templates/');

    }

    public function getName()
    {
        return 'Configurator Products';
    }

    public function getDescription()
    {
        return 'Module voor custom configurator producten.';
    }

    public function getAuthor(): string
    {
        return 'Dimitri';
    }

}

Now I do get the Configurator Products in the add products puldown, and I can add one by filling the fields, and it will save, but it does not show up in the product list. It is saved in the custum database table: commerce_miproductproduct, defined in the model:

<?xml version="1.0" encoding="UTF-8"?>
<model package="miconfiguratorproducts" baseClass="xPDO\xPDO" platform="mysql" defaultEngine="InnoDB" version="1.1">
    <object class="MiProductProduct" table="commerce_miproductproduct" extends="comProduct" />
    <object class="MiProductBundleProduct" table="commerce_miproductbundleproduct" extends="comBundleProduct" />
</model>

but it does no return in the list, when I manually add a product with this classKey in the mdx_commerce_miproductproduct table, it wil show that row and data, but when I edit that one in the manager (say its ID 3) the it wil save to the custom table.

Do I miss something? to let commerce know that the product is saved in a custom table?

What I actually was hoping for is that it world save the product in the default product database with a link to the extended data table for the other fields.

Getting this to work in MODx 3 was already a pain. because of the xpdo2 legacy that commerce still uses, witch makes connecting custom (modx3) xpdo3 classes impossible. As far as I can see and know.

Hope that someone sees the mistake and can help me out a bit more, to get this working properly. In the near future, We need to connect an external product database, and I am wondering it that’s even possible if I cant get this to work.

The way inheritance in xPDO works, you’ll need to keep the extended product class tied to the same database table.

You can however use a relationship to have an extended data table that is tied to the product ID in the main products table.