You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please use the following script to test your code :
<?phpnamespaceShoppingFeed\Feed;
require_once__DIR__ . '/vendor/autoload.php';
$generator = newProductGenerator('php://output', 'json');
// in order for the generator to work, we need at least one mapper// see the documentation for more details$generator->addMapper(function(array$item, Product\Product$product) {
$product
->setName($item['title'])
->setReference($item['sku'])
->setPrice($item['price'])
->setQuantity($item['quantity']);
});
// hardcode the data of your products here (or you can import it from an external file, if you wish)$items[0] = ['sku' => 1, 'title' => 'Product 1', 'price' => 5.99, 'quantity' => 3];
$items[1] = ['sku' => 2, 'title' => 'Product 2', 'price' => 12.99, 'quantity' => 6];
// now generate the feed, which will output the file// in the specified format and at the specified location$generator->write($items);
If you place the above code, at the root of the project, in a file named test.php then, in the CLI you can position yourself at the root of the project as well and launch the following command :
Please start by reading the documentation of the project, that explains the context.
What needs to be done
We want to allow the feed generator to output the feed in JSON format. The library, as it currently exists, already supports :
In order to add the new JSON format, we need to
In order to keep things simple, the output is expected to contain 1 json-encoded product per line.
So, with an input product like this :
We would have an output JSON file that looks like this :
With multiple products, the file will look like this :
How to test your code
Please use the following script to test your code :
If you place the above code, at the root of the project, in a file named
test.php
then, in the CLI you can position yourself at the root of the project as well and launch the following command :(so, just to be clear, the test command is just
php./test.php
)This should output at the specified location (
php://output
), the file, in the required format.You can already test that the project works as expected, by replacing
json
withxml
in this lineWithout any new code, this should already output the XML file. What we want is that, when using the new
json
format, we obtain the desired result.How to propose a solution for this issue
In order to propose a solution for this issue, you can :
More details here and here.
The text was updated successfully, but these errors were encountered: