How to get Attributes of a associated child product(saleable) in magento2 - configurable-product

As shown in below image a configurable product has only one associated product that is in stock. I want to get only those attributes of this simple product from which its associated with parent product.
I am not sure it is correct whatever I tried is below-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load(6); // 6 is product id of configurable product.
$_children = $product->getTypeInstance()->getUsedProducts($product);
foreach ($_children as $child){
foreach ($child->getAttributes() as $attribute) {
echo $attrCode = $attribute->getAttributeCode();
}
}
this $attrcode prints all attributes whether want to get only super attributes as shown in above image.

Related

Get the names of a dynamic product group with a subscriber in Shopware 6.1

how can I get the names of the dynamic product groups of a product?
Especially the names of that groups. The names are in the table 'product_stream_translation'.
I have a subscriber and have added this Criteria. When I am doing it like this:
$criteria->addFilter(new EqualsFilter('id', $id));
$criteria->addAssociation('streams');
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
I just got back an empty streamEntity.
#streams: Shopware\Core\Content\ProductStream\ProductStreamCollection {#11805 ▼
#elements: []
#extensions: []
}
When I am doing it like this:
$criteria->addFilter(new EqualsFilter('productId', $id));
$dynamicProductGroups = $this->productStreamMappingRepository->searchIds($criteria, $context);
I just got back the Id I put in:
product_stream_mapping
I wonder how I will get the name of the dynamic product group.
With a query I can get all the assign 'product_stream_id's from the table 'product_stream_mapping' like this:
SELECT * FROM product_stream_mapping WHERE product_id =0x000000000000000000123b313030524b
And then get the associated name of the dynamic product group. With is like this:
SELECT psm.product_id, psm.product_stream_id, p.product_number, pst.name
FROM product_stream_mapping psm
JOIN product_stream_translation pst ON pst.product_stream_id = psm.product_stream_id
JOIN product p ON p.id = psm.product_id
WHERE psm.product_id = 0x000000000000000000123b313030524b
How can I get it in the Subscriber?
Do I have to use criteria or do I have to user a repository?
This line is wrong:
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
It won't return dynamic product groups but a product collection. To get a product stream collection (dynamic product groups) replace it with:
/** #var ProductEntity $product */
$product = $this->productRepository->search($criteria, $context)->first();
$dynamicProductGroups = $product->getStreams();
Then you can read the names of the streams with:
$names = array_values(
$dynamicProductGroups->map(fn (ProductStreamEntity $productStream) => $productStream->getName())
);

MappingEntityClassesException - Mapping definition neither have entities nor collection

I have written a product import which imports some product data via CLI command.
When i run it multiple times the defined product property (color) does not get overwritten but adden.
Example
First run - color: red
Second run: - color: green
The importer sums the properties up, So the color has then multiple values - red AND green.
I want to solve this by deleting the product properties before the importer runs by this code:
$items = $this->productPropertyRepository->search((new Criteria())->addFilter(new EqualsAnyFilter('productId',
$productIds)), Context::createDefaultContext());
$ids = [];
foreach ($items as $item) {
$ids[] = ['productId' => $item['product_id'], 'productVersionId' => $item['product_version_id']];
}
if ($ids) {
$this->productPropertyRepository->delete($ids, Context::createDefaultContext());
}
But this does not work because there is no ProductPropertyEntity class in Shopware 6.
I get an exception when execution the first line.
[Shopware\Core\Framework\DataAbstractionLayer\Exception\MappingEntityClassesException]
Mapping definition neither have entities nor collection.
Whats the best way to avoid keeping orphaned data in this case?

How to get source list types of particular list/record field?

Here is I have two entity custom fields with list/record type,
custom_dev_j15 entity field has a custom source list (eg: one, two, three, four, etc)
custom_qa_v93 entity field has a standard source list as an object (eg: customer )
I've two vendor entity custom fields as stated in screenshots of question,
custentity473 --> customer is selected as list source
custentity474 --> custom_dev_j15_m_list as selected as list source ( which is custom list)
Here is snippet that i used to get the options of these fields,
// Snippet
var fieldDetails = {};
var record = nlapiCreateRecord("Vendor");
var field = record.getField("custentity473");
var selectoptions = field.getSelectOptions();
for ( var i in selectOptions) {
var Option = {
id : selectOptions[i].getId(),
label : selectOptions[i].getText()
}
Options.push(Option);
}
fieldDetail["options"] = Options;
But my need is to get source list information like name of the list source (customer or custom_dev_j15_m_list) via suitescript
any idea on how to get this information?
Thanks in advance
I'm not sure I understand this question for what you're trying to do.
In NetSuite almost always, you accommodate to the source list types because you know that's the type, and if you need something else (e.g. a selection which is a combination/or custom selection you'll use a scripted field)
Perhaps you can expand on your use case, and then we can help you further?

The Requested Resources was not found or you do not have sufficient permissions to view it

Dynamics crm when retrieving value and updating it into another entity it showing like
The Requested Resources was not found or you do not have sufficient permissions to view it
i specified update ids like
enobj.Id=(Guid)context.OutputParameters["id"];
message:create
service :update on another entity
this is my code:
Query Expression query = new Query Expression();
query.EntityName = en.LogicalName;
query.ColumnSet = new ColumnSet("new_amount");
var x = service.RetrieveMultiple(query);
Entity enobj = new Entity("new_product");
int i = 0;
foreach (var item in x.Entities)
{
i = i + (int)item.Attributes["new_amount"];
enobj.Attributes["new_grandtotal"] = i;
}
enobj.Id=(Guid)context.OutputParameters["id"];
// en.Id = enobj.Id;
enobj.Id = en.Id;
service.Update(enobj);
message:create
service :update
i have two entites product and productlineitems
in productlineitems iam creating a record with the field amount 50 after creating that value.iam updating on product entity.
again i create productlineitem 2 with the value some 90.iam adding 50+90 =140
again lineitem 3 with the value. iam taking that on product entity
message:create --- productlineitems
service :update --- product
I think you are trying to update Product with Product Line Id. Try the following:
Replace
enobj.Id = en.Id;
With
// set the field name (key) based on what you got in system
enobj.Id = (Guid)en["new_productid"];
Also, Calling Context is set to Current user. So make sure that user have permissions to update Product.

Cognos 8 SDK: How to get Subgroups of a Group?

I try to get the Subgroup of a Group in the standard Cognos Namespace.
Quering the Contentstore to get ALL groups works fine.
The standard methodes to get "members" of objects return the users or only the "root" group (the group I want the subgroups of). Nothing else....
Am I doing something wrong or is it just "not to be done" ?
I found a way of doing it:
Assuming you have the searchpath for the group you want the subgroups of.
Query the contentstore for it with following PropEnum:
PropEnum[] props = {
PropEnum.defaultName,
PropEnum.searchPath,
PropEnum.members };
As result you get a BaseClass[] object (with only one element though...).
Import com.cognos.developer.schemas.bibus._3.Group <--- this is part of the Cognos SDK libraries and
now you can cast the object[0] to Group.
object.getMembers().getValue()[] is an array of all members INCLUDING groups, roles, accounts.
In java it looks like this (query for the object already done):
Group group = (Group)object[0];
BaseClass obj = null;
for (int i = 0; i < group.getMembers().getValue().length; i++){
obj = group.getMembers().getValue();
System.out.println(obj.getSearchPath().getValue());
}

Resources