I can't show my inventory on my reports in Amazon Selling Partner API - amazon

object(ClouSale\AmazonSellingPartnerAPI\Models\Reports\GetReportResponse)#482 (1) { ["container":protected]=> array(2) { ["payload"]=> object(ClouSale\AmazonSellingPartnerAPI\Models\Reports\Report)#491 (1) { ["container":protected]=> array(11) { ["marketplace_ids"]=> array(1) { [0]=> string(14) "A1VC38T7YXB528" } ["report_id"]=> string(11) "55933018913" ["report_type"]=> string(30) "GET_MERCHANT_LISTINGS_ALL_DATA" ["data_start_time"]=> object(DateTime)#506 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["data_end_time"]=> object(DateTime)#483 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["report_schedule_id"]=> NULL ["created_time"]=> object(DateTime)#502 (3) { ["date"]=> string(26) "2021-10-13 04:42:10.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["processing_status"]=> string(4) "DONE" ["processing_start_time"]=> object(DateTime)#481 (3) { ["date"]=> string(26) "2021-10-13 04:42:16.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["processing_end_time"]=> object(DateTime)#480 (3) { ["date"]=> string(26) "2021-10-13 04:42:25.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ["report_document_id"]=> string(73) "amzn1.spdoc.1.3.2149a182-4354-4177-b03e-0bc4552cb190.T25GAW47NVJ50Z.47700" } } ["errors"]=> NULL } }
I want to show my inventory using Amazon Selling Partner API. Firstly, I created a report for this. I have report id, document id etc.
When I pull the report with using GetReports function using this information, the inventory does not appear. Is it normal?
my expectation was that

I solved my problem.
Firstly, If you want to see second image (my expectation) you have to need the document id.
So
Create a report and get a report ID
Get a documentID with using a reportID
Use getReportDocument function with using documentID
Open decrypto document and read file
This is my code (on laravel)
public function getInventoryReportData() {
header('Content-Type: text/html; charset=utf-8');
$options = [
'refresh_token' => self::constOptions["amazon"]["refresh_token"],
'client_id' => self::constOptions["amazon"]["client_id"],
'client_secret' => self::constOptions["amazon"]["client_secret"],
'region' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerRegion::$FAR_EAST,
'access_key' => self::constOptions["amazon"]["access_key"],
'secret_key' => self::constOptions["amazon"]["secret_key"],
'endpoint' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$FAR_EAST,
'role_arn' => self::constOptions["amazon"]["role_arn"],
];
$accessToken = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
$options['refresh_token'],
$options['client_id'],
$options['client_secret']
);
$config = \ClouSale\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($options['access_key']);
$config->setSecretKey($options['secret_key']);
$config->setRegion($options['region']);
$apiInstance = new \ClouSale\AmazonSellingPartnerAPI\Api\ReportsApi($config);
$report_document_id = "YOUR_DOCUMENT_ID_IN_HERE";
try {
$result = $apiInstance->getReportDocument($report_document_id);
$key = base64_decode($result->getPayload()->getEncryptionDetails()->getKey());
$iv = base64_decode($result->getPayload()->getEncryptionDetails()->getInitializationVector());
$decryptedData = openssl_decrypt(file_get_contents($result->getPayload()->getUrl()), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
$convertEncodeData = mb_convert_encoding($decryptedData, 'UTF-8', 'ASCII, JIS, UTF-8, SJIS');
echo $convertEncodeData;
} catch (Exception $e) {
echo 'Exception when calling ReportsApi->getReportDocument: ', $e->getMessage(), PHP_EOL;
}
}

Related

Always the same view content on slim framework with twig after save changes

I'm using Slim and Twig and I'm trying to change a view content, but it doesn't change after I saved the changes.
This is the controller:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
require './classes/connection.php';
$app = new \Slim\App;
$container = $app->getContainer();
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('../../views', [
'cache' => '../../views_cache'
]);
// Instantiate and add Slim specific extension
$router = $container->get('router');
$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
$view->addExtension(new \Slim\Views\TwigExtension($router, $uri));
return $view;
};
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
/*$name = $args['name'];
$response->getBody()->write("Hello, $name");
echo getcwd();
return $response;*/
return $this->view->render($response, 'login.html', [
'name' => $args['name']
]);
});
$app->post('/login', function (Request $request, Response $response, array $args) {
$post_data = $request->getParsedBody();
if (isset($post_data['user']) && isset($post_data['pass'])) {
$mongo = new Connection();
$conn = $mongo->getConnection();
$collection = $conn->prueba->users;
$result = $collection->find(['user' => $post_data['user']])->toArray();
$dbUser = $result[0]['username'];
$dbPass = $result[0]['password'];
if (password_verify($post_data['pass'], $dbPass)) {
echo '¡La contraseña es válida!';
} else {
echo 'La contraseña no es válida.';
}
} else {
return $response->withJson(array('login_status' => 'ko'));
}
});
$app->run();
What I missed to see the view changes? I think it's something about compile view but I'm not sure. It's the first time I use this framework.

How get object from indices in Areablock?

I have Pimcore\Model\Document\Tag\Areablock with tree elements table of indices:
array(3) {
[0]=>
array(2) {
["key"]=>
string(1) "3"
["type"]=>
string(8) "newsData"
}
[1]=>
array(2) {
["key"]=>
string(1) "1"
["type"]=>
string(7) "wysiwyg"
}
[2]=>
array(2) {
["key"]=>
string(1) "2"
["type"]=>
string(12) "videogallery"
}
}
How could I get newsData object from Areablock object?
I coudn't find function in Areablock for that and don't know how to get date.
Thanks in advance.
Areabricks are not subelements of the actual areablock, but are direct elements of current document. Their names are just differently constructed.
$areablock = $this->areablock("yourAreablock");
foreach ($areablock->getData() as $brick) {
if ($brick["type"] == "yourAreaBrickName") {
$nameOfTheEditableInBrick = "bigtitle";
$indexOfTheAreaBrick = $brick["key"];
// This is your element
$subelement = $this->document->getElement($nameOfTheEditableInBrick . $areablock->getName() . $brick["key"]);
}
}

kohana 3 incorporate file validate in orm

I cant figure out how to add file validation code to the orm model
As the code is now the text inputs are validated in the orm, but the file has no validation on it at all. I was wondering if it was possible to merge the file validation in the 'profile' model where I have the text validation?
Here is the code in my controller
public function action_public_edit()
{
$content = View::factory('profile/public_edit')
->bind('user', $user)
->bind('profile', $profile)
->bind('errors', $errors);
$user = Auth::instance()->get_user();
$profile = $user->profiles;
$this->template->content = $content;
if ($_POST)
{
if ($profile->values($_POST)->check())
{
$picture = Upload::save($_FILES['profile_picture']);
// Resize, sharpen, and save the image
Image::factory($picture)
->resize(100, 100, Image::WIDTH)
->save();
$profile->profile_picture = basename($picture);
$profile->save();
$redirect = "profile/private";
Request::instance()->redirect($redirect);
}
else
{
$errors = $profile->validate()->errors('profile/public_edit');
}
}
}
And the ORM model
protected $_belongs_to = array('user' => array());
protected $_rules = array(
'first_name' => array(
'not_empty' => NULL,
),
'last_name' => array(
'not_empty' => NULL,
),
You don't need to check() if you save() later - save will do the checking and throw ORM_Validation_Exception if validation is not passed. I suggest to create a function in your model for saving - move the lines after check() to this model. In controller you'll only need to write:
if ($this->request->method() === 'POST')
{
$errors = $profile->upload('profile_picture');
if (empty($errors))
{
try
{
$profile->your_save_function();
$this->request->redirect('profile/private');
}
catch (ORM_Validation_Exception $e)
{
$errors = $e->errors('profile');
}
}
}
In your model:
public function your_save_function()
{
// Do your stuff before uploading the picture
// Save the model
$this->save();
}
public function upload($filename)
{
// Set the default upload directory
Upload::$default_directory = 'your_path';
// Validate the file first
$validation = Validation::factory($_FILES)
->rules($filename, array(
array('not_empty'),
array('Upload::not_empty'),
array('Upload::valid'),
array('Upload::type', array(':value', array('your_valid_extensions'))),
array('Upload::size', array(':value', 'your_max_size')),
));
// Validate and upload OK
if ($validation->check())
{
$picture = Upload::save($_FILES[$filename]);
// Resize, sharpen, and save the image
Image::factory($picture)
->resize(100, 100, Image::WIDTH)
->save();
$this->profile_picture = basename($picture);
}
else
{
return $validation->errors('upload');
}
}
Much simpler and cleaner code.

Drupal Pressflow problem with hook_block

i'm having troubles with implementing the hook_block hook in a clean Pressflow installation. For some reason it always outputs ArrayArray for all my blocks. The reason for this is that the $info variable in the theme function is set to:
["block"]=>
array(7) {
["function"]=>
string(10) "fwtb_block"
["include files"]=>
array(0) {
}
["type"]=>
string(12) "theme_engine"
["theme path"]=>
string(21) "sites/all/themes/fwtb"
["arguments"]=>
array(1) {
["block"]=>
NULL
}
["theme paths"]=>
array(2) {
[0]=>
string(14) "modules/system"
[1]=>
string(21) "sites/all/themes/fwtb"
}
["preprocess functions"]=>
array(2) {
[0]=>
string(19) "template_preprocess"
[1]=>
string(25) "template_preprocess_block"
}
}
as you can see this is overwritten with my custom hook_block method. So now it thinks blocks should be rendered using my fwtb_block method which returns an array containing the subject and the content. That's why it prints ArrayArray. Any idea what is going wrong here?
This is my hook_block implementation:
function fwtb_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks['sidebar_description'] = array(
'info' => t('Sidebar description'),
'cache' => BLOCK_CACHE_GLOBAL,
'status' => TRUE,
'region' => 'left',
'visibility' => 0,
'custom' => FALSE
);
return $blocks;
case 'configure':
$form = array();
return $form;
case 'save':
return;
case 'view': default:
switch ($delta) {
case 'sidebar_description':
$block['subject'] = t('block_subject');
$block['content'] = t('block_description');
break;
}
return $block;
}
}
kind regards,
Daan
After taking a fresh look to my setup i saw what the problem was. I had a theme and a module with the same name. This caused some conflicts :/

Kohana ORM Model not loading

In the following code, the "add" action works as expected, but the remove action throws an error citing that Kohana "Cannot delete favorites model because it is not loaded."
Any ideas?
if ($_GET['action'] == 'add')
{
$favorites = ORM::factory('favorites');
$favorites->question_id = $_GET['question_id'];
$favorites->user_id = Kohana_Facebook::instance()->user_id();
$favorites->save();
}
elseif ($_GET['action'] == 'remove')
{
$favorites = ORM::factory('favorites')
->where('user_id', '=', $facebook->user_id())
->and_where('question_id', '=', $_GET['question_id'])
->find();
$favorites->delete();
}
A var_dump($favorites) show this:
object(Model_Favorites)#24 (31) {
["_table_name:protected"]=> string(9) "favorites"
["_has_one:protected"]=> array(0) { }
["_belongs_to:protected"]=> array(0) { }
["_has_many:protected"]=> array(0) { }
["_load_with:protected"]=> array(0) { }
["_validation:protected"]=> NULL
["_object:protected"]=> array(2) { ["user_id"]=> string(8) "60717257" ["question_id"]=> string(1) "2" }
["_changed:protected"]=> array(0) { }
["_related:protected"]=> array(0) { }
["_valid:protected"]=> bool(false)
["_loaded:protected"]=> bool(false)
["_saved:protected"]=> bool(false)
["_sorting:protected"]=> NULL
["_foreign_key_suffix:protected"]=> string(3) "_id"
["_object_name:protected"]=> string(9) "favorites"
["_object_plural:protected"]=> string(11) "favoriteses"
["_table_columns:protected"]=> array(2) { ["user_id"]=> array(13) { ["type"]=> string(3) "int" ["min"]=> string(11) "-2147483648" ["max"]=> string(10) "2147483647" ["column_name"]=> string(7) "user_id"
["column_default"]=> NULL
["data_type"]=> string(3) "int"
["is_nullable"]=> bool(false)
["ordinal_position"]=> int(1)
["display"]=> string(2) "11"
["comment"]=> string(0) ""
["extra"]=> string(0) ""
["key"]=> string(3) "PRI"
["privileges"]=> string(31) "select,insert,update,references" }
["question_id"]=> array(13) { ["type"]=> string(3) "int" ["min"]=> string(11) "-2147483648" ["max"]=> string(10) "2147483647" ["column_name"]=> string(11) "question_id" ["column_default"]=> NULL ["data_type"]=> string(3) "int" ["is_nullable"]=> bool(false) ["ordinal_position"]=> int(2) ["display"]=> string(2) "11" ["comment"]=> string(0) "" ["extra"]=> string(0) "" ["key"]=> string(3) "PRI" ["privileges"]=> string(31) "select,insert,update,references" } } ["_updated_column:protected"]=> NULL ["_created_column:protected"]=> NULL ["_primary_key:protected"]=> string(2) "id" ["_primary_key_value:protected"]=> NULL ["_table_names_plural:protected"]=> bool(true) ["_reload_on_wakeup:protected"]=> bool(true) ["_db:protected"]=> object(Database_MySQL)#23 (6) { ["_connection_id:protected"]=> string(40) "f9eb0f07846bef120d6d8414616f81f993f5306a" ["_identifier:protected"]=> string(1) "`" ["last_query"]=> string(98) "SELECT `favorites`.* FROM `favorites` WHERE `user_id` = '60717257' AND `question_id` = '2' LIMIT 1" ["_instance:protected"]=> string(7) "default" ["_connection:protected"]=> resource(73) of type (mysql link) ["_config:protected"]=> array(6) { ["type"]=> string(5) "mysql" ["connection"]=> array(3) { ["hostname"]=> string(9) "localhost" ["database"]=> string(17) "davekiss_dumbpoll" ["persistent"]=> bool(false) } ["table_prefix"]=> string(0) "" ["charset"]=> string(4) "utf8" ["caching"]=> bool(false) ["profiling"]=> bool(true) } }
["_db_group:protected"]=> NULL
["_db_applied:protected"]=> array(0) { }
["_db_pending:protected"]=> array(0) { }
["_db_reset:protected"]=> bool(true)
["_db_builder:protected"]=> NULL
["_with_applied:protected"]=> array(0) { }
["_cast_data:protected"]=> array(0) { } }
Yes, it is not loaded in your code.
You need to add find() before your delete()
UPD:
As I can see - it is just a relation tables without single PK field (id)
You could delete row with something like:
DB::delete('favorites')->where('user_id', '=', $facebook->user_id())
->and_where('question_id', '=', $_GET['question_id'])
->execute(Database::instance());
Or you could use remove() method (since seems like you're using kohana ORM relations)
Face same issue and fixed with the solution
add code like
protected $_primary_key = 'your tables primary key';
I have the same issue after loading my codes with ->where() and ->find()
Just make sure that the
protected $_primary_key = 'id';
is defined at the model.

Resources