X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Change widget class of some field in Checkout (https://forum.x-cart.com/showthread.php?t=76134)

Soptareanu Alex 03-28-2018 01:17 AM

Change widget class of some field in Checkout
 
I want to change the Field City widget class from
\XLite\View\FormField\Input\Text into \XLite\View\FormField\Select\MyCustomClass(). Is there a way to do this job ?

tony_sologubov 03-30-2018 01:47 AM

Re: Change widget class of some field in Checkout
 
Hi @Alex,

Try to update 'schemaClass' column in the xc_address_field MySQL table for 'city' field.
These values are defined by the sql/xlite_data.yaml file, which is loaded during installation, so the new value should not be overwritten by store re-deployment.

Tony


Quote:

Originally Posted by Soptareanu Alex
I want to change the Field City widget class from
\XLite\View\FormField\Input\Text into \XLite\View\FormField\Select\MyCustomClass(). Is there a way to do this job ?


Soptareanu Alex 03-30-2018 02:38 AM

Re: Change widget class of some field in Checkout
 
Quote:

Originally Posted by tony_sologubov
Hi @Alex,

Try to update 'schemaClass' column in the xc_address_field MySQL table for 'city' field.
These values are defined by the sql/xlite_data.yaml file, which is loaded during installation, so the new value should not be overwritten by store re-deployment.

Tony


Yes, this is was the solution that i found and use but still remains a problem because when i finish my module i want to install in an production env and there i don't have the access to go and hard-code the yaml file. I need a solution if can be posible to do this task when i deploy the module.

tony_sologubov 04-02-2018 03:18 AM

Re: Change widget class of some field in Checkout
 
Quote:

Originally Posted by Soptareanu Alex
Yes, this is was the solution that i found and use but still remains a problem because when i finish my module i want to install in an production env and there i don't have the access to go and hard-code the yaml file. I need a solution if can be posible to do this task when i deploy the module.


There are several ways how to overcome the problem.

1) Decorate \XLite\Model\AddressField class and define its getSchemaClass() method as follows:
Code:

    public function getSchemaClass()
    {
        if ($this->getServiceName() == 'city') {
            return '\XLite\Module\DevID\ModuleID\View\FormField\Select\MyCustomClass';
        } else {
            return parent::getSchemaClass();
        }
    }


2) In your module's Main.php file create runBuildCacheHandler() method that will change 'schemaClass' property of the Address Field.

Here is an example script that shows how you can change 'schemaClass' property for 'city' address field:

Code:

<?php

include "top.inc.php";

$cityField = \XLite\Core\Database::getRepo('XLite\Model\AddressField')->createQueryBuilder('af')
    ->andWhere('af.serviceName = :city')
    ->setParameter('city', 'city')
    ->getSingleResult();

$cityField->setSchemaClass('\XLite\View\FormField\Input\Text');
\XLite\Core\Database::getEM()->flush();


So, in your module you should define 'schemaClass' as your own value, if the module is enabled:
Code:

\XLite\Core\Database::getRepo('XLite\Model\Module')->isModuleEnabled('DevID\ModuleID')

or if your module is inactive, then you define 'schemaClass' as usual '\XLite\View\FormField\Input\Text'.

Please, let me know if it makes sense to you.

Tony


All times are GMT -8. The time now is 10:50 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.