Recent Topics

modify addresses in different files



  • Dear All

    i'm trying to modify the address but there lots of files and I'm confused should I change all of the them ?

    so we have

    Core/Database/Migrations/2020_01_28_102422_add_new_column_and_rename_name_column_in_customer_addresses_table.php
    
           $table->string('area');
                    $table->string('block');
                    $table->string('street');
                    $table->string('house_building');
                    $table->string('apartment_office');
                    $table->string('floor');
                    $table->string('avenue');
                    $table->string('phone');
                    $table->string('note');
    
     ***  there is below 3 function should I add the new fields ?***
    
        private function migrateCustomerAddresses(): void
        {
            $dbPrefix = DB::getTablePrefix();
    
            $insertCustomerAddresses = <<< SQL
                INSERT INTO ${dbPrefix}addresses(
                    address_type,
                    customer_id,
                    first_name,
                    last_name,
                    gender,
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    email,
                    phone,
                    default_address,
                    additional,
                    created_at,
                    updated_at
                )
                SELECT
                    "customer",
                    customer_id,
                    first_name,
                    last_name,
                    (SELECT gender FROM customers c WHERE c.id=ca.customer_id),
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    null,
                    phone,
                    default_address,
                    JSON_INSERT('{}', '$.old_customer_address_id', id),
                    created_at,
                    updated_at
                FROM customer_addresses ca;
    SQL;
    
            DB::unprepared($insertCustomerAddresses);
        }
    
        private function migrateCartAddresses(): void
        {
            $dbPrefix = DB::getTablePrefix();
    
            $insertCustomerAddresses = <<< SQL
                INSERT INTO ${dbPrefix}addresses(
                    address_type,
                    customer_id,
                    cart_id,
                    first_name,
                    last_name,
                    gender,
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    email,
                    phone,
                    additional,
                    created_at,
                    updated_at
                )
                SELECT
                    (CASE WHEN ca.address_type='billing' THEN "cart_billing" ELSE "cart_shipping" END),
                    customer_id,
                    cart_id,
                    first_name,
                    last_name,
                    (SELECT gender FROM customers c WHERE c.id=ca.customer_id),
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    email,
                    phone,
                    JSON_INSERT('{}', '$.old_cart_address_id', id),
                    created_at,
                    updated_at
                FROM cart_address ca;
    SQL;
    
            DB::unprepared($insertCustomerAddresses);
        }
    
        private function migrateOrderAddresses(): void
        {
            $dbPrefix = DB::getTablePrefix();
    
            $insertCustomerAddresses = <<< SQL
                INSERT INTO ${dbPrefix}addresses(
                    address_type,
                    customer_id,
                    order_id,
                    first_name,
                    last_name,
                    gender,
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    email,
                    phone,
                    additional,
                    created_at,
                    updated_at
                )
                SELECT
                    (CASE WHEN oa.address_type='billing' THEN "order_billing" ELSE "order_shipping" END),
                    customer_id,
                    order_id,
                    first_name,
                    last_name,
                    (SELECT gender FROM customers c WHERE c.id=oa.customer_id),
                    company_name,
                    address1,
                    address2,
                    postcode,
                    city,
                    state,
                    country,
                    email,
                    phone,
                    JSON_INSERT('{}', '$.old_order_address_id', id),
                    created_at,
                    updated_at
                FROM order_address oa;
    SQL;
    
            DB::unprepared($insertCustomerAddresses);
        }
    
    

    also there is Customer/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php

    and last Checkout/Database/Migrations/2018_09_19_092845_create_cart_address.php

    as you can see its really confusing which one should I update ?

    it would be great if some one can explain so we can change it the right way instead of messing around

    Best regards



  • is there any one can help me ?



  • Hi @cmpengineers,

    May I know what you are trying to do? Do you want to update the address column in the table or want to update the address for the customer?



  • @cmpengineers said in modify addresses in different files:

    customer_addresses

    there are multiple types of addresses, what you need to modify. You can easily differentiate the migration files accordingly folder.

    For example: Customer/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php contains customer addresses...



  • This post is deleted!


  • @devansh-webkul

    i want to change the whole address, cart, checkout ..etc anywhere that has an address I want to change?

    i don't understand why there is address and customer address ? there is no table called customer_address only addresses ?

    please just explain so i can understand

    these fields I need to add to address but it has to be in add table that contains address

      $table->string('area');
                    $table->string('block');
                    $table->string('street');
                    $table->string('house_building');
                    $table->string('apartment_office');
                    $table->string('floor');
                    $table->string('avenue');
    

    regards



  • @devansh-webkul

    what does view_render_event do ?

     {!! view_render_event('bagisto.shop.customers.account.address.create_form_controls.area.after') !!}
    

    regards



  • Hi @cmpengineers,

    You need to check this file packages/Webkul/Customer/src/Models/CustomerAddress.php. In this file, we have the CustomerAddress class. But this class is extending the Address Model.

    In that model, you will see that the linked table is addresses.

    I hope this will help you.

    And if you are planning to change migration, I request you to create a new migration file because the existing one won't reflect any changes.



  • @devansh-webkul

    this is an awesome answer, thank you very much for your help

    best regards


Log in to reply