Magento Go product_attribute.addOption - magento

I am using SOAP v1 of the Magento API, I am trying to add an option to an attribute.
My Code:
$attributeCode = "feltColor";
$optionToAdd = array(
"Label" => array(
array(
"store_id" => 1,
"value" => "Green"
)
),
"order" => 0,
"is_default" => 0
);
But I keep getting the following error:
Fatal error: Uncaught SoapFault exception: [108] Default option value is not defined
Can't get it to work...any suggestions?

You need to specify a label for store_id = 0 (instead of or in addition to defining one for store_id = 1).
This is from the docs for product_attribute.create, but also holds true for product_attribute.addOption:
Notes: The "label" value for the "store_id" value set to 0 must be
specified. An attribute cannot be created without specifying the label
for store_id=0.
If you define a label for store_id = 0, that is the default, so you don't need to define it for other store views unless you want to override the default:
$attributeCode = "feltColor";
$optionToAdd = array(
"Label" => array(
array(
"store_id" => 0,
"value" => "Green"
)
),
"order" => 0,
"is_default" => 0
);

Related

Laravel : undefined index cap tcpdf

$lineStyle = array(
'color' => $tag['fgcolor'],
'cap' => $tag['style']['cap'] ,
'join' => $tag['style']['join'] ,
'dash' => $tag['style']['dash'] ,
'phase' => $tag['style']['phase'] ,
);
$tag['style']['cap'] undefined index: cap
The error is self explanatory, there is no index cap in the array $tag['style'].
If you dd($tag['style']); you should be able to see it yourself.
If you are using PHP 7.0+, you use the following syntax to set a "default" value in case an index doesn't exist:
$lineStyle = array(
'color' => $tag['fgcolor'],
'cap' => $tag['style']['cap'] ?? "something" ,
'join' => $tag['style']['join'] ,
'dash' => $tag['style']['dash'] ,
'phase' => $tag['style']['phase'] ,
);
The ?? is the null coalescing operator and it is documented here: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
It basically allows you to set a default value in case something doesn't exist.
You can use this code below in vendor/tecnickcom/tcpdf/tcpdf.php:
$lineStyle = array('color' => $tag['fgcolor'] ?? "",'cap' => $tag['style']['cap'] ?? "",'join' => $tag['style']['join'] ?? "",'dash' => $tag['style']['dash'] ?? "",'phase' => $tag['style']['phase'] ?? "",
);

TYPO3 Extbase repository constraint with MM relation

I build an extension with a table for items, these can be either projects or objects, a project being a container for multple objects.
To distinguish, a checkbox is used to label an item as project, and when this checkbox is ticked an optional field is displayed.
This field is a relation (m:n) from the project to the objects it contains (same table). The Multiple side by side select displayes only non projects and objects not yet assigned to a project through foreign_table_where.
This field has following TCA:
'objects' => [
'displayCond' => 'FIELD:isproject:=:1',
'exclude' => 0,
'label' => $ll . 'tx_myext_domain_model_item.objects',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_myext_domain_model_item',
'foreign_table_where' => 'AND isproject = 0 AND tx_myext_domain_model_item.uid NOT IN (SELECT uid_foreign FROM tx_myext_item_object_mm WHERE uid_local != ###THIS_UID###)',
'MM' => 'tx_myext_item_object_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0
],
],
with my plugin I give the option (trough a flexform) to select to display only objects, only projects or both, done with following code in the repository:
public function findList($entryInclude = 'objects_only') {
/** #var \TYPO3\CMS\Extbase\Persistence\Generic\Query $query */
$query = $this->createQuery();
switch ($entryInclude) {
case 'projects_objects':
$foreign_uids = $this->createQuery()
->statement('SELECT uid_foreign FROM tx_myext_item_object_mm')
->execute();
$constraints = [
$query->equals('isproject', 1),
$query->logicalNot($query->in('uid', $foreign_uids))
];
break;
case 'projects_only':
$constraints = $query->equals('isproject', 1);
break;
default:
$constraints = $query->equals('isproject', 0);
break;
}
$query->matching($query->logicalAnd($constraints));
return $query->execute();
}
the effort to build an array of all uid_foreign found in the tx_myext_item_object_mm table causes an error ...
This is, in my oppinion, a case for a custom query. The following should give you the objects not referenced to from within your mm-table:
$query = $this->createQuery();
$query->statement('
SELECT *
FROM tx_myext_domain_model_item
WHERE uid NOT IN(
SELECT foreign_uid FROM tx_myext_item_object_mm
)
');
$query->execute();

Magento custom attribute label

I have created a custom attribute for the billing address on my magneto backed (Sales-> order -> billing address). However, the attribute input field is showing on the backend without the label. like this
My backend array for this label is like this.
$attributes = array(
'buildingnumber' => array(
'label' => 'Building Number',
'backend_type' => 'varchar',
'frontend_input' => 'text',
'is_user_defined' => 1,
'is_system' => 0,
'is_visible' => 1,
'is_required' => 1,
'multiline_count' => 0,
'validate_rules' => array(
'max_text_length' => 255,
'min_text_length' => 1
),
),
);
Please let me know how to add a label for my field.
Open eav_attribute table and search for buildingnumber attribute_code and check field frontend_label

Distinguish between magento product attributes and custom created product attribute

I have my custom product attributes in magento.i want to set the product description dynamically.is their any way in magento so that we can find the attribute is custom created by us not by default magento.
i had searched.but not got any success.
Please Help.
Thanks in Advance.
Let's say you have an attribute with code some_code.
Here is how you can check if it's a system attribute or if it's a custom one.
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'some_code');
if ($attribute->getIsUserDefined()) {
//then you created the attribute
}
else {
//then it's a system attribute
}
Use the magento soap/rest api for creating a custom attribute for Product and update with values as well,
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
echo "<pre>";
// Create new attribute
$attributeToCreate = array(
"attribute_code" => "new_attribute",
"scope" => "store",
"frontend_input" => "select",
"is_unique" => 0,
"is_required" => 0,
"is_configurable" => 0,
"is_searchable" => 0,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
"is_filterable" => 1,
"is_filterable_in_search" => 1,
"position" => 1,
"used_for_sort_by" => 1
),
"frontend_label" => array(
array( "store_id" => 0,"label" => "A new attribute" )
)
);
$attributeId = $proxy->call($sessionId,"product_attribute.create",
array(
$attributeToCreate
)
);
// Update attribute
$attributeToUpdate = array(
"scope" => "global",
"is_unique" => 1,
"is_required" => 1,
"is_configurable" => 1,
"is_searchable" => 1,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
"is_filterable" => 01,
"is_filterable_in_search" => 0,
"position" => 2,
"used_for_sort_by" => 0
),
"frontend_label" => array(
array(
"store_id" => 0,
"label" => "A Test Attribute"
)
)
);
$proxy->call(
$sessionId,
"product_attribute.update",
array(
"new_attribute",
$attributeToUpdate
)
);
I hope this will solve your problem..
You can use Magento default API to get default product list
For more details you can refer to following url:
http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.listOfAdditionalAttributes.html
Code used will be:
$proxy = new SoapClient('localhost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$listAttributes = $proxy->call($sessionId, 'product.listOfAdditionalAttributes', array( 'simple', 13 ));

Change category attribute within installation script

I have my module. This module has installation script where should be add custom image field to categories.
$setup->addAttribute('catalog_category', 'additional_image', array(
'type' => 'varchar',
'backend' => 'catalog/category_attribute_backend_image',
'label' => 'Additional Image',
'input' => 'image',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'default' => '',
'position' => 6,
));
After that it must change captions other image fields (Image, Thumbnail). How I can get this system's fields and change their?
You can do this using Mage_Eav_Model_Entity_Setup::updateAttribute() method.
This is a long way off but someone else may need the information.
Mage_Eav_Model_Entity_Setup::updateAttribute()
has 5 arguments, 3 of which are necessary.
I am going to use the example of a custom customer attribute:
$entityTypeId = 'customer'
$id = 'my_custom_attribute_code'
$field = 'is_used_for_customer_segment'
$value = '1'
$sortOrder = Not Needed
So as you can see I am using the customer entity to update the attribute. I am updating my custom attribute with attribute id (code) my_custom_attribute_code. The field in this attribute that I am udpating is the is_used_for_customer_segment and setting the value to yes(1).
Here is an example of how to do this as an update.
$installer->startSetup();
$installer->updateAttribute('customer', 'my_custom_attribute_code', 'is_used_for_customer_segment', '1');
$installer->endSetup();

Resources