magento2 – Magento 2: How to get DefaultBillingAddress using knockout?

UI component Magento_Checkout/js/view/billing-address does not expose the defaultBillingAddress property to the html template, we need to create a new one for that.

See the screenshot and try the complete billing address code.js below:
here

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

define((
    'ko',
    'underscore',
    'Magento_Ui/js/form/form',
    'Magento_Customer/js/model/customer',
    'Magento_Customer/js/model/address-list',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/action/create-billing-address',
    'Magento_Checkout/js/action/select-billing-address',
    'Magento_Checkout/js/checkout-data',
    'Magento_Checkout/js/model/checkout-data-resolver',
    'Magento_Customer/js/customer-data',
    'Magento_Checkout/js/action/set-billing-address',
    'Magento_Ui/js/model/messageList',
    'mage/translate',
    'Magento_Checkout/js/model/shipping-rates-validator'
),
function (
    ko,
    _,
    Component,
    customer,
    addressList,
    quote,
    createBillingAddress,
    selectBillingAddress,
    checkoutData,
    checkoutDataResolver,
    customerData,
    setBillingAddressAction,
    globalMessageList,
    $t,
    shippingRatesValidator
) {
    'use strict';

    var lastSelectedBillingAddress = null,
        newAddressOption = {
            /**
             * Get new address label
             * @returns {String}
             */
            getAddressInline: function () {
                return $t('New Address');
            },
            customerAddressId: null
        },
        countryData = customerData.get('directory-data'),
        addressOptions = addressList().filter(function (address) {
            return address.getType() == 'customer-address'; //eslint-disable-line eqeqeq
        });

        var defaultBillingAddresses = addressList().filter(function (address) {
            return  address.getType() == 'customer-address' && address.isDefaultBilling();
        });

    addressOptions.push(newAddressOption);

    return Component.extend({
        defaults: {
            template: 'Magento_Checkout/billing-address'
        },
        currentBillingAddress: quote.billingAddress,
        addressOptions: addressOptions,
        customerHasAddresses: addressOptions.length > 1,
        defaultBillingAddress: ko.observable(defaultBillingAddresses(0)),

        /**
         * Init component
         */
        initialize: function () {
            this._super();
            quote.paymentMethod.subscribe(function () {
                checkoutDataResolver.resolveBillingAddress();
            }, this);
            shippingRatesValidator.initFields(this.get('name') + '.form-fields');
        },

        /**
         * @return {exports.initObservable}
         */
        initObservable: function () {
            this._super()
                .observe({
                    selectedAddress: null,
                    isAddressDetailsVisible: quote.billingAddress() != null,
                    isAddressFormVisible: !customer.isLoggedIn() || addressOptions.length === 1,
                    isAddressSameAsShipping: false,
                    saveInAddressBook: 1
                });

            quote.billingAddress.subscribe(function (newAddress) {
                if (quote.isVirtual()) {
                    this.isAddressSameAsShipping(false);
                } else {
                    this.isAddressSameAsShipping(
                        newAddress != null &&
                        newAddress.getCacheKey() == quote.shippingAddress().getCacheKey() //eslint-disable-line eqeqeq
                    );
                }

                if (newAddress != null && newAddress.saveInAddressBook !== undefined) {
                    this.saveInAddressBook(newAddress.saveInAddressBook);
                } else {
                    this.saveInAddressBook(1);
                }
                this.isAddressDetailsVisible(true);
            }, this);

            return this;
        },

        canUseShippingAddress: ko.computed(function () {
            return !quote.isVirtual() && quote.shippingAddress() && quote.shippingAddress().canUseForBilling();
        }),

        /**
         * @param {Object} address
         * @return {*}
         */
        addressOptionsText: function (address) {
            return address.getAddressInline();
        },

        /**
         * @return {Boolean}
         */
        useShippingAddress: function () {
            if (this.isAddressSameAsShipping()) {
                selectBillingAddress(quote.shippingAddress());

                this.updateAddresses();
                this.isAddressDetailsVisible(true);
            } else {
                lastSelectedBillingAddress = quote.billingAddress();
                quote.billingAddress(null);
                this.isAddressDetailsVisible(false);
            }
            checkoutData.setSelectedBillingAddress(null);

            return true;
        },

        /**
         * Update address action
         */
        updateAddress: function () {
            var addressData, newBillingAddress;

            if (this.selectedAddress() && this.selectedAddress() != newAddressOption) { //eslint-disable-line eqeqeq
                selectBillingAddress(this.selectedAddress());
                checkoutData.setSelectedBillingAddress(this.selectedAddress().getKey());
            } else {
                this.source.set('params.invalid', false);
                this.source.trigger(this.dataScopePrefix + '.data.validate');

                if (this.source.get(this.dataScopePrefix + '.custom_attributes')) {
                    this.source.trigger(this.dataScopePrefix + '.custom_attributes.data.validate');
                }

                if (!this.source.get('params.invalid')) {
                    addressData = this.source.get(this.dataScopePrefix);

                    if (customer.isLoggedIn() && !this.customerHasAddresses) { //eslint-disable-line max-depth
                        this.saveInAddressBook(1);
                    }
                    addressData('save_in_address_book') = this.saveInAddressBook() ? 1 : 0;
                    newBillingAddress = createBillingAddress(addressData);

                    // New address must be selected as a billing address
                    selectBillingAddress(newBillingAddress);
                    checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
                    checkoutData.setNewCustomerBillingAddress(addressData);
                }
            }
            this.updateAddresses();
        },

        /**
         * Edit address action
         */
        editAddress: function () {
            lastSelectedBillingAddress = quote.billingAddress();
            quote.billingAddress(null);
            this.isAddressDetailsVisible(false);
        },

        /**
         * Cancel address edit action
         */
        cancelAddressEdit: function () {
            this.restoreBillingAddress();

            if (quote.billingAddress()) {
                // restore 'Same As Shipping' checkbox state
                this.isAddressSameAsShipping(
                    quote.billingAddress() != null &&
                        quote.billingAddress().getCacheKey() == quote.shippingAddress().getCacheKey() && //eslint-disable-line
                        !quote.isVirtual()
                );
                this.isAddressDetailsVisible(true);
            }
        },

        /**
         * Restore billing address
         */
        restoreBillingAddress: function () {
            if (lastSelectedBillingAddress != null) {
                selectBillingAddress(lastSelectedBillingAddress);
            }
        },

        /**
         * @param {Object} address
         */
        onAddressChange: function (address) {
            this.isAddressFormVisible(address == newAddressOption); //eslint-disable-line eqeqeq
        },

        /**
         * @param {Number} countryId
         * @return {*}
         */
        getCountryName: function (countryId) {
            return countryData()(countryId) != undefined ? countryData()(countryId).name : ''; //eslint-disable-line
        },

        /**
         * Trigger action to update shipping and billing addresses
         */
        updateAddresses: function () {
            if (window.checkoutConfig.reloadOnBillingAddress ||
                !window.checkoutConfig.displayBillingOnPaymentMethod
            ) {
                setBillingAddressAction(globalMessageList);
            }
        },

        /**
         * Get code
         * @param {Object} parent
         * @returns {String}
         */
        getCode: function (parent) {
            return _.isFunction(parent.getCode) ? parent.getCode() : 'shared';
        }
    });
});*

After that, at the billing address / details.html you can use defaultBillingAddress (). Firstname, defaultBillingAddress (). Lastname, etc.

product cannot be edited in magento 2. redirects to connection error 504

In Magneto 2, after editing the product, wait for the message and redirect to the connection timeout error 504 while reviewing the database after editing the product, redirect to the MySQL query report.

Magento auction, the Offer button does not work

I installed the Magento Auction extension developed by magesale in magento 1. but the Bid button on the front end does not work. When I inspect Element I received an error in the console:
in firefox

XML Parsing Error: no root element found
Location: https://mangetoroot/js/auction/auction.php?id=1&tmpl=auctioninfo¤t_bid_id=
Line Number 1, Column 1: auction.php:1:1 

in Chrom

Uncaught TypeError: Cannot read property '0' of null
    at klass.initialize (auction210.js:102)
    at new klass (prototype.js:101)
    at chateau-haut-brion-1989.html:491

GET https://magentoroot/skin/frontend/em0139/default/images/ourwinecoterie-logo@2x.png 404 ()

I tried to search but I really can't find a solution. Thank you.

magento2 – Magento 2.3.2 Custom JavaScript module will not load

I am building a module, and the HTML loads well, but the JS does not.
This is what I have:

  • Seller Name: NewShop
  • Module Name: HelloWorld

File: app / code / NewShop / HelloWorld / view / frontend / requirejs-config.js

var config = {
  map: {
    '*': {
      "helloworld": "NewShop_HelloWorld/js/newshop_helloworld",
    }
  }
};

File: app / code / NewShop / HelloWorld / view / frontend / web / js / newshop_helloworld.js

require(("helloworld"), function($) {
  console.log('Hello World!')
});

I cleaned the cache and everything. I cannot see the message from the console, although the module shows well.

magento2: the Edit action column is not shown in the administration grid in magento 2

enter the description of the image here

Why the editing option is not shown in the action column. Kindly help me.
My Action.php code:

_urlBuilder = $urlBuilder;
        $this->_editUrl = $editUrl;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }


    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource('data')('items'))) {
            foreach ($dataSource('data')('items') as &$item) {
                $name = $this->getData('name');
                if (isset($item('entity_id'))) {
                    $item($name)('edit') = (
                        'href' => $this->_urlBuilder->getUrl(
                            $this->_editUrl, 
                            ('id' => $item('entity_id'))
                        ),
                        'label' => __('Edit'),
                    );
                }
            }
        }

        return $dataSource;
    }
}

XML code:


   
       
           
               false
               107
               id
           
       
   

magento2 – Edit Ui form with two tables in Magento 2

Below is the code for DataProvider in the Edit form.
Here it shows the data of the main tables while I choose to edit them.
Can anyone tell how to display data from another table?

 collection = $contactCollectionFactory->create();

    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }

    $items = $this->collection->getItems();
    $this->loadedData = array();

    /** @var Customer $customer */
    foreach ($items as $contact) {
        // notre fieldset s'apelle "contact" d'ou ce tableau pour que magento puisse retrouver ses datas :
        $this->loadedData($contact->getId())('contact') = $contact->getData();
    }


    return $this->loadedData;

}
}

magento 1.9 – Custom option once through x quantity

I have problems with a small problem:

I would like to add an additional charge of x amount if the customer wants customization. There is also a minimum order quantity of 2 packages. Now, accordingly, I have added the following custom option:

Custom option

But, unfortunately, this will add 20 to the price for each quantity. I would like to add the additional cost regardless of the amount they require.

How would you achieve this?

How can I change the default value of the Magento form?

I want to modify the value of the Associated website options (in Client> Manage clients> Add a new client), but I know it's a native Magento option, how can I rewrite it?

Thank you!

Get custom table error data in magento 1

I want to get data from a custom table, this is my code

$address = Mage::getModel ( 'shippingaddresses/shippingaddresses' )->getCollection()->addFieldToSelect('*')->addFieldToFilter(
                   array(
                             array("account_id",("eq"=>$customerNumber)),
                             array("account_name",("like"=>"%".$customerName."%")),
                             array("shipping_city",("like"=>"%".$customerCity."%")),
                             array("shipping_postal_code",("like"=>"%".$customerCode."%"))
                   )
        );

My mistake

Column not found: 1054 Unknown column 'account_id.Array' in 'where clause', query was: SELECT `main_table`.* FROM `commercers_shippingaddresses` AS `main_table` WHERE ((`account_id`.`Array` = '') OR (`account_name`.`Array` = '') OR (`shipping_city`.`Array` = '') OR (`shipping_postal_code`.`Array` = ''))";i:1;s:2143:

magento2 – Magento 2 FTP File Manager

And when frontend calls him, he doesn't answer. It means an error "css" or "js" 400.

Magento works fine, but it doesn't execute commands like di: compile because you can't find them in directories.

And going to the directories are only in the form of shortcuts, what will it be?

Here is an impression: http://prntscr.com/ot77ql

Thanks in advance. I'm sorry for bad English.