what is the difference between a user and a customer table?

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!
Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

what is the difference between a user and a customer table?

Post by Ahmad » 08 Nov 2020, 12:58

hi, i use aimeos/laravel 2020.07
I want to know what is the difference between a user and a customer table? I mean when a guest customer make an order and want to create an account during order registration, customer data In what table is user information stored?

I make email field in billing address hidden, because I don't need it and I change make mobile number (telephone field) mandatory because I use this unique field as username in my laravel login, so how can I change or create my own Customer Item/Manager to store my own user address fields (state_id and city_id) in User and Customer tables.
currently I store this fields in order_base_address table with create own Order/Item/Base/Address and Order/Manager/Base/Address class but I don't know how can to this for Customer and User tables.
please give me a way to do.

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: what is the difference between a user and a customer table?

Post by Ahmad » 09 Nov 2020, 15:54

@aimeos
please help me for my problem

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

Re: what is the difference between a user and a customer table?

Post by aimeos » 10 Nov 2020, 09:26

In Laravel, only the users table is uses. The mshop_customer table is the default Aimeos table and is created too because the setup tasks are independent from each other and the task creating the mshop_customer table doesn't know that Laravel also creates the users table. Therefore, the mshop_customer table is there but will be empty.

By default, the e-mail address is used as unique username in Laravel registration. If you have already changed that, you can extend the Laravel customer manager like you did for the order managers and make the telephone number the unique value by changing these lines:
https://github.com/aimeos/ai-laravel/bl ... hp#L40-L46
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: what is the difference between a user and a customer table?

Post by Ahmad » 10 Nov 2020, 18:10

aimeos wrote: 10 Nov 2020, 09:26 In Laravel, only the users table is uses. The mshop_customer table is the default Aimeos table and is created too because the setup tasks are independent from each other and the task creating the mshop_customer table doesn't know that Laravel also creates the users table. Therefore, the mshop_customer table is there but will be empty.
- thanks for your answer, now if a customer (user) add more than 1 address to store and use those in future orders, where will they be stored?

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: what is the difference between a user and a customer table?

Post by Ahmad » 10 Nov 2020, 18:47

I do it and work for me but I have a problem with my extended laravel customer manager:

I create a class named MyCustomerManager in my extension like as the attached image, and a class named MyCustomerItem in path lib/custom/src/MShop/Customer/Item in my extension like as the attached image, the fromArray and toArray functions in MyCustomerItem never called As they called in my Order/item/Base/Address/MyAddressItem class (I attached screenshot of code in this files, also I attached screenshot Order/Manager/Base/Address/MyAddressManager, Please take a look at them)

by creating these two files, the state_id and city_id fields are now stored correctly in table mshop_order_base_address of database. However, I think I have a mistake in my codes because it does not work properly without the following two lines in the function createItemBase in MyOrderManagerBaseAddress

Code: Select all

    protected function createItemBase(array $values = []): \Aimeos\MShop\Order\Item\Base\Address\Iface
    {
        if(isset($values['state_id'])) $values['order.base.address.state_id'] = $values['state_id']; unset($values['state_id']);
        if(isset($values['city_id'])) $values['order.base.address.city_id'] = $values['city_id']; unset($values['city_id']);
        return new \Aimeos\MShop\Order\Item\Base\Address\MyAddress( $values /* , ... */ );
    }
    
, and also in MyOrderItemBaseAddress, I should not use the full order.base.address. prefix fields in get and set and toArray and fromArray functions.

I do same this for MyCustomer Manager and Item but I can not access to my custom state_id and city_id fields to store in users table of database because I check and noticed that the fromArray and toArray functions never called in MyCustomerItem.

I follow https://aimeos.org/docs/Developers/Libr ... gers_items to extend order base address manager but don't for me but when I make change it with wrong codes above it work for me and state_id and city_id stored correctly in table.


@aimeos
please take a look to my extended classes and say to me What is the correct code to achieve my goal? (my goal is save state_id and city_id in mshop_order_base_address and users table and user addresses table and also access them in Item class or Item array to show in front end).
Attachments
MyOrderManagerBaseAddress
MyOrderManagerBaseAddress
2020-11-10_21-59-10.jpg (217.07 KiB) Viewed 3589 times
MyOrderItemBaseAddress
MyOrderItemBaseAddress
2020-11-10_21-58-05.jpg (205.29 KiB) Viewed 3589 times
MyCustomerItem
MyCustomerItem
2020-11-10_21-50-19.jpg (180.39 KiB) Viewed 3589 times
MyCustomerManager
MyCustomerManager
2020-11-10_21-45-41.jpg (179.05 KiB) Viewed 3589 times

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

Re: what is the difference between a user and a customer table?

Post by aimeos » 11 Nov 2020, 17:05

Ahmad wrote: 10 Nov 2020, 18:10 - thanks for your answer, now if a customer (user) add more than 1 address to store and use those in future orders, where will they be stored?
In the users_address table are all delivery addresses stored.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: what is the difference between a user and a customer table?

Post by aimeos » 11 Nov 2020, 17:16

You don't need to extend the items when following https://aimeos.org/docs/2020.x/infrastr ... /#easy-way
The columns state_id and city_id will be automatically stored and fetched by the manager and available in the item using

Code: Select all

$item->get( 'state_id' );
$item->get( 'city_id' );
Please make sure, you extend the customer manager item in the same way.
To store the values from the order address item also in the customer address item, you need to overwrite the copyFrom() method in your order address item:
https://github.com/aimeos/aimeos-core/b ... #L143-L151
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: what is the difference between a user and a customer table?

Post by Ahmad » 13 Nov 2020, 15:42

Please make sure, you extend the customer manager item in the same way.
To store the values from the order address item also in the customer address item, you need to overwrite the copyFrom() method in your order address item:
https://github.com/aimeos/aimeos-core/b ... #L143-L151
[/quote]

when I overwrite the copyFrom() method in my order address item as follows ▼

Code: Select all

    public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) : \Aimeos\MShop\Common\Item\Address\Iface
    {
        parent::copyFrom( $item );

        $this->setStateId( (string) $item->getStateId() );
        $this->setCityId( (string) $item->getCityId() );
        $this->setModified();

        return $this;
    }
I get the following error ▼

#message: "Called unknown method "getStateId" on class "Aimeos\MShop\Common\Item\Address\Simple""

what can I do?

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

Re: what is the difference between a user and a customer table?

Post by aimeos » 16 Nov 2020, 09:34

There are no such methods and like said, you can get/set the properties using:

Code: Select all

$this->set( 'state_id', $item->get( 'state_id' ) );
$this->set( 'city_id' , $item->get( 'city_id' ) );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: what is the difference between a user and a customer table?

Post by Ahmad » 29 Nov 2020, 15:14

aimeos wrote: 16 Nov 2020, 09:34 There are no such methods and like said, you can get/set the properties using:

Code: Select all

$this->set( 'state_id', $item->get( 'state_id' ) );
$this->set( 'city_id' , $item->get( 'city_id' ) );
I remove my custom Customer Item and Customer Manager in my extension and add MyCustomerManagerDecorator and now I can access to my own state_id and city_id properties but I have problem yet:

--- when I change this properties in checkout/address, they don't save in database but other properties change successfully, the element name tag in this page is ca_billing_2[order.base.address.state_id] and ca_billing_2[order.base.address.city_id]
I try change config of mshop/customer/laravel/update and add "state_id" = ?, "city_id" = ? to end of update statement but I get error with log "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: "

--- I change my customer code from email to telephone as username with $searchConfig in my Customer Manager

Code: Select all

        'customer.code' => array(
            'label' => 'Customer username',
            'code' => 'customer.code',
            'internalcode' => 'lvu."telephone"',
            'type' => 'string',
            'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
        ),
but I don't know what can I do for this in Decorator?

--- when I var_dump address in checkout/summary I get MyOrderAddressItem with state_id and city_id without order.base.address. in bdata, is this ok?

--- as you say need to extend copyFrom method in my order address item, can I remove my custom Order Address Item and Order Address Manager and replace those with Order Address Decorator like as what I do with customer?

--- And I have another problem in checkout/address and that is when for example I change firstname and submit form and redirect back with validation error like as required validation for another field the firstname fill with default value while it should fill with changed value to don't have to type again, what can I do for this?

Post Reply