I want to update Magento articles through the Magento PHP SOAP API.
This request works fine:
$result = $soap->catalogProductUpdate($session_id, $res[0]['sku'], array(
'price' => '69,99'
));
But I want to do something like this:
$result = $soap->catalogProductUpdate($session_id, $res[0]['sku'], array(
$_POST['t0'] => '69,99'
));
The variable $_POST['t0'] contains the string that I want to update, in this case $_POST['t0'] = 'price'.
But it does not work. Any idea how to use post-variables as an array-key?
Related
I am using the Firebase PHP Admin SDK: https://firebase-php.readthedocs.io/en/stable/realtime-database.html#update-specific-fields
Here is the example it gives to update specific fields:
$uid = 'some-user-id';
$postData = [
'title' => 'My awesome post title',
'body' => 'This text should be longer',
];
// Create a key for a new post
$newPostKey = $db->getReference('posts')->push()->getKey();
$updates = [
'posts/'.$newPostKey => $postData,
'user-posts/'.$uid.'/'.$newPostKey => $postData,
];
$db->getReference() // this is the root reference
->update($updates);
From that, I created a users class and in that I have an update function. Like so:
public function update() {
$data = array('users' => array('1' => 'David'));
$this->database->getReference()->update($data);
return true;
}
In my database I have this structure:
Now if I run that function $users->update();
It removes the other child and only leaves David. Like so:
How can I update only a specific value of a specified key without it overriding the other data?
There's nothing specific to PHP here. That's the way Realtime Database update operations work. If you want a minimal update, you have to target the deepest key that you want to update. In your case, since you're storing an array type object, the keys are the number indexes of the array items you've written. If you want to modify one of them, you need to build a reference that includes the child number you want update. In that case, none of the sibling values will be touched.
Try this instead:
$this->database->getReference('users')->update(array('1' => 'David'));
Notice here that the update is rooted at "users", and you're updating just the immediate child "1" of that.
The example on docs is a little bit hard to grasp as a beginner. I have made it simpler for you to understand.
Once you get the newPostKey, prepare the url for child and run the code. It will only change the specific fields.
$ref = 'users/' . $newPostKey;
$updates = [
'title' => 'Updated title',
'body' => 'Updated body text',
];
$set = $db->getReference($ref)->update($updates);
Obviously, I can't do this, but is there some way to achieve what I am trying to? I only found can not do's online, but no potential workarounds.
Here is what I am trying to do.
Currently I get the following error... "Cannot use [] for reading"
For my theme, I have a framework and the fields from that framework are built using an array that I create.
It looks something like this (minus the 300+ lines of code that I actually use)...
$options[] =
array(
'title' => 'This Field Tab Title',
'name' => 'this-field-tab-slug',
'fields' =>
array(
// ----------------------------------------------------------------------
// This Field Option Name
// ----------------------------------------------------------------------
array(
'type' => 'this_field_type',
'id' => 'this_field_types_id',
),
// ----------------------------------------------------------------------
// This Field Option Name
// ----------------------------------------------------------------------
array(
'type' => 'this_field_type',
'id' => 'this_field_types_id',
),
// ----------------------------------------------------------------------
// This Field Option Name
// ----------------------------------------------------------------------
array(
'type' => 'this_field_type',
'id' => 'this_field_types_id',
),
),
);
I am running a grouped field type, so my output has many options/fields within this grouped field/area which can then be added again and again as many times as the user needs. Then I am repeating that whole process/code again but for other taxonomies of the user's site.
So for example, the whole process above applies to post types, categories, tags, archived, etc. etc. So instead of having thousands of lines of repetitive codes, I'm trying to create my own function and pass the variables to that function.
But for the function, I find I can't return $options[];
Here is a screenshot of what I mean by the grouped field that can be added as many times as the user needs.
And here's an example of the function I am trying to create!
public static function layout_settings_config($title_name = '', $title_slug = '', $title_id = '', $query = '') {
$title_name = 'Post Type';
$title_slug = 'post-type';
$title_id = 'post_type';
$query = 'post_types';
$options[] =
array(
// all the config array codes in here...
);
return $options ??? $options[]; doesn't work.
}
Is this possible to achieve what I am trying to a different way? I'm still a little new to creating my own functions and OOP, but nothing I find online for this specific issue with a workaround.
Thanks!
$options[] is not object but it is an operation like function.
You should return $options instead.
and, by the way, when you say $options[] = something. it actually insert something inside an array called $option. so effectively you have to access your options like this.
$option[0]->title.
So I suggest Instead of making it complex like this. simply say
$option = something.
I am trying to place an order via WHMCS API on my local environment. This is my order code,
$postfields["action"] = "addorder";
$postfields["clientid"] = "104";
$postfields["billingcycle"] = "monthly";
$postfields["pid"] = "55";
$postfields['configoptions'] = base64_encode(serialize(array(1 => 3)));
$postfields["regperiod"] = "5";
$postfields["paymentmethod"] = "paypal";
It is listed on the API doc that 'configoptions',
$postfields['configoptions'] = base64_encode(serialize(array(1 => 3)));
^ is for changing the order quantity and other options(first element is for the quantity). Problem is that the invoice generated by WHMCS only contains quantity as 1 and not 3.
---------------------------------------------------------Edit 1 ------------------------------------------------------------------
I have looked into the product configurations, "Tick this box to allow customers to specify if they want more than 1 of this item when ordering" option is ticked as well!
A bit late to the game but oh well.
In the current WHMCS API documentation for the AddOrder function I have not been able to find anything regarding quantity, I have a feeling that at this point that simply enables an input in the order form and WHMCS handles that input somehow.
I did find a way that might work for you though. Im not sure how you are actually using the API if it's driven by some custom form somewhere or what but you can do the following.
in lieu of:$postfields['configoptions'] = base64_encode(serialize(array(1 => 3))); which doesn't seem to work you can just use the 'pid' field to specify the quantity, something like this:
$quantity = trim(str_repeat("{$pid},", $_POST['qty']), ',');
$postfields["pid"] = $quantity;
Simply repeating the product ID as many times as desired sets the quantity, you can do basically the same thing using the local API function, see below:
$quantity = array_fill(0, $_POST['qty'], $pid);
$command = 'AddOrder';
$postData = array(
'clientid' => '1',
'pid' => $quantity,
'domain' => array('example.com'),
'billingcycle' => array('monthly'),
'paymentmethod' => 'PayPal',
);
The result of the above code will be a single order with however many products ($pid) were specified in $_POST['qty']
I need to clear data from the class created in parse.com'm using CURL with PHP.
However, I have to put in a foreach so that data and it makes very heavy processing.
Is there any way to delete all rows automated class?
foreach($request->results as $item){
$params = array(
'className' => 'UltimaMilha',
'objectId' => 'QE0oL2R4X6,xc3rzlKF7U'
);
$request = $parse->delete($params);
}
I'm trying to get products from Magento API with catalogProductList (soap v2) here is my function.
public function get_products() {
$products = array();
$login = $this->login_info();
$proxy = new SoapClient($login['url']);
$sessionId = $proxy->login($login['user'], $login['pass']);
$result = $proxy->catalogProductList($sessionId);
foreach($result as $value) {
$products[] = $proxy->catalogProductInfo($sessionId, $value->product_id);
}
echo "<pre>";
var_dump($products);
echo "</pre>";
}
However because the request it's in a loop it will make for each product a request to Magento API.
I'm wondering if there is a solution to get multiple products info (based on provided product_id) in the same request. Maybe 50 or 100 products info for each request I think will reduce a lot the time of getting all the products.
I have found on http://www.magentocommerce.com/api/soap/introduction.html
$params = array('filter' => array(
array('key' => 'status', 'value' => 'pending'),
array('key' => 'customer_is_guest', 'value' => '1')
));
$result = $client->salesOrderList($sessionId, $params);
but from my understanding it's more about filtering the products so I don't know if it helps too much.
Looks like you're calling the catalogProductList twice, first time outside the loop and the second time inside the loop passing invalid arguments, the doc here is showing that you only need to use the method once passing the session id plus you are able to pass two extra optional arguments (array of filters and the store view id or code) additionally if the returned result catalogProductEntity is not enough you can override that part of the API adding extra product information for example the media images.