Home computickets does not add the price for the

does not add the price for the

Author

Date

Category

Good day
I am trying to add the price of already existing goods, but prices are not added.

And noticed, if then in the admin hand, put the price, then the CPRice :: Add method, or Update, already the price is set (changes).

also noticed if in $ arfields, I will point in “quantity_from” = & gt; 1, “quantity_to” = & gt; 10, the price is set by the Add.

1) In general, the product initially is installed without a price, and in the field “Basic price” is empty. And then if when installing the CPRice :: Add AdD method, nothing is not installed, it does not even give an error, but on the contrary, the IF section works, not the price is not installed.

2) if in $ arfields, specify “quantity_from” = & gt; 1, “quantity_to” = & gt; 10. That price is set.

3) If the product has arms to specify the price in the admin, then you can later install or update the price.

And how to set the price without setting up in “quantity_from” = & gt; 1, “quantity_to” = & gt; 10. And putting hands, but immediately not looking empty there or not, just set the price that is indicated in Arfields [‘Price’]?
Can anyone come across such a task? Share your experience. =)

Here is the code:

$ product_id = 15;
$ Price_type_id = 2;
$ arfields = array (
  "Product_ID" = & gt; $ Product_id
  "Catalog_group_id" = & gt; $ Price_type_id,
  "Price" = & gt; 29.95,
  "CURRENCY" = & gt; "USD",
  "Quantity_from" = & gt; 1,
  "Quantity_to" = & gt; ten
);
$ res = CPRice :: GetList (
    Array (),
    Array (
        "Product_ID" = & gt; $ Product_id
        "Catalog_group_id" = & gt; $ Price_Type_id
      )
  );
if ($ arr = $ res- & gt; fetch ())
{
  CPRice :: Update ($ Arr [ID "], $ arfields);
  DUMP (Arfields);
}
ELSE.
{
  CPRice :: Add ($ arfields);
  DUMP (Arfields);
}

Arfields is printed, but the price is not added and not updated.


Answer 1, Authority 100%

I suspect that after adding an item, you do not CCATALOGPRODUCT :: Add than you do not create a directory item for which you can already assign prices. And the update through the administrator is triggered because the system itself adds an element to the table when manipulation in admin.

The sequence of actions when adding goods should be like this:

$ element = new \ ciblockelement ()
$ result = $ Element :: Add ($ arfields);
If (IS_Numeric ($ Result)) {
  CCATALOGPRODUCT :: Add ($ arfields); // here ID element
  CPRice :: Update ($ Result, $ Arfields);
} else {
  Echo $ Element- & GT; Last_error;
}

You can see more detail in documentation

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions