getOfferById method provided by an API does not work (invalid Id or Error cannot find parameter) [Laravel] - laravel

I am a junior developer working on this project.
I'm using an API who provide offers and I'm trying to display them.
They provide several methods as "getOffers" "search" "getOfferById".
I managed to display all the offers with the getOffers, but I can't use the getOfferById. I might be using it the wrong way.
They also provide us with a sandbox to play with the methods so when I put the id on the sandbox it works fine. Here is an exemple from the doc:
$offer = $soapClient->getOfferById($offerId, array('key' => 'length.unit', 'value' => 'm'));
and here is what I've tried so far :
$offerId = 2020012100009;
$offer = $soapClient->getOfferById($offerId, array('key' => 'length.unit', 'value' => 'm'));
dd($offer->length);
I get "Error can not find parameter" for this.
$offer = $soapClient->getOfferById($offerId);
and I get "Invalid Id" for this.

There is no such id in the database, are you sure that the id you providing is valid?

I resolved my problem. I had to apply it like that.
$offer = $soapClient->getOfferById(array(
'id' => $offerId
));

Related

Add cursorPaginate to collection

So, I have built a very detailed collection in Laravel to give me very specific and clean data in a format that works within my frontend. Now, forgetting that this will be a LOT of data, I needed to add paginate. As this is just going to be infinite scroll, I wanted to use cursorPaginate
Unfortunately, the code below does not allow it. The standard error of Method Illuminate\Support\Collection::cursorPaginate does not exist
How would I be best to refactor this to give me the data required AND give me cursorPaginate? I am completely open to changing some of it, I just do not know where best to start.
Thanks in advance!
return Activity::get()->groupBy('batch_uuid')->map(function ($batch) {
return [
'description' => $batch->first()->description,
'uuid' => $batch->first()->batch_uuid,
'event' => $batch->first()->event,
'created_at' => $batch->first()->created_at,
'subject' => $batch->first()->subject_type::find($batch->first()->subject_id),
'activities' => $batch->map(function ($activity) {
return [
'item' => $activity->causer_type::find($activity->causer_id),
];
}),
];
})->sortByDesc('created_at')->values();
```
You should watch this video from Laravel Daily. First method mentioned in this video he uses LengthAwarePaginator but you can try CursorPaginator for your purpose.

unable to get spring-social-showcase-boot working due to facebook scope?

I am following the instructions provided here to get spring-social-showcase-boot running in my local.
This is the error I get when I try to authenticate using facebook. The error is clear that read_stream scope is invalid.
But I am unable to figure where this scope is configured in the spring-social-showcase-boot example.
Any help to fix this would be much appreciated.
I encountered the same problem. You can change the scopes you request by modifying the 'scope' form field in /src/main/resources/templates/connect/facebookConnect.html.
Specifically I removed 'read_stream' and just had 'email' as the value of that form input.
I hope that helps!
Just change:
./admin/sources/classes/facebook/connect.php: public $extendedPerms = array( 'email', 'read_stream', 'publish_stream' );
to be:
./admin/sources/classes/facebook/connect.php: public $extendedPerms = array( 'email' );

zf2 DB insert using custom query is not working

We are developing a website using ZF2. We alreday started the project. We installed ZF2 skelton application and integrated the album module. Everything seems working. Now we are trying to integrate multiple zend forms in a module. Forms eveyrything we made [ by modifying the albulm module elements) I am able to insert/update/delete etc data in to the default table that set on the module.php file [this is for form 1].
I have another form which requires to insert/delete/update to another table, I created new form class, Table class (on model) etc. When I tried to insert the data in to Db using custom query format, it throws error:
File:
/home/catholic/public_html/propertydosth/vendor/zendframework/zendframework/library/Zend/Db/Sql/Insert.php:298
Message:
The key adapter was not found in this objects column list.
It seems adaptor value is not getting something..
My Code for insert query:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $insert->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
I am getting correct query value when I echoed $selectString .
Any one please suggest what is wrong in my code to get it done.
Finally Sam helped me on this issue:
So correct Answer become [this will be helpful somebody having similar issue. Even I spent lot of time to debug the same]:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);

Updating post_meta in WordPress through XML-RPC

I am currently working on a project that involves scraping data from over 300 static pages and transferring that data into a WordPress site. I have set up various custom fields with the Simple Fields (http://simple-fields.com/) plugin, and have a basic XML-RPC connection working. Below is what I am using to test injecting custom posts (written in Ruby):
connection = XMLRPC::Client.new_from_uri "http://localhost:8888/xmlrpc.php"
username = "admin"
password = "password"
test_post = {
:post_type => "custom_property",
:post_status => "draft",
:post_title => "test post!",
:post_meta => {
:_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0 => "test"
}
}
puts connection.call("wp.newPost", 1, username, password, test_post)
I have tried :custom_fields in place of :post_meta but still to no avail. I can't seem to be able to update the custom fields that have been created through Simple Fields.
If anyone has any suggestions on what to do, it would be greatly appreciated.
EDIT: This problem was solved by extending the XML-RPC functions using this article: http://kovshenin.com/2010/custom-xml-rpc-methods-in-wordpress/
It is actually quite tricky to figure out the structure of the Wordpress post. If it is a custom field you want to post in, you should use the format below:
'custom_fields' => [{'key' => 'something', 'value' => 'something else'}]
If it is custom taxonomy, use this:
'terms' => {
'custom_type' => [value],
'custom_something' => ['array_item','array_item']
}
For terms you always need to put the value into an array even if it's just one item. Hope it helped.

Codeigniter Datamapper not running get rules on fields with NULL values

I'm using Datamapper v1.8.2 with Codeigniter v2.1.2 and have a "get" rule that doesn't seem to run on fields with NULL values. Here's the model:
class Page extends Datamapper {
public $validation = array(
'name' => array(
'rules' => array('required'),
'get_rules' => array('get_page_name')
)
);
function _get_page_name($field)
{
$this->$field = 'TESTING '.$this->id;
}
}
Example code:
$page = new Page();
foreach ($page->get() as $p) echo $p->name;
When the table field name has any non-null value including an empty string it works fine outputting something like TESTING 358, but when the value is NULL (which is the default value for this field), it outputs nothing. There is no difference using get_iterated().
I guess I could work around this by changing the default value, but I'm wondering if I'm doing something wrong or missed something in the documentation, or maybe it's a bug? Does anyone know what the issue is?
Also, if someone could point me to the proper thread in the CI forums for Datamapper 1.8.2 support that would be great, I'm trying to find it and getting lost in a maze of links to threads for old versions of DM.
You need to add the allow_null to the get_rules array to make this work. I'm not sure about the intent of the creator but this is how get_rules are implemented (however i don't see it mentioned in the docs).

Resources