nosto / nosto-php-sdk Goto Github PK
View Code? Open in Web Editor NEWNosto php-sdk - https://packagist.org/packages/nosto/php-sdk
License: BSD 3-Clause "New" or "Revised" License
Nosto php-sdk - https://packagist.org/packages/nosto/php-sdk
License: BSD 3-Clause "New" or "Revised" License
Tests must follow PSR-0 / PSR-4 namespaces and class names
In order for platforms to push the thumbnail-URL from the platform itself, we should add this to the product model. This would be great when we begin adding support for Fastly on Magento and allowing retailers to serve thumbnails from their own CDN instead of us.
Add test cases for
The new fields that are available in the tagging should be available in the SDK as well.
If we can generate all the markup programmatically, then we won't need any templates in any of the extensions. Below is a snippet of code that uses a patches serializer (skips the json_encode
) and passes the returned array object to this serializer.
$x = \Nosto\Helper\SerializationHelper::serialize($product);
echo self::toMarkup($x);
private static function toMarkup($object, $indent = 0) {
$markup = '';
$spaces = str_repeat(' ', $indent);
foreach ($object as $key => $value) {
if (is_array($value)) {
$output = self::toMarkup($value, $indent + 2);
if (!empty($output)) {
$span = sprintf("<span class=\"%s\">", $key);
$endx = "</span>";
$markup .= $spaces . $span . PHP_EOL . $output . $spaces . $endx . PHP_EOL;
}
} else {
if (!empty($value)) {
$span = sprintf("<span class=\"%s\">", $key);
$endx = "</span>";
$markup = $markup . $spaces . $span . $value . $endx . PHP_EOL;
}
}
}
return $markup;
}
Here's some sample output when serializing a product:
<span class="url">http://mridang.dev.nos.to:8890/magento/210/default/breathe-easy-tank.html</span>
<span class="product_id">1817</span>
<span class="name">Breathe-Easy Tank</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="price_currency_code">EUR</span>
<span class="availability">InStock</span>
<span class="categories">
<span class="0">/Women/Tops/Bras & Tanks</span>
<span class="1">/Promotions/Women Sale</span>
<span class="2">/Collections/Erin Recommends</span>
</span>
<span class="description"><p>The Breathe Easy Tank is so soft, lightweight, and comfortable, you won't even know it's there -- until its high-tech Cocona® fabric starts wicking sweat away from your body to help you stay dry and focused. Layer it over your favorite sports bra and get moving.</p>
<p>• Machine wash/dry.<br />• Cocona® fabric.</p></span>
<span class="variation_id">EUR</span>
<span class="inventory_level">1500</span>
<span class="review_count">2</span>
<span class="rating_value">3.5</span>
<span class="alternate_image_urls">
<span class="0">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_back.jpg</span>
</span>
<span class="skus">
<span class="0">
<span class="id">1802</span>
<span class="name">Breathe-Easy Tank-XS-Purple</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-purple_main.jpg</span>
<span class="gtin">WT09-XS-Purple</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Purple</span>
<span class="size">XS</span>
</span>
</span>
<span class="1">
<span class="id">1803</span>
<span class="name">Breathe-Easy Tank-XS-White</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="gtin">WT09-XS-White</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">White</span>
<span class="size">XS</span>
</span>
</span>
<span class="2">
<span class="id">1804</span>
<span class="name">Breathe-Easy Tank-XS-Yellow</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-yellow_main.jpg</span>
<span class="gtin">WT09-XS-Yellow</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Yellow</span>
<span class="size">XS</span>
</span>
</span>
<span class="3">
<span class="id">1805</span>
<span class="name">Breathe-Easy Tank-S-Purple</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-purple_main.jpg</span>
<span class="gtin">WT09-S-Purple</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Purple</span>
<span class="size">S</span>
</span>
</span>
<span class="4">
<span class="id">1806</span>
<span class="name">Breathe-Easy Tank-S-White</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="gtin">WT09-S-White</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">White</span>
<span class="size">S</span>
</span>
</span>
<span class="5">
<span class="id">1807</span>
<span class="name">Breathe-Easy Tank-S-Yellow</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-yellow_main.jpg</span>
<span class="gtin">WT09-S-Yellow</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Yellow</span>
<span class="size">S</span>
</span>
</span>
<span class="6">
<span class="id">1808</span>
<span class="name">Breathe-Easy Tank-M-Purple</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-purple_main.jpg</span>
<span class="gtin">WT09-M-Purple</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Purple</span>
<span class="size">M</span>
</span>
</span>
<span class="7">
<span class="id">1809</span>
<span class="name">Breathe-Easy Tank-M-White</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="gtin">WT09-M-White</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">White</span>
<span class="size">M</span>
</span>
</span>
<span class="8">
<span class="id">1810</span>
<span class="name">Breathe-Easy Tank-M-Yellow</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-yellow_main.jpg</span>
<span class="gtin">WT09-M-Yellow</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Yellow</span>
<span class="size">M</span>
</span>
</span>
<span class="9">
<span class="id">1811</span>
<span class="name">Breathe-Easy Tank-L-Purple</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-purple_main.jpg</span>
<span class="gtin">WT09-L-Purple</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Purple</span>
<span class="size">L</span>
</span>
</span>
<span class="10">
<span class="id">1812</span>
<span class="name">Breathe-Easy Tank-L-White</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="gtin">WT09-L-White</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">White</span>
<span class="size">L</span>
</span>
</span>
<span class="11">
<span class="id">1813</span>
<span class="name">Breathe-Easy Tank-L-Yellow</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-yellow_main.jpg</span>
<span class="gtin">WT09-L-Yellow</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Yellow</span>
<span class="size">L</span>
</span>
</span>
<span class="12">
<span class="id">1814</span>
<span class="name">Breathe-Easy Tank-XL-Purple</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-purple_main.jpg</span>
<span class="gtin">WT09-XL-Purple</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Purple</span>
<span class="size">XL</span>
</span>
</span>
<span class="13">
<span class="id">1815</span>
<span class="name">Breathe-Easy Tank-XL-White</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-white_main.jpg</span>
<span class="gtin">WT09-XL-White</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">White</span>
<span class="size">XL</span>
</span>
</span>
<span class="14">
<span class="id">1816</span>
<span class="name">Breathe-Easy Tank-XL-Yellow</span>
<span class="price">34</span>
<span class="list_price">34</span>
<span class="image_url">http://mridang.dev.nos.to:8890/magento/210/pub/media/catalog/product/w/t/wt09-yellow_main.jpg</span>
<span class="gtin">WT09-XL-Yellow</span>
<span class="availability">InStock</span>
<span class="custom_attributes">
<span class="color">Yellow</span>
<span class="size">XL</span>
</span>
</span>
</span>
With dockerised / virtualised environments & running Nosto locally it must be possible to separate the endpoints called from virtual machine to host and from browser to host.
For example NOSTO_WEB_HOOK_BASE_URL
is used for loading the installation iframe in browser and to get the SSO url.
In case there are data in result
field in Nosto API response try to parse the errors from that field. https://github.com/Nosto/nosto-php-sdk/blob/develop/src/Nosto.php#L110
Currently if the sso authentication fails, the error message and status code are discarded by sdk. That makes it difficult to debug the sso issue.
Iframe URL building
Current min supported PHP is 5.5.
When forking the repository you end up with just lsolesen/php-sdk. That makes it a little hard to know what repository it actually is without digging into the code.
Set the connect timeout to 5 seconds
The following headers should be sent with every API call for debugging purposes
The SDK is missing all the default page-type constants and these could be added to the SDK
const PAGE_TYPE_FRONT_PAGE = 'front';
const PAGE_TYPE_CART = 'cart';
const PAGE_TYPE_PRODUCT = 'product';
const PAGE_TYPE_CATEGORY = 'category';
const PAGE_TYPE_SEARCH = 'search';
const PAGE_TYPE_NOTFOUND = 'notfound';
const PAGE_TYPE_ORDER = 'order';
DateTimeInterface was introduced in PHP 5.5. and we want to keep the SDK compatible with 5.4.
Nosto\Object\Cart::getUnitPrice
vs. Nosto\Object\Cart::setPrice
- should be Nosto\Object\Cart::setUnitPrice
Static method that takes string (Nosto cookie id) as a parameter
The account object is a superset of the information of the settings object. Currently when updating the settings to Nosto, we create a NostoAccount
object and then only use a small subset of the fields when serializing to JSON. This would be a lot cleaner if a had a NostoSettings
object and the NostoAccount
object would extend it.
Would you accept a pull request to install phpseclib using composer instead?
Example: Do a POST
to the /platform/module/uninstall
endpoint with the API_MODULE
.
Oauth trait needs to have abstract method for checking if account is already installed
UpsertProduct::upsert()
is using:
$response = $request->post($this->collection);
to send the Products.
The ApiRequest::post()
is using:
return $this->postRaw(SerializationHelper::serialize($content));
I suggest a AbstractCollection::toJson()
method, which is calling the AbstractObject::toJson()
method.
BONUS: Automatic UTF-8 Conversion if necessary ;-)
All the extensions using the connect.nosto.com
constant have it defined in their own codebase, why not add that constant here so when you need the embed script constant, you could just invoke a method like this
function getConnectURL()
{
return self::getEnvVariable('NOSTO_SERVER_URL', self::DEFAULT_SERVER_ADDRESS);
}
Here are some examples:
https://github.com/Nosto/nosto-magento/blob/develop/app/code/community/Nosto/Tagging/Block/Embed.php#L39
https://github.com/Nosto/nosto-magento2/blob/develop/Block/Embed.php#L60
Add possibility to send customer data over the API. Use the token API_EMAIL for authentication.
Currently we only have InStock and OutOfStock. Should have Invisible & other missing ones
The markup for the simple objects should be only one html tag. For example page type must be
<span class="nosto_page_type" style="display:none">front</span>
NOT
<span class="nosto_page_type" style="display:none">
<span class="page_type">front</span>
</span>
ToDos
setValue
into MarkupableString
MarkupableString
when implementing Category, PageType and SearchTerm objectsKeys with special chars like "Größe" end up like "gr":
<span class="custom_fields">
<span class="gr">41</span>
<span class="farbe">Weiß</span>
</span>
toJson()
/ API works fine!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.