Can someone explain the "status" and "visibility" fields on each product in the list obtained through Magento 2 REST API?
When calling the /products endpoint a list of products are returned but I'm having issues understanding the different fields. Sure, some fields are self explanatory like sku, name, etc. but others like status and visibility aren't.
Looking at the documentation, I can see both values are integers but no further explanation as to what values are allowed and what they actually mean? That makes the documentation kinda useless since I can probably just guess the type looking at the often related GET-request.
Documentation found here:
https://magento.redoc.ly/2.4.1-admin/tag/products#operation/catalogProductRepositoryV1GetListGet
I have no former experience with Magento :D
Maybe there is a reference list somewhere that explains each field?
Hope someone can help me!
If you have a look at four constants at the top of the class Visibility: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Model/Product/Visibility.php
const VISIBILITY_NOT_VISIBLE = 1;
const VISIBILITY_IN_CATALOG = 2;
const VISIBILITY_IN_SEARCH = 3;
const VISIBILITY_BOTH = 4;
you will see what values are allowed and what they mean: IN_CATALOG means that the product will not be taken into account when user is using search, while IN_SEARCH means that the product will not show on product page and category page, but will be returned in search results, the other two (NOT_VISIBLE, BOTH) are a combination of these two both being false or both being true.
Now about status - have a look here: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Model/Product/Attribute/Source/Status.php
Again, you have constants which are used to store the status:
/**
* Product Status values
*/
const STATUS_ENABLED = 1;
const STATUS_DISABLED = 2;
I hope this answers your question :)
Related
Let's say that we are displaying books grouped by author. The GET request would look as follows:
// The server parses this like: author=['tolkien', 'shakespeare']
const data = useSWR('example.com/books?author[]=tolkien&author[]=shakespeare')
After having fetched this, the user now also wants to see the books written by another author. The easy thing to do here would be to fire off the following request:
const data = useSWR('example.com/books?author[]=tolkien&author[]=shakespeare&author[]=rowling')
Here data includes all the books by Tolkien, Shakespeare and Rowling.
But we already have the books by Tolkien and Shakespeare, so fetching these again would be a waste. Instead it would make more sense to call the following:
const data = useSWR('example.com/books?author[]=rowling')
But here the books by Tolkien and Shakespeare are not included in data.
Is it possible to call the following:
const data = useSWR('example.com/books?author[]=tolkien&author[]=shakespeare&author[]=rowling')
Where only the books by Rowling are actually fetched and are added to the 'example.com/books?author[]=tolkien&author[]=shakespeare&author[]=rowling' key?
Similarly, let's say that we want to show only the books by Tolkien:
const data = useSWR('example.com/books?author[]=tolkien')
But calling the above would refetch Tolkien's books, even though we already have them...
What is the correct way to handle this scenario with SWR?
Lets say I need to have some logic in this use case scenario. The user is on the WIX Online Store's Product page for a particular product and clicks on QTY to order more units of the product. The logic to add is to check against the inventory at that moment and send a Twilio SMS message to the Store owner as a warning(this use case is somewhat contrived).
The thing is I dont seem to see any examples on WIX online training that shows how the Corvid Database can be connected to existing WIX Online stores which have Products and Collections already defined (which I assume is kept in some database). How does the Corvid Database and the Online Store Products/Collections map and how is it done and how can Corvid js code access that ? By the way, the Corvid uses the term "Collections" which does not seem related to Product Collections which must be a source of confusion for many.
You can access your Wix-Stores products collection using the wix-data module.
import wixStoresBackend from 'wix-stores-backend'; // Not needed here but try in the editor
import wixData from 'wix-data';
const WIX_STORES_PRODUCT_TABLE = 'Stores/Products';
const getProducts = () => {
return wixData.query(WIX_STORES_PRODUCT_TABLE)
.find()
.then((data) => {
let wixInventory = data.items;
return wixInventory
}
If you start there you will see all the items in your Wix-Stores. You can further query the database/collection by narrowing down the query. There are some good starter examples in the Corvid documentation for query here.
Just as a note - Because the Wix-Stores collections are read only you can query them but you can't write to them. If you have a look at wixStoresBackend within the Corvid editor the code completion there shows that you can update some parameters of a product however, you will need to modify a product's item if you want to adjust things like quantity.
Please check my previous question
EMBER JS - Fetch associated model data from back-end only when required
Related to the above question I need help on API formation in ruby on rails(JSON format: jsonapi.org)
how to form the API for sideloading only students.records and link with data already available in ember-data store (school and students)
based on the comments in the other question, I think you're wanting something like
GET /api/students?include=records
But you need that filtered to a school, which is where application-specific code can come in, as { json:api } does not dictate how filtering should happen
but, I've used this: https://github.com/activerecord-hackery/ransack with much success
So, your new query would be something like:
GET /api/students?include=records&q[school_id_eq]=1
to get all students and their records for the school with id 1
and then to make this query in ember:
store.query('student', {
include: 'records',
q: {
['school_id_eq']: 1
}
});
hope this helps
I have 4 stores for a stack overflow example:
SearchQuestionsStore
RecentQuestionsStore
UserQuestionsStore
CurrentQuestionStore
Each of the first 3 stores have an #observable questionsList = [];
A question may be accessed from any of those 3 stores, when the questionsList is populated with questions. An #observable currentQuestion holds the current selected question in the CurrentQuestionStore
If a user upvotes the currentQuestion, we simply increment the current question's count using CurrentQuestionStore.currentQuestion.upvotes++, but this does not reflect the latest upvote count in the other 3 stores.
The issue is that the question may or may not exist in any of the other 3 stores questionlists, so I was wondering what would be the best way to approach this using MobX? So we can update the latest count for this questionId = 1 across all stores if they exist. The same situation occurs when changing the title, answers count, or any other attribute on the currentQuestion
What's the best way to reflect the changes of any attribute change across the stores at once?
With MobX, you should never have two copies of the same thing. The same question object should be referenced from all stores. To achieve this, it will depend on how your code is setup to load and store the questions.
One way I suggest doing this is to have an AllQuestionsStore that contains all questions in a map:
class AllQuestionsStore {
#observable questionsMap = asMap({});
#action addQuestion(question) {
const map = this.questionsMap;
if (map.has(question.id)) {
extendObservable(map.get(question.id), question);
} else {
map.set(question.id, question);
}
return map.get(question.id);
}
}
Then you whenever you create or load a question, you should add it to this store. For example, when you load user questions from the server:
function loadedUserQuestions(userQuestions) {
const questions = userQuestions.map(AllQuestionsStore.addQuestion, AllQuestionsStore);
UserQuestionsStore.questionsList = questions;
}
And if you want to set the current question:
CurrentQuestionStore.currentQuestion = AllQuestionsStore.addQuestion(question);
Now it's guaranteed that a question has only one instance, so if you update it, other stores will never be out of date.
I'd like to use the published field on products that's documented here in the Shopify API:
Hide a published product by changing the published attribute to false
I can change the flag on any product, but I have not figured out yet how to get the published field back from the API. It's not listed the list of fields of the Product
object.
You can set the published_at field of individual products directly as described here:
product.published_at = nil; product.save # hides product
product.published_at = Time.now.utc; product.save # makes product visible
You can also hide a collection of products by setting published to false as described here:
collection = ShopifyAPI::CustomCollection.find(params[:collection_id])
collection.published = false
collection.save
UPDATED
Now that I understand the question better, here is the answer you want. You can't really get the 'published' value back as there isn't really a published attribute on a product. You can, however, check the published_at field and check if it's nil (not published). Setting published = false apparently sets this to nil for you.
You can get a published status very easily. It is in the API as an endpoint: published_status
This returns published, unpublished and any.
https://help.shopify.com/api/reference/product
Usage:
To get an array of all published products:
GET /admin/products.json?publish_status=published
To get an array of all unpublished products:
GET /admin/products.json?publish_status=unpublished
Then iterate the array and find the product you want. Some sample php that does this:
function isPublished($shopify, $myprodid) {
$products = $shopify('GET /admin/products.json?publish_status=unpublished');
foreach($products as $prod) {
if($prod['id'] == $myprodid)
return false;
}
return true
}
Iterating the unpublished should be quick unless you have a large amount of unpublished products. Then swap the test.