magento 1.9 – Adding or removing option in a quote item

I had to create a controller that added or removed an option from a quote item.

I succeeded but I did not convince the solution. It seems strange to me to have to manage the correct filling of the option: "option_ids". Can someone of experience tell me if there is a better solution?




// Add optional o remove.
$ optionId = 1234; // Optional Id.
$ optionData = $ product-> getOptionByid ($ optionId);
foreach ($ optionData-> getValues ​​() as $ v) {
$ optionId = $ v-> getOptionId ();
$ optionCode = "option _". $ optionId;
$ itemOptionIds = $ quoteItem-> getOptionByCode (& # 39; option_ids & # 39;);

if ($ status) {
$ quoteItem-> addOption (new Varien_Object ([
          'product' => $quoteItem->getProduct(),
          'code' => $optionCode,
          'value' => $v->getOptionTypeId()
          ])
)

if ($ itemOptionIds) {
$ optionIds = explode (& # 39 ;, $ itemOptionIds-> getValue ());
$ optionIds[] = $ optionId;
$ quoteItem-> getOptionByCode (& # 39; option_ids & # 39;) -> setValue (implode (& # 39 ;, $ optionIds));
} other {
$ quoteItem-> addOption (new Varien_Object ([
                'product' => $quoteItem->getProduct(),
                'code' => 'option_ids',
                'value' => $optionId
              ])
)
}
} other {
$ optionIds = [];
if ($ itemOptionIds) {
foreach (explode (& # 39 ;, $ itemOptionIds-> getValue ()) as $ itemOptionId) {
if ($ optionId === $ itemOptionId) {
$ quoteItem-> removeOption (<option _ $ optionId);
} other {
$ optionIds[] = $ itemOptionId;
}
}

if (! empty ($ optionIds)) {
$ quoteItem-> getOptionByCode (& # 39; option_ids & # 39;) -> setValue (implode (& # 39 ;, $ optionIds));
} other {
$ quoteItem-> removeOption (& # 39; option_ids & # 39;);
}
}
}

$ quoteItem-> setDataChanges (true);
$ quoteItem-> save ();
}

// Save the cart.
$ this -> _ getCart () -> save ();

Adding HTML in the HTML tag for all MediaWiki Web pages

How to add HTML in the HTML tag for all MediaWiki web pages?

  • In /skins/mySkin/includes/mySkinTemplate.php I did not find anything to do with .

  • I have not found any global template file and I prefer not to use a hook for this.

Is there another way?

javascript – Code design: introduction of a new method vs adding an optional parameter to an existing method

In JavaScript (ES6), I can have an optional function parameter with a default value. So, to add a new behavior to the existing codebase, I could either introduce new methods or extend the existing method with an optional parameter.

Let's take the following example:

Existing method:

something (param) {
// code to do something trivial
}

New desired behavior: the ability to do something special after a trivial thing


Option 1: Extend the existing method

                doSomething (param, isSpecial = false) {
// code to do something trivial
if (isSpecial) {
// code to do something more special
}
}

Use:

                doSomething (param); // do something trivial
doSomething (param, true); // do something special

Option 2: Add a new method

                something special (param) {
doSomething (param); // just call the existing method to do something trivial
// code to do something more special

Use:

                doSomething (param); // do something trivial
doSomething special (param); // do something special

Option 3: Extend the existing method and add two new methods

                something (param, isSpecial) {
// code to do something trivial
if (isSpecial) {
// code to do something more special
}
}

something trivial (param) {
doSomething (param, false);
}

something special (param) {
doSomething (param, true);
}

Use:

                something trivial (param); // do something trivial
doSomething special (param); // do something special

Currently, I mainly use the first option, because it's less code to write. But thinking about the open-ended principle, that does not seem right to me.

So, which option should I choose? (in general, not special in JavaScript)

google sheets – Comparing two cells and adding a check mark to the corresponding values

I have two columns, one with all the elements of one set and another with the elements that I currently have. I would like to compare these and for the corresponding results to have some added text if they match. Here is an example.

So, in this example, column A is the defined number, column B is the set values, column C is what I currently have, and column D is the expected result.

So, I want to compare B to C and if their names match, then I want B to have the word & # 39; CHECK & # 39; added to the corresponding name.

I thought doing this to get the word "CHECK". added

= ARRAYFORMULA (B2: B & "-CHECK")

But do I also need a SEARCH and LEN operate here?

Could the application script be easier?

Thank you for any advice,

scheduling practices – RESTful API – Adding nested resources as a query parameter?

I've recently been thinking about managing flat vs. nested architecture when designing a RESTful API.

Would there be a problem with a system in which your nested resources can be specified in a request parameter of the API request? This is only necessary in certain complex situations, otherwise you would access it regularly via collections / instance / collections / instance.

Example:
Let's say we need to get a thread with its user comments.

Flat architecture way:

getThreadWithPostCommentUsers (threadUuid) {
const thread = new Thread ();

// by default, flat however becomes a lasagna code.
// conscious data, heavy, flexible layer.
this.http.request (& # 39; threads / & # 39; + threadUuid) .then ((threadData) => {
Object.assign (thread, threadData);

this.http.request (& # 39; threads / + + threadUuid + & # 39; / posts & # 39;). then ((posts) => {
thread.posts = posts;

posts.forEach (post => {
this.http.request (& # 39; posts / + post.uuid + & # 39; comments) .then ((comments) => {
post.comments = comments;

comments.forEach (comment => {
this.http.request ('users /' + comment.user_uuid) .then ((user) => {
comment.user = user
console.log (comment.user);
});
});
});
});
});
});
}
  • Large amount of layers, lasagna code
  • Flexible for efficient multiple use of data.

It feels most encapsulated and simple. However, it starts to become a little redundant and unfavorable when dealing with a lot of relationships.

Nested architecture way:

getThreadWithPostCommentUsers (threadUuid) {
const thread = new Thread ();

// by default has nested objects, very simple but inefficient
// not aware of the data, not heavy in layers, not flexible
this.http.request (& # 39; threads / & # 39; + threadUuid) .then ((threadData) => {
Object.assign (thread, threadData);

thread.posts.forEach (post => {
post.comments.forEach (comment => {
console.log (comment.user);
});
});
});
}
  • Small amount of layers
  • Not flexible for efficient multiple use of data.

The nested method is interesting from the point of view of convenience, but it is not very flexible if you want to minimize the data.

So my idea was to combine the two, where I can take advantage of the advantages of a simple and flat architecture, but also to load nests into a query.

Hybrid Flat and Nested Way:

getThreadWithPostCommentUsers (threadUuid) {
const thread = new Thread ();

// default flat, add nests based on the resources parameter
// flexible, data aware, no heavy layer
this.http.request (& # 39; threads / + threadUuid + & # 39 ;? resources = posts.comments.user & # 39;). then ((threadData) => {
Object.assign (thread, threadData);

thread.posts.forEach (post => {
post.comments.forEach (comment => {
console.log (comment.user);
});
});
});
}
  • Small amount of layers
  • Flexible for efficient multiple use of data.

My requests would be flat by default, but my requests have the ability to call some nested resources on demand without creating many custom routes and optimizing data efficiency.

The authorization would always be done at the server level, allowing only certain resources depending on the request.

Would it be a bad choice of practice / design? What are your thoughts? Is there anything for that and I reinvent the wheel?

Thank you

javascript – can XSS attacks be rolled back by adding a backslash to all external links?

On my website, I noticed that my developers had it set up so that some form data had moved from the URL to the content of the website. FOR EXAMPLE

? email = "email"

The obvious vulnerability means that I can put? Email = "XSS vector" in the field and that XSS Vector would be displayed in the email field.

Another was that, when only one form data was present, additional data could be added at the end of the URL. for example

? email = "email" XSS vector

I informed the developer of this vulnerability and they told me that the website was secure because all the text was cleaned up. For example, if I had to add an external link or file via the URL

? email = "email"   

what is rendered in html is


And the link leads to

https://mysite.com/https://myscripts.js

Which means that the script can only be loaded if it is on my domain.

However, I only know the basic HTML, JS. So, I can not check if it is safe.

I would prefer it not to happen at all, but I do not have the skills to fix it myself. But if I have it like that, I need to know that it is secure.

Magento 1.9 – Add a tax-free product to a specific product when adding to cart

When I add a specific product to the cart, I also want to automatically add a tax-free product to the cart.

Example

  • Addition of a watch (500 €) with 21% tax in the basket
  • Automatically add the product excluding tax (30 €)

The price will be: 500 € + 21% tax (605 €) + 30 € before tax.
Total price: 635 €

How can I do this?

javascript – Adding jQuery to a Drupal Web Form 8

Trying to count the selected radios in a web form, I managed to make it work outside of Drupal (see the link below), but I do not know how to add it to my theme / Web form.

https://jsfiddle.net/j9q75Lay/

I have created a .js file containing the jQuery code:

                $ (document) .ready (function () {
$ (& # 39; input: radio & # 39;). change (function () {
var a = $ ("input[value='a']: checked ").
var b = $ ("input[value='b']: checked ").
var c = $ ("input[value='c']: checked ").
$ (& # 39 ;. a_results & # 39;). text (a)
$ (& # 39; .b_results & # 39;). text (b)
$ (& # 39 ;. c_results & # 39;). text (c)
})
});

I saved the .js file in the / js folder of my theme and added it to my theme's .library.yml file, as follows:

                global scripts:
js:
js / jscripts.js: {}
js / webform_count_radios.js: {}
dependencies:
- kernel / jquery

I drush cr

I created a textfield element in my web form and added the class "a_results". (I'll add two more each for b_results and c_results)

But it does not work! In fact, the .js file seems to break other js-dependent features in my web theme / form (for example, iCheck and the rrssb block).

It's my first try of this type and I'm not sure where I'm going wrong.

Thank you for your help.

boot – Adding programs when Windows 10 starts using the task manager

I'm aware that when I want to run a program on Windows startup, I'm supposed to add a shortcut to the following folder:

C:  Users [username] AppData  Roaming  Microsoft  Windows  Start Menu  Programs  Startup

However, there is also a Startup tab in Task Manager, where you can enable / disable specific applications running at startup. I like it better because it gives me a single logical location to control that.

Unfortunately, I am unable to find a way to add / remove programs manually. When an application asks me if I want to run it from startup and that I confirm, I presume that it changes something in the registers and that the application appears in the list in the Task Manager.

Can I directly edit the start list in the task manager or do I need to check the logs? Or do I really have to manage this using this silly folder?