magento2 – Assign custom attribute values to grid collection

I have a created a custom grid in admin ,

I want to assign custom attributes from customer to one of the column in the grid , I can get the value of attribute from customer repository but how can I pass it to collection?

Any help appreciated.

Thank You.

magento2 – Magento 2 Unable to get custom item options from order item

I have added custom options to quote item using below code

        $quote = $this->quoteFactory->create()->load($quoteId);
        $_product = $this->product->load($productId);
        $additionalOptions = array();
            if ($additionalOption = $_product->getOptionByCode('additional_options')) {
                $additionalOptions = $this->serializer->unserialize($additionalOption->getValue());
            }

            $additionalOptions() = (
                'label' => 'Type',
                'value' => 'Sample'
            );
        $quote->addProduct($_product, 1)
                    ->addOption(array(
                        'product_id' => $_product->getId(),
                        'code' => 'additional_options',
                        'value' => $this->serializer->serialize($additionalOptions)
                    ))
                    ->setCustomPrice(2)
                    ->setWeight(5)
                    ->setOriginalCustomPrice(2)
                    ->getProduct()->setIsSuperMode(true);
                $quote->collectTotals()->save();

it is adding the item and to quote.After saving the order I tried to get the additional option value but i’m unable to get it on order details page

sales_order_view.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="default_order_items_renderer">
            <action method="setTemplate">
                <argument name="template" translate="true" xsi:type="string">Vendor_Module::order/view/items/renderer/default.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

default.phtml

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

// @codingStandardsIgnoreFile

?>
<?php /** @var MagentoSalesBlockAdminhtmlOrderViewItemsRendererDefaultRenderer $block */ ?>
<?php $_item = $block->getItem() ?>
<?php $block->setPriceDataObject($_item) ?>
<tr>
    <?php $i = 0;
    $columns = $block->getColumns();
    $lastItemNumber = count($columns) ?>
    <?php foreach ($columns as $columnName => $columnClass):?>
        <?php $i++; ?>
        <td class="<?= /* @noEscape */ $columnClass ?><?= /* @noEscape */ ($i === $lastItemNumber ? ' last' : '') ?>"><?= /* @escapeNotVerified */ $block->getColumnHtml($_item, $columnName) ?>
            <?php if($columnClass == "col-product"){  ?>
                <span><?php echo __("Type:") ?></span>
                <?php
                 //here I'm getting empty array 
                 print_r( $_item->getOptionByCode('additional_options'));

                ?>
            <?php  } ?>
        </td>
    <?php endforeach; ?>
</tr>

$_item->getOptionByCode('additional_options') this lines returns empty array .Please someone guide me hoe to get the additional option value .I have seen the quote_item_option table it contains the data .

Custom PHP / WordPress Developer with 15+ yrs experience

Hi All,

I have been a long time member here in DP since 2007 serving clients across globe.

[​IMG]
SEMrush

As a Professional Freelancer with over 15+ yrs of experience I do offer following services:

CUSTOM PHP/MySQL Services:
# Complete Website Design & Development
# Bug Fixing & Maintenance
# Fine tuning & Performance Optimisation for speed
# Takeover someone’s Website code & do provide maintenance / upgradation service

WORDPRESS SERVICES:
# Complete WordPress site Design & Development
# Theme Development & Customisation
# Plugin Development & Customisation
# Website Maintenance & Bug Fixing
# Website Audit Report
# WordPress Website Customisations

Checkout my portfolio linked in my signature to know more about my skill-sets / experience / projects & client references.

[​IMG]

If you are interested with my services , I would be happy to help you on long-term.

Looking forward to hear from you fellow DP members.

Thanks & wish you all the best.

 

Why is my Custom User Meta deleted on Profile Update?

I have problems with my custom user fields on updating the user profile withing the /wp-admin/user-edit.php. The values of the huna and ki field are deleted. The validation and altUserID still show up correctly. Where is my error in the code? Thanks for your help!

Before Updating the User

enter image description here

After Updating the User

enter image description here

My Code

add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Magic Link", "blank"); ?></h3>

    <table class="form-table">
    <tr>
        <th><label for="Secret">Secret</label></th>
        <td>
            <input type="text" name="secret" id="secret" value="<?php echo esc_attr( get_the_author_meta( 'huna', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Key">Key</label></th>
        <td>
            <input type="text" name="key" id="key" value="<?php echo esc_attr( get_the_author_meta( 'ki', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Validation">Validation</label></th>
        <td>
            <input type="text" name="validation" id="validation" value="<?php echo esc_attr( get_the_author_meta( 'validation', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Validation">Welcome Screen</label></th>
        <td>
            <input type="checkbox" name="welcome" id="welcome" value="<?php echo esc_attr( get_the_author_meta( 'welcome', $user->ID ) ); ?>" class="regular-text" /><br />

        </td>
    </tr>
    </table>

    <h3>Misc</h3>

    <table class="form-table">
    <tr>
        <th><label for="altID">Alternate ID</label></th>
        <td>
            <input type="text" name="altUserID" id="altUserID" value="<?php echo esc_attr( get_the_author_meta( 'altUserID', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    
    </table>
<?php }

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

function save_extra_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }
    update_user_meta( $user_id, 'huna', $_POST('huna') );
    update_user_meta( $user_id, 'ki', $_POST('ki') );
    update_user_meta( $user_id, 'validation', $_POST('validation') );
    update_user_meta( $user_id, 'welcome', $_POST('welcome') );
    update_user_meta( $user_id, 'altUserID', $_POST('altUserID') );
}

Create link to custom URI-scheme on home-screen (eg. zoomus://zoom.us/…) to start app

Is there a way to create an app-icon-link to a non HTTP-url and place it on the home screen?
I’m trying to add an icon to auto-join a zoom-meeting.

https://marketplace.zoom.us/docs/guides/guides/client-url-schemes

The idea are to pass parameters like meeting id and password to the app Zoom, that uses the URI: zoomus://
Eg. zoomus://zoom.us/join?confno=123456789&pwd=xxxx

I have done similar on iOS / iPadOS using the Shortcut app.
Thanks for advice!

Modify custom attribute value before place order

I have a custom attribute that is placed in the Billing Address section. Now there’s a condition that I only need to save the first 200 character of my custom attribute text box. Is there an event or observer that will intercept this request before proceeding to save/place order? So basically on the checkout page after inputting the text in my custom attribute when user click the Place Order button I want to check this input first if it’s beyond the limit then I will trim the text. How do I do this?

Heavily Customised MyBB Forum (Custom Theme + Addons)

Why are you selling this site?
I started this project last year and have not got round to opening the forum but it has great potential.

How is it monetized?
Not currently.

Does this site come with any social media accounts?
N/A

How much time does this site take to run?
The more time you put into it the more profit you will return, a bit like any website.
SEMrush

What challenges are there with running this site?
Growing the community.

 

Custom taxonomy template shows different content if there are children

I am trying to create a template for my custom post type (products) custom taxonomy (product_category) that will show sub categories if there are any and but if there aren’t, then it should list the products.

As an example

categories:

category1
category2
-sub-category1
-sub-catetory2
category3

so if the url is loaded (/product_category/category1) then it will list the products in that category.

However if (/product_category/category2) is loaded, then it will show the names “subcategory1” and “subcategory2” but no actual products.

Here is what I came up with so far, but it feels “hacky” is there a better way to do this?

<?php
get_header(); ?>

    <div id="primary">
        <main id="main">
            <?php

            do_action( 'generate_before_main_content' );

            if ( have_posts() ) :

                $term = get_queried_object();
                $term_id = $term->term_id;
                $taxonomy_name = $term->taxonomy;

                $termchildren = get_term_children( $term_id, $taxonomy_name );
                if ( $termchildren  ) {
                        //there are kids...just show the children categories.
                                            // we have kids...just show the terms.
                   echo '<ul>';
                   foreach ( $termchildren as $child ) {
                       $term = get_term_by( 'id', $child, $taxonomy_name );
                       echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
                }
                   echo '</ul>';
                } else { 
                    //no kids...right on to the products.
                    echo '<div class="productCategories grid">';
                        while ( have_posts() ) : the_post();
                            ?>
                            <div class="product_cat">
                                <a href="<?php the_permalink();?>">
                                    <?php the_post_thumbnail('small');?>
                                    <h2><?php the_title();?></h2>
                                </a>
                            </div>
                            <?php
                        endwhile;
                    echo '</div>';
                }
            else :
                get_template_part( 'no-results', 'archive' );
            endif;
            ?>
        </main><!-- #main -->
    </div><!-- #primary -->

    <?php
get_footer();

entities – Create Custom Select Webform Element

I asked this last time with ‘Select Other’, but I am still not understanding how to change custom element’s type. In this scenario, I am attempting to build a Select type webform element. I am reusing the Webform Example attached to the webform module. But my issue is that I can not change it from an <input> to a <select> type.

Inside, webform_example_elementsrcElementWebformExampleElement.php I have tried:

  public function getInfo() {
    $class = get_class($this);
    return (
      '#title' => $this->t('Facility'),
      '#type' => 'Select',
      '#input' => false,
    ...
   }

AND I have tried:

  public static function processWebformAssignedBy(&$element, FormStateInterface $form_state, &$complete_form) {
    $element('#tree') = true;
    $element('#type') = 'select';
    $element('#input') = false;
    $element('#options') = (
      '1' => 'One',
      '2' => 'Two',
    );

Using X-Debug, when the page is loaded I get:

$element = {array} (48)
 #type = "select"
 #title = "current_facility"
 #multiple = false
 #access_create_roles = {array} (2)
 #access_update_roles = {array} (2)
 #access_view_roles = {array} (2)
 #webform = "generate_system_number_form_1_"
 #webform_id = "generate_system_number_form_1_--current_facility"
 #webform_key = "current_facility"
 #webform_parent_key = "net_new_process_information"
 #webform_parent_flexbox = false
 #webform_depth = {int} 1
 #webform_children = {array} (0)
 #webform_multiple = false
 #webform_composite = false
 #webform_parents = {array} (2)
 #admin_title = "current_facility"
 #webform_plugin_id = "facility"
 #webform_submission = "121"
 #access = true
 #webform_element = true
 #allowed_tags = {array} (78)
 #element_validate = {array} (1)
 #pre_render = {array} (1)
 #after_build = {array} (1)
 #_webform_access = true
 #_webform_states = {array} (0)
 #theme = "input__webform_example_element__webform_generate_system_number_form_1__form__current_facility"
 #theme_wrappers = {array} (1)
 #formdazzle = {array} (3)
 #process = {array} (3)
 #input = false
 #value_callback = {array} (2)
 #defaults_loaded = true
 #tree = true
 #parents = {array} (1)
 #array_parents = {array} (3)
 #weight = {float} 0.007
 #processed = false
 #required = false
 #attributes = {array} (1)
 #title_display = "before"
 #description_display = "after"
 #errors = null
 #id = "edit-current-facility"
 #name = "current_facility"
 #value = ""
 #options = {array} (2)

But after returning, I still get an <input> field. Any suggestions how to alter the input type to be select? Thank you

magento2 – Add TOTAL ROW for Magento Custom Grid

I was wondering if there’s a way to add a Total Row in a Custom Grid in Magento 2? I already have a Custom Report using Custom Grid in Magento so I made like 20 reports all in all. But client want to add a total in each of the tables but I can’t find any source that will tell me how to do it. Surely I can just copy the approach in vendor/magento/module_report but redoing all the report I did will be very time consuming. And it doesn’t make sense to redo all the code just to add a TOTAL ROW in each of the table. For now I have this

enter image description here

But what I’m trying to achieve is something like this

enter image description here

As you can see the TOTAL Row should be inside the first Grid Table and not in a separate table. Is there a way to achieve this in Magento 2 Custom Grid?

Note: I already checked the vendor/magento/module_report but this require me to redo all my code for custom grid. Is there a simpler and correct way to do this?