Trouble Displaying Selected Value for Custom Columns in jqadmin Template

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
PaoloLegaspi
Posts: 32
Joined: 07 Nov 2024, 15:02

Trouble Displaying Selected Value for Custom Columns in jqadmin Template

Post by PaoloLegaspi » 25 Nov 2024, 16:22

Hi,
I’m customizing the product_item jqadmin template to include some additional values. The code successfully updates the new columns, but the selected value doesn’t show up in the dropdown. I checked itemData, and it doesn’t seem to include the new columns.

Any ideas on what I might be missing? Do I have to extend the jqadmin/product/standard? I think this involves the toArray and fromArray

Dropdown

Code: Select all

<div class="form-group row optional advanced">
                    <label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'Is Testdrive' ) ) ?</label>
                                <div class="col-sm-8">
                                    <select class="form-select item-isTestdrive" tabindex="1"
                                        name="<?= $enc->attr( $this->formparam( array( 'item', 'is_testdrive' ) ) ) ?>"
                                        v-bind:readonly="!can('change')" >
                                        <option value="">
					<?= $enc->html( $this->translate( 'admin', 'Please select' ) ) ?>
						</option>
                                        <option value="0" <?= $selected( $this->get( 'itemData/product.is_testdrive'), 0 ) ?> >
                                            <?= $enc->html( $this->translate( 'mshop/code', 'No' ) ) ?>
                                        </option>
                                        <option value="1" <?= $selected( $this->get( 'itemData/product.is_testdrive'), 1 ) ?> >
						<?= $enc->html( $this->translate( 'mshop/code', 'Yes' ) ) ?>
					</option>
                                    </select>
                                </div>
                                <div class="col-sm-12 form-text text-muted help-text">
                                    <?= $enc->html( $this->translate( 'admin', 'Is this product a testdrive?' ) ) ?>
                                </div>
                            </div>
Product Manager Decorator

Code: Select all

class ProductDecorator extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $attr = [
        'is_testdrive' => [
            'code' => 'product.is_testdrive',
            'internalcode' => 'mpro."is_testdrive"',
            'label' => 'Is Test Drive',
            'type' => 'bool',
        ],
        'location' => [
            'code' => 'product.location',
            'internalcode' => 'mpro."location"',
            'label' => 'Location',
            'type' => 'string',
        ],
    ];

    /**
     * @return array
     */
    public function getSaveAttributes() : array
    {
        return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
    }

    /**
     * @param bool $withsub
     * @return array|\Aimeos\Base\Criteria\Attribute\Iface[]
     */
    public function getSearchAttributes( bool $sub = true ) : array
    {
        return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
    }
}
AppServiceProvider

Code: Select all

public function boot()
    {
        \Aimeos\MShop\Product\Item\Standard::macro( 'getIsTestdrive', function() {
            return $this->get( 'product.is_testdrive' );
        } );

        \Aimeos\MShop\Product\Item\Standard::macro( 'getLocation', function() {
            return $this->get( 'product.location' );
        } );

        \Aimeos\MShop\Product\Item\Standard::macro( 'setIsTestDrive', function( $value ) {
            return $this->set( 'product.is_testdrive', (int) $value );
        } );

        \Aimeos\MShop\Product\Item\Standard::macro( 'setLocation', function( $value ) {
            return $this->set( 'product.location', (string) $value );
        } );
    }

User avatar
aimeos
Administrator
Posts: 8415
Joined: 01 Jan 1970, 00:00

Re: Trouble Displaying Selected Value for Custom Columns in jqadmin Template

Post by aimeos » 27 Nov 2024, 14:06

Can you check if this works:

Code: Select all

    private $attr = [
        'product.is_testdrive' => [
            'internalcode' => 'is_testdrive',
            'label' => 'Is Test Drive',
            'type' => 'bool',
        ],
        'product.location' => [
            'internalcode' => 'location',
            'label' => 'Location',
        ],
    ];
See: https://aimeos.org/docs/latest/models/e ... -decorator
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply