magento2 – Move Attributes from Attritube group to Unassigned Attribute Programmatically

enter image description here

Im trying to move attribute from Attribute group to unassigned from all attribute sets in my controller.
I tried below code by its not removing, instaed its deleted.

$eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
$eavSetup->removeAttribute( Product::ENTITY,'my_custom_attribute_code');

When i try below nothing happens to the attribute

$attribute = $this->_eavConfig->getAttribute( Product::ENTITY, 'manufacturer');
$id = $attribute->getAttributeId();
$options = $attribute->getSource()->getAllOptions();
foreach ($options as $option) {
           $options('delete')($option('value')) = true; 
            $options('value')($option('value')) = true;
            }
           $eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
          $eavSetup->addAttributeOption($options);

Anyone help how to achieve this? Thanks!

Get Image URLs (and prices) of product attributes (color)

I need the images for all color options of a product (and also prices in case they are different in different color options). I figured out how to get the color options of a product:

$colorAttribute = $product->getResource()->getAttribute('color');
$colorAttributeId = $colorAttribute->getId();
$configurableAttrs = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);

$values = $configurableAttrs($colorAttributeId)('values') ?? ();

But how do I now get the product image URL (and price) in all color options?

magento2 – How do you send additional attributes to order using /rest//V1/guest-carts/{cart-id}/order REST API Magento 2?

I have successfully placed order by creating cart and finally calling rest api /rest//V1/guest-carts/{cart-id}/order to place the order. Now I am trying to add an additional attribute custom_attribute to be displayed on orders table page of admin dashboard but am unable to figure out the way around.

I have tried to extend the magento functionality using following link but somehow cannot set custom attribute via rest api

Magento 2 – How to add new order attribute

accessibility – Accessible non-english website: what input element attributes in native language?

I’m making an accessible Dutch language website. As a rule variable names in code are in English because not all programmers are Dutch natives. Do any of the attributes of input fields have to be in Dutch to be usable by a Dutch screenreader and compliant with WCAG?

Below is an example of a labelled radio-group:

<fieldset>
    <legend>Geef neerslag door:</legend>
    <div class="form-div" id="rainfall">
        <input type="radio" id="no-rain" name="rainfall" value="none" />
        <label for="no-rain">geen neerslag vandaag</label><br/>
        <input type="radio" id="catsndogs" name="rainfall" value="catsndogs"/>
        <label for="catsndogs">regen regen regen</label><br/>
    </div>
 </fieldset>

Database schema for job offers with some common attributes

I’m trying to design a database in order to store IT job offers. My data comes from 4 different websites and unfortunately only part of their attributes (column names) are common. It looks like this:

Website 1: title, overall experience level
Webiste 2: title, overall experience level, skills required, skills nice to see
Website 3: title, overall experience level, skills required, level of required skills (junior or mid or senior)
Webiste 4: title, overall experience level, skills required, level of required skills (in years), skills nice to see, language, level of langauge

I would like to know how would you design a database with this kind of data? I did some research and found that it can be done in different ways:

Approach 1: only one table with all attributes (there will be a lot of nulls) but to be honest I think it’s bad idea.

Approach 2: one table storing common attributes to all websites and rest of attributes in separate tables. Also I must notice that each job offer has multiple values in skills required and skills nice to see attributes so I think these two must be in many-to-many relationship with JobOffer table
enter image description here

Approach 3: Four tables with attributes assigned to each of websites (so each table represents each website with its atrributes). And like in previous approach skills required and skills nice to see are in many-to-many relationship with almost (except WEBSITE1 table) every website table
enter image description here

Approach 4: Your own approach because none of these above fit well to this problem. (I’ve never been designing database before so I’m aware that all 3 approaches proposed by me could be wrong)

Thanks in advance!

plugins – Custom Field / Attributes change programmatically by the quantity of product sold

The stock quantity is logged by two items “Warehouse” and “Shop” in the Custom Fileds in Woocommerce.

I want the number in “Warehouse” can be minus programmatically according to the quantity of product sold.

For example, product Cake sold 500 grams, the “Warehouse 3500” will be changed to “Warehouse 3000”.

How can I edit this function to accomplish this function? The final result will be like a “dynamic” Custom Field.

add_filter( 'woocommerce_order_item_quantity', 'filter_order_item_quantity', 10, 3 ); 
function filter_order_item_quantity( $quantity, $order, $item )  
{
    $product   = $item->get_product();
    $term_name = $product->get_attribute('pa_hmotnost');

// The 'pa_hmotnost' attribute value is "15 grams" And we keep only the numbers
$quantity_grams = preg_replace('/(^0-9.)+/', '', $term_name);

// Calculated new quantity
if( is_numeric ( $quantity_grams ) && $quantity_grams != 0 )
    $quantity *= $quantity_grams;

return $quantity;

}

The Custom Fileds is NOT a third-party plugin, it is integrated by WordPress, https://wordpress.org/support/article/custom-fields/

enter image description here

wp autop – Disable wpautop on Shortcode attributes

I have a shortcode which accepts basic HTML tags as shortcode attribute.

When this shortcode is used in the shortcode block i.e within <!-- wp:shortcode --> then unbalanced <p> tags are added to the shortcode attribute.

If it is used normally, then no <p> tags are added.

Are there any workarounds which can be done to avoid this issue ?

function abcd_shortcode( $atts ){
    print_r( $atts );
}
add_shortcode('abcd', 'abcd_shortcode');

enter image description here

Output (notice the </p> and <p> tags added for no reason in the second array)

Array
(
    (html) => <h4>Hey</h4>Outside
)

Array
(
    (html) => </p>
<h4>Hey</h4>
<p>Inside
)

8 – Adding attributes to a link to an uploaded file

I have been asked to add target=”_blank” to the links that are produced when a user uploads a file on a Drupal 8 site.

The field type is “File”. Multiple uploads are allowed.

Twig debug shows me that the field is being produced by the core template “file-link.html.twig”. The entire uncommented contents of that template are:

<span{{ attributes }}>{{ link }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}

I brought that template into my custom theme and tried to add the attribute to the link. I thought I’d be editing the {{ link }} part of the template, changing it to attach attributes. I did variations of this:

{{ link(item.title, item.url, attributes.setAttribute(‘target’,’_blank’)) }}

Every syntax I tried produced a fatal PHP error. Thinking I was doing the attribute syntax wrong, I tested by simply trying to add a single class.

{{ link(item.title, item.url, { 'class': ('bananas') }) }}

That was still a white screen of death, so I guess I can’t use that syntax on the {{ link }} field in my file-link template.

I’ve been googling my eyeballs out of my head. I found this cool idea:

{% for item in items %}
  {{ item.content|merge({'#attributes': {'class': ('button', 'button--arrow', 'button--centered')}}) }}
{% endfor %}

so I adapted it for my field.html.twig template like so, changing this part:

{% for item in items %}
    <div{{ item.attributes }}>{{ item.content }}</div>
{% endfor %}

to this:

{% for item in items %}
      <div{{ item.attributes }}>{{ item.content|merge({'#attributes': {'target': ('_blank')}}) }}</div>
{% endfor %}

And while at least the page loaded and didn’t have a fatal error, the target attribute did not appear on the link.

Does anyone have any advice for me getting an attribute onto a file upload link? Almost everything I’ve found has to do with the link field, not the file upload field. Thanks for your time.

layered navigation filter attributes based on selection magento 2 api

I am aware of this Magento 2 api – How to get layer navigation filters available in rest api?.

If the color is selected as a filter then rest attributes like size should change based on that color.
How can I achieve that?

Thanks in advance.

Why Don’t We Add `Attributes` To Use Case Diagrams?

When talking about Use Case Diagrams, I like to make sure to mention one or two quotes from Martin Fowler’s UML Distilled:

The best way to think of a use case diagram is that it’s a graphical table of contents for the use case set.

and

Instead, concentrate on the textual description of a use case; that’s where the real value of the technique lies.

Going to your specific example, the first step is to figure out what the use case is. A use case is a list of interactions between a role (or actor) and the system under design. In the example, I would not consider “get date” or even “get details” to be a use case. The use case would be “book ticket”. A fully detailed use case would include information about who the actor is (the travel agent using the software system), their goal (reserve a ticket for a client or customer), other stakeholders (the agent’s customer, the airline), preconditions (authentication and authorization, perhaps), steps (a sequence of inputs and outputs to achieve the goal, including dates, times, addresses) and perhaps extensions or alternate flows (alternate sequences of inputs and outputs which could be positive or negative).

The way that I think about it is that the use case exists at a level that provides value. A travel agent wouldn’t use your system to enter an address – that doesn’t add value for the travel agent or their client. The value comes from being able to book a ticket. Once your system provides at least one slice of flow through the use case, the travel agent can realize some value. As more flows (if there are any alternate flows) are added, more value is realized.

The Use Case Diagram, however, doesn’t allow you to capture this level of detail. Like Fowler says, it’s a graphical table of contents.