magento2 – Magento 2: Sort the list of products by custom attribute

Here is my list of products
enter the description of the image here

Here is a product that has a custom attribute image_count == 1
enter the description of the image here

My problem is how to register the list.phtml file

if(image_count == 1) {products with image_count == 1 will be at the top of the list} else {other product}

Any help Thanks in advance.

magento2 – Magento update to 2.3.3 back-end after logging in Invalid parent ID specified Magento_Analytics

I have a problem updating Magento from 2.3.2 to 2.3.3. The update works fine and I already did everything mentioned here: https://devdocs.magento.com/guides/v2.3/comp-mgr/cli/cli-upgrade.html

After that, Magento Backend does not work properly. The login form can be loaded, but after the login, an error appears:

There was an error processing your request.

Exception printing is disabled by default for security reasons.

Error log number: 1078057989546

The Erorr record says:

{"0": "Invalid parent ID specified (Magento_Analytics :: business_intelligence)", "1": "# 1 Magento Backend Model Menu Builder Interceptor -> ___ callParent (& # 39; getResult & # 39; , array (& Magento Backend Model Menu # 000000005d9d073500000000399c9a80 #)) called in (vendor / magento / framework / Interception / Interceptor.php: 138) n # 2 Magento Backend Model Menu Builder Interceptor-> Magento Framework Interception {closing} (& Magento Backend Model Menu # 000000005d9d073500000000399c9a80 #) called in (vendor / magento / framework / Interception / Interceptor.php: 153) n # 3 Magento Backend Model Menu Builder Interceptor -> ___ callPlugins (& # 39; getResult & # 39 ;, array (& Magento Backend Model Menu # 000000005d9d073500000000399c9a80 #), array (array (& # 39; SetupMenuBuilder & # 39;))) called in (generated / code / Magento / Backend / Model / Menu / Builder / Interceptor.php: 26) ……..

I really don't know why, when I switch to 2.3.2 it works fine. Frontend works fine in both versions, only the backend in 2.3.3 has this problem. Update made with the composer.

Does anyone know how to fix it?

Thanks for any help.

magento2: Magento 2.3.2 strings are not translated

I can't understand why some of the strings I entered in my i18> bg_BG.csv are not being translated. I will give a small example with Qty.

Qty,Количество,module,Magento_Catalog
Qty,Количество,module,Magento_AdvancedCheckout
Qty,Количество,module,Magento_CatalogInventory
Qty,Количество,module,Magento_Checkout
Qty,Количество,module,Magento_Customer
Qty,Количество,module,Magento_GiftRegistry

These are the occurrences in my translation file for Qty, none of which works. I can't understand if I'm doing something wrong. I cleaned the cache, implemented static files, changed from production to developer. Some of the strings in the file are translated and others are not.

blocks – Magento 2: in checking, how to display the input fields in the same row?

How can i show Street , House number, Addition fields in a row?
I have this file

application / code / Mageplaza / Osc / Block / Checkout / LayoutProcessor.php

checkoutSession = $checkoutSession;
        $this->_oscHelper = $oscHelper;
        $this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
        $this->attributeMapper = $attributeMapper;
        $this->merger = $merger;
    }

    /**
     * Process js Layout of block
     *
     * @param array $jsLayout
     *
     * @return array
     * @throws LocalizedException
     */
    public function process($jsLayout)
    {
        if (!$this->_oscHelper->isOscPage()) {
            return $jsLayout;
        }

        /** Shipping address fields */
        if (isset($jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')
            ('children')('shippingAddress')('children')('shipping-address-fieldset')('children'))) {
            $fields = $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('shippingAddress')
            ('children')('shipping-address-fieldset')('children');
            $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('shippingAddress')
            ('children')('shipping-address-fieldset')('children')
                = $this->getAddressFieldset($fields, 'shippingAddress');

            if ($this->_oscHelper->isEnableAmazonPay()) {
                $shippingConfig = &$jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('shippingAddress');
                $shippingConfig('component') = 'Mageplaza_Osc/js/view/shipping';
                $shippingConfig('children')('customer-email')('component') = 'Mageplaza_Osc/js/view/form/element/email';
            }

            /** Fix the issue of the unsaved vat_id field */
            if (isset($jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')
                ('children')('shippingAddress')('children')('shipping-address-fieldset')('children')('taxvat'))) {
                $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')
                ('children')('shippingAddress')('children')('shipping-address-fieldset')('children')('taxvat')('dataScope') = 'shippingAddress.vat_id';
            }
        }

        $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')
        ('shippingAddress')('children')('shipping-address-fieldset')('children')('street') = (
            'component' => 'Magento_Ui/js/form/components/group',
            //'label' => __('Address'),
            'required' => false, //turn false because I removed main label
            'dataScope' => 'shippingAddress.street',
            'provider' => 'checkoutProvider',
            'sortOrder' => 3,
            'type' => 'group',
            'children' => (
                (
                    'component' => 'Magento_Ui/js/form/element/abstract',
                    'config' => (
                        'customScope' => 'shippingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/input'
                    ),
                    'dataScope' => '0',
                    'provider' => 'checkoutProvider',
                    'validation' => ('required-entry' => true, "min_text_length" => 1, "max_text_length" => 24),
                    'additionalClasses' => 'additional',
                    'label' => __('Street'),
                    'visible' => true,
                    'required' => true
                ),
                (
                    'component' => 'Magento_Ui/js/form/element/abstract',
                    'config' => (
                        'customScope' => 'shippingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/input'
                    ),
                    'dataScope' => '0',
                    'provider' => 'checkoutProvider',
                    'validation' => ('required-entry' => true, "validate-number" => true, "min_text_length" => 1, "max_text_length" => 8),
                    'label' => __('House number'),
                    'visible' => true,
                    'required' => true

                ),
                (
                    'component' => 'Magento_Ui/js/form/element/abstract',
                    'config' => (
                        'customScope' => 'shippingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/input'
                    ),
                    'dataScope' => '0',
                    'provider' => 'checkoutProvider',
                    'validation' => ('required-entry' => true, "max_text_length" => 9),
                    'label' => __('Addition'),
                    'visible' => true,
                    'required' => true
                    )
                )

        );

        /** Billing address fields */
        if (isset($jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')
            ('children')('billingAddress')('children')('billing-address-fieldset')('children'))) {
            $fields = $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('billingAddress')
            ('children')('billing-address-fieldset')('children');
            $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('billingAddress')
            ('children')('billing-address-fieldset')('children')
                = $this->getAddressFieldset($fields, 'billingAddress');

            /** Fix the issue of the unsaved vat_id field */
            if (isset($jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('billingAddress')
                ('children')('billing-address-fieldset')('children')('taxvat'))) {
                $jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('billingAddress')
                ('children')('billing-address-fieldset')('children')('taxvat')('dataScope') = 'billingAddress.vat_id';
            }
        }

        /** Remove billing customer email if quote is not virtual */
        if (!$this->checkoutSession->getQuote()->isVirtual()) {
            unset($jsLayout('components')('checkout')('children')('steps')('children')('shipping-step')('children')('billingAddress')
                ('children')('customer-email'));
        }

        /** Remove billing address in payment method content */
        $fields = &$jsLayout('components')('checkout')('children')('steps')('children')('billing-step')('children')
        ('payment')('children')('payments-list')('children');
        foreach ($fields as $code => $field) {
            if ($field('component') === 'Magento_Checkout/js/view/billing-address') {
                unset($fields($code));
            }
        }

        return $jsLayout;
    }

    /**
     * Get address fieldset for shipping/billing address
     *
     * @param $fields
     * @param $type
     *
     * @return array
     * @throws LocalizedException
     */
    public function getAddressFieldset($fields, $type)
    {
        $elements = $this->getAddressAttributes();

        $systemAttribute = $elements('default');
        if (sizeof($systemAttribute)) {
            $attributesToConvert = (
                'prefix' => ($this->getOptions(), 'getNamePrefixOptions'),
                'suffix' => ($this->getOptions(), 'getNameSuffixOptions'),
            );
            $systemAttribute = $this->convertElementsToSelect($systemAttribute, $attributesToConvert);
            $fields = $this->merger->merge(
                $systemAttribute,
                'checkoutProvider',
                $type,
                $fields
            );
        }

        $customAttribute = $elements('custom');
        if (sizeof($customAttribute)) {
            $fields = $this->merger->merge(
                $customAttribute,
                'checkoutProvider',
                $type . '.custom_attributes',
                $fields
            );
        }

        $this->addCustomerAttribute($fields, $type);
        $this->addAddressOption($fields);

        return $fields;
    }

    /**
     * Add customer attribute like gender, dob, taxvat
     *
     * @param $fields
     * @param $type
     *
     * @return $this
     * @throws LocalizedException
     */
    private function addCustomerAttribute(&$fields, $type)
    {
        $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
            'customer',
            'customer_account_create'
        );
        $addressElements = ();
        foreach ($attributes as $attribute) {
            if (!$this->_oscHelper->getAddressHelper()->isCustomerAttributeVisible($attribute)) {
                continue;
            }
            $addressElements($attribute->getAttributeCode()) = $this->attributeMapper->map($attribute);
        }

        if (sizeof($addressElements)) {
            $fields = $this->merger->merge(
                $addressElements,
                'checkoutProvider',
                $type . '.custom_attributes',
                $fields
            );
        }

        foreach ($fields as $code => &$field) {
            if (isset($field('label'))) {
                $field('label') = __($field('label'));
            }
        }

        return $this;
    }

    /**
     * @param $fields
     *
     * @return $this
     */
    private function addAddressOption(&$fields)
    {
        $fieldPosition = $this->_oscHelper->getAddressHelper()->getAddressFieldPosition();

        $oscField = ();
        $allFieldSection = $this->_oscHelper->getAddressHelper()->getSortedField(false);
        foreach ($allFieldSection as $allfield) {
            /** @var Attribute $field */
            foreach ($allfield as $field) {
                $oscField() = $field->getAttributeCode();
            }
        }

        $this->rewriteFieldStreet($fields);

        foreach ($fields as $code => &$field) {
            $fieldConfig = isset($fieldPosition($code)) ? $fieldPosition($code) : ();
            if (!sizeof($fieldConfig)) {
                if (in_array($code, ('country_id'))) {
                    $field('config')('additionalClasses') = "mp-hidden";
                    continue;
                } elseif (in_array($code, $oscField)) {
                    unset($fields($code));
                }
            } else {
                $oriClasses = isset($field('config')('additionalClasses')) ? $field('config')('additionalClasses') : '';
                $field('config')('additionalClasses') = "{$oriClasses} col-mp mp-{$fieldConfig('colspan')}" . ($fieldConfig('isNewRow') ? ' mp-clear' : '');
                $field('sortOrder') = (isset($field('sortOrder')) && !in_array(
                    $code,
                    $oscField
                )) ? $field('sortOrder') : $fieldConfig('sortOrder');
                if ($code === 'dob') {
                    $field('options') = ('yearRange'   => '-120y:c+nn',
                                         'maxDate'     => '-1d',
                                         'changeMonth' => true,
                                         'changeYear'  => true
                    );
                    $field('component') = 'Magento_Ui/js/form/element/date';
                }

                $this->rewriteTemplate($field);
            }
        }

        /**
         * Compatible Amazon Pay
         */
        if ($this->_oscHelper->isEnableAmazonPay()) {
            $amazonHelper = ObjectManager::getInstance()->get("AmazonCoreHelperData");
            if ($amazonHelper->isPwaEnabled()) {
                $fields('inline-form-manipulator') = (
                    'component' => 'Mageplaza_Osc/js/view/amazon'
                );
            }
        }

        return $this;
    }

    /**
     * Change template to remove valueUpdate = 'keyup'
     *
     * @param $field
     * @param string $template
     *
     * @return $this
     */
    public function rewriteTemplate(&$field, $template = 'Mageplaza_Osc/container/form/element/input')
    {
        if (isset($field('type')) && $field('type') === 'group') {
            foreach ($field('children') as $key => &$child) {
                if ($key == 0 &&
                    in_array('street', explode('.', $field('dataScope'))) &&
                    $this->_oscHelper->isGoogleHttps()
                ) {
                    $this->rewriteTemplate($child, 'Mageplaza_Osc/container/form/element/street');
                    continue;
                }
                $this->rewriteTemplate($child);
            }
        } elseif (isset($field('config')('elementTmpl')) && $field('config')('elementTmpl') === "ui/form/element/input") {
            $field('config')('elementTmpl') = $template;
            if ($this->_oscHelper->isUsedMaterialDesign()) {
                $field('config')('template') = 'Mageplaza_Osc/container/form/field';
            }
        }

        return $this;
    }

    /**
     * Change template street when enable material design
     *
     * @param $fields
     *
     * @return $this
     */
    public function rewriteFieldStreet(&$fields)
    {
        if ($this->_oscHelper->isUsedMaterialDesign()) {
            $fields('country_id')('config')('template') = 'Mageplaza_Osc/container/form/field';
            $fields('region_id')('config')('template') = 'Mageplaza_Osc/container/form/field';
            foreach ($fields('street')('children') as $key => $value) {
                $fields('street')('children')(0)('label') = $fields('street')('label');
                $fields('street')('children')($key)('config')('template') = 'Mageplaza_Osc/container/form/field';
            }
            $fields('street')('config')('fieldTemplate') = 'Mageplaza_Osc/container/form/field';
            unset($fields('street')('label'));
        }

        return $this;
    }

    /**
     * @return Options
     */
    private function getOptions()
    {
        if (!is_object($this->options)) {
            $this->options = ObjectManager::getInstance()->get(Options::class);
        }

        return $this->options;
    }

    /**
     * @return array
     * @throws LocalizedException
     */
    private function getAddressAttributes()
    {
        $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
            'customer_address',
            'customer_register_address'
        );

        $elements = (
            'custom'  => (),
            'default' => ()
        );
        /** @var Attribute $attribute */
        foreach ($attributes as $attribute) {
            if ($this->_oscHelper->isEnableCustomerAttributes() && $attribute->getIsUserDefined()) {
                continue;
            }

            $code = $attribute->getAttributeCode();
            $element = $this->attributeMapper->map($attribute);
            if (isset($element('label'))) {
                $label = $element('label');
                $element('label') = __($label);
            }
            (
            $attribute->getIsUserDefined()
            ) ?
                $elements('custom')($code) = $element :
                $elements('default')($code) = $element;
        }

        return $elements;
    }

    /**
     * Convert elements(like prefix and suffix) from inputs to selects when necessary
     *
     * @param array $elements address attributes
     * @param array $attributesToConvert fields and their callbacks
     *
     * @return array
     */
    private function convertElementsToSelect($elements, $attributesToConvert)
    {
        $codes = array_keys($attributesToConvert);
        foreach (array_keys($elements) as $code) {
            if (!in_array($code, $codes)) {
                continue;
            }
            $options = call_user_func($attributesToConvert($code));
            if (!is_array($options)) {
                continue;
            }
            $elements($code)('dataType') = 'select';
            $elements($code)('formElement') = 'select';

            foreach ($options as $key => $value) {
                $elements($code)('options')() = (
                    'value' => $key,
                    'label' => $value,
                );
            }
        }

        return $elements;
    }
}

And it is shown as the picture below.enter the description of the image here

BUT I NEED AS BELOW IMAGES:
enter the description of the image here

product – Magento 2: How to add extension attributes for ProductCustomOptionValuesInterface

I need to add custom product added Customizable Options to the Rest API product. I have configured those custom options for the main interface below MagentoCatalogApiDataProductCustomOptionValuesInterface and model MagentoCatalogModelProductOptionValue file and options to access the product API.

But you can't override the interface, so how to add as extension attributes or another override solution for dependency below the kernel.

Core dependency file path: magento231vendormagentomodule-catalogetcdi.xml


Any help would be appreciated. Thank you!

Magento 1.9.1.0 remove .html suffix – Is manual redirection htaccess 301 necessary?

I have a functioning store with around 600 products and I wanted to remove the html suffix from my URLs.

I deleted the html in the configuration and re-indexed. All html pages are redirected to non-html variants.

I have read that people online are placing 301 redirect manually in their htaccess

e.g. RewriteRule ^index.php/?(.*).html$ /$1 (R=301,L)

But is this really necessary when I don't get 404?

Any ideas appreciated

Thank you

magento2 – Magento 2.3.2 – Update the product attribute option api duplicate option value

I am trying to add and update product attribute options through the API endpoint: /V1/products/attributes/:attributeCode/options. When I try to update the values ​​of an existing attribute option, the option is no updated, instead it is added. Follow an example of api call:

Add new option:

{
    "option": {
        "sort_order": 14,
        "label": "Good",
        "store_labels": [
            {
                "store_id": 2,
                "label": "Good"
            },
            {
                "store_id": 0,
                "label": "Good"
            },
            {
                "store_id": 5,
                "label": "Buono"
            }
        ]
    }
}

Reply: id_7589

Update option:

{
    "option": {
        "sort_order": 14,
        "label": "Very Good",
        "store_labels": [
            {
                "store_id": 2,
                "label": "Very Good"
            },
            {
                "store_id": 0,
                "label": "Very Good"
            },
            {
                "store_id": 5,
                "label": "Ottimo"
            }
        ],
        "value": "7589"
    }
}

How can I update the value of an existing product attribute option and avoid duplication?

magento2: the Magento administration area redirects to the old URL

Magento 2.3.1 installed on lightsail using the official Bitnami Aws installer, if you go to the administrator, redirect to the previous website. In the core_config_data database the URLs are correct.

I updated the domain name, updated letsencrypt, deleted and rinsed the magento cache and restarted everything. Only the administration area is redirecting

magento2 – Magento 2 – AWS Lightsail – Bitnami – Password Protection Development Site

I followed the link below and added the authentication for the Bitnami Magento 2.3.2 development site found in AWS Lightsail.

https://docs.bitnami.com/bch/apps/magento/administration/use-htpasswd/

I created htpasswd and magento_users using,

cd /opt/bitnami
apache2/bin/htpasswd -cb apache2/magento_users USERNAME PASSWORD```

I have also added the following code in /opt/bitnami/apps/magento/conf/httpd-app.conf


...
AuthType Basic
AuthName MyAuthName
AuthUserFile "/opt/bitnami/apache2/magento_users"
Require valid-user
...
= 2.3>
# Require all granted

...

After restarting the apache and emptying the cache, it requested username and password when loading the development interface. When I provide credentials, I end up getting an error like,

Error 503 Backend fetch failed
Backend fetch failed

Guru Meditation:
XID: 393256

Varnish cache server

I can't see anything related to this in Apache error_log.

Can anyone help me solve this problem?