Typo3 TCA mark thumb photo - typo3-7.6.x

'main_photos' => array(
'exclude' => 0,
'label' => 'LLL:EXT:my_ext.main_photos',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'uploadfolder' => 'uploads/LLL:EXT:my_ext',
'show_thumbs' => 1,
'size' => 5,
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'disallowed' => '',
'minitems' => 0,
'maxitems' => 10,
),
),
I have multiple images loader. I want to mark one of this photos as main, such as in news.
How can I do it?

Just as it's described in the docs.
https://docs.typo3.org/typo3cms/TCAReference/Reference/Ctrl/Index.html#thumbnail
Add a key 'thumbnail' to your config and have it point to the column name that contains the images you would like to use as thumbnails.
'config'=>array(
...
'thumbnail' => 'image',
...
)

Related

Can't save multiselect attribute on Magento

I created a custom multiselect product attribute through installer. It works and I can save the product if I only select one option from the multiselect values. But if I select 2 values, the product still can be saved but came back up with 1 selected value again. In short, I can't save the attribute with 2 selected values.
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'attr_id',array(
'label' => 'Frontend Name',
'type' => 'int',
'input' => 'multiselect',
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'option' => array (
'value' => array(
'0' => array('First Option'),
'1' => array('Second Option'),
'2' => array('Third Option'),
)
),
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false
));
$installer->endSetup();
The problem comes from the type of your attribute.
'type'=> 'int',
The values from multiselect attributes are saved concatenated by comma 1,4,6. For this you need the attribute to be varchar or text. I recommend varchar if you are not going to have hundreds of options for the attribute.
The way is configured now, when it's saved, the value 1,4,6 is converted to int and it ends up being 1.
Modify you option array from
'option' => array (
'value' => array(
'0' => array('First Option'),
'1' => array('Second Option'),
'2' => array('Third Option'),
)
),
to
'option' => array (
'value' => array(
'first_option' => array('First Option'),
'second_option' => array('Second Option'),
'third_option' => array('Third Option'),
)
),
Multiselect will accept associated array.
I have found the solution myself .
open app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
on save action after this
$category->setAttributeSetId($category->getDefaultAttributeSetId());
Please change language is your attribute name . you can change attribute name accordingly
$ga = "";
if($data['general']['language']){
foreach($data['general']['language'] as $a){
$ga .= $a.",";
}
$category->setLanguage(substr_replace($ga, "", -1));
}
Please replace language to your attribute name and it works...**
I am using SOAP API for entering products in magento shops. here is the full code
In the case of multiselect custom attribute.
$arrProductTime = explode(',', '136,139');
$result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku1234', array(
'categories' => array(36),
'websites' => array(1),
'name' => 'my_pdt1008',
'description' => 'my_pdt1',
'short_description' => 'my_pdt1000',
'weight' => '11',
'status' => '1',
'url_key' => 'product-url-key1',
'url_path' => 'product-url-path1',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title1',
'meta_keyword' => 'Product meta keyword1',
'meta_description' => 'Product meta description1',
'stock_data' => array('qty'=>'100','is_in_stock'=>1,'manage_stock'=>1),
'additional_attributes' => array('multi_data' => array(array('key' => 'product_time', 'value' => $arrProductTime)))
));
I have faced a problem in my custom category attribute. It does not save the multiselect value in data base and does not show multiselect values on the category backend admin.
<?php
require_once("app/Mage.php");
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'cutomcity', array(
'label' => 'Test Select',
'type' => 'varchar',
'input' => 'multiselect',
'visible' => true,
'user_defined' => true,
'required' => false,
'position' => 80,
'visible_on_front' => false,
'group' => 'General Information',
'input' => 'multiselect',
'backend_model'=>'eav/entity_attribute_backend_array'
'source' => 'GA_Multiattribute_Helper_Testsource'
// eav/entity_attribute_source_table Even if i use this untill it does not show selected value on the Multiselect
));
?>
This is my helper file code
<?php
class GA_Multiattribute_Helper_Multiattributesource extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
protected $_optionsDefault = array();
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');;
$customers = array();
foreach($collection as $cust)
{
$fname = $cust->getFirstname();
$lname = $cust->getLastname();
$id = $cust->getId();
$customers[] = array('value'=>"$id$fname", 'label'=>"$fname $lname");
}
return $customers;
}
} ?>

Create Magento coupons progmatically with expiry dates of 30 days from now

I need to Create Coupons in Magento on Action of account Create.
I have created observer which is executing properly on account Create but i am Struggling with Coupons create. I have fixed coupon names on of fixed amount on applicable on cart subtotal.
I found many ans but none of them has anything about expiry of coupon
No replies yet :(
Though I found the solution.
$customer = $observer->getCustomer()->getData();
$email = $customer['email'];
$email100 = $email.'-100-1';
$datei=date('d/m/Y');
$datee = date('d/m/Y', strtotime('1 day'));
$firstname=$customer['firstname'];
$couponcode1=$email.'100-1';
$data = array(
'product_ids' => null,
'name' => sprintf('coupon-100-1', Mage::getSingleton('customer/session')->getCustomerId()),
'description' => null,
'is_active' => 1,
'website_ids' => array(1),
'customer_group_ids' => array(1),
'coupon_type' => 2,
'coupon_code' => $email100,
'uses_per_coupon' => 1,
'uses_per_customer' => 1,
'from_date' => $datei,
'to_date' => $datee,
'sort_order' => null,
'is_rss' => 1,
'test' => 'test',
'rule' => array(
'conditions' => array(
'1' =>array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
),
'1--1' => array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
),
'1--1--1' =>array(
'type' => 'salesrule/rule_condition_address',
'attribute' => 'base_subtotal',
'operator' => '>=',
'value' => '400'
),
'1--1--2' =>array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 0
),
'1--1--2--1' =>array(
'type' => 'salesrule/rule_condition_product_found',
'value' => 1,
'aggregator' => 'all'
),
'1--1--2--1--1' => array(
'type' => 'salesrule/rule_condition_product',
'attribute' => 'special_price',
'operator' => '>=',
'value' => 0
)
),
'actions' => array(
'1' =>array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
'new_child' => null
),
)
),
'simple_action' => 'cart_fixed',
'discount_amount' => 100,
'discount_qty' => 0,
'discount_step' => null,
'apply_to_shipping' => 0,
'simple_free_shipping' => 0,
'stop_rules_processing' => 0,
'store_labels' => array()
);
$model = Mage::getModel('salesrule/rule');
$validateResult = $model->validateData(new Varien_Object($data));
if ($validateResult !== true) {
foreach($validateResult as $errorMessage) {
// print_r($errorMessage);
$session->addError($errorMessage);
}
}
if (isset($data['rule']['conditions'])) {
$data['conditions'] = $data['rule']['conditions'];
}
if (isset($data['rule']['actions'])) {
$data['actions'] = $data['rule']['actions'];
}
unset($data['rule']);
//print_r($data);
$model->loadPost($data);
$model->save();
Here the name of coupon code is email id followed by -100-1.
$datei and $datee are the initial date and the expiry date. I have customized the coupon code so that it is not being used if the cart contains special price item.
Fixed amount discount is applied on the complete cart subtotal.
In Case of query do respond.

Specifying actions for programmatically created coupon code

Based off information found in a couple of posts online (http://www.magentocommerce.com/boards/viewthread/178767/ and http://marius-strajeru.blogspot.co.uk/2010/04/create-bulk-discount-rules.html), I am putting some code together to generate some coupon codes.
One piece I am stuck on is how to write the code to specify the "actions" specific conditions for the coupons use. That would be specified in the "Apply the rule only to cart items matching the following conditions" section of the Actions tab in the Magento admin system.
In the Magento admin system, I would build the following line:
Category is not one of 10,20,30
What I need to know is how to replicate this in code.
I currently have the following, which doesn't appear to be working - at least, when I check the generated coupon code, the action values I require are missing.
$actions = array();
$actions[1] = array(
'type' => 'salesrule/rule_condition_category',
'aggregator' => 'all',
'value' => 1,
'new_child' => ''
);
$actions['1--1'] = array(
'type' => 'salesrule/rule_condition_category',
'attribute' => 'category_ids',
'operator' => '!()',
'value' => '932,341,800',
'is_value_processed' => 0,
);
$model->setData('actions',$actions);
I am assuming that the code is simply wrong, although not tripping up the system.
How I might achieve what I need?
Here's what I ended up with, which works great!
$conditions = array(
"1" => array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
'new_child' => false
),
"1--1" => array(
'type' => 'salesrule/rule_condition_product_found',
'value' => 1,
'aggregator' => 'all',
'new_child' => false
),
"1--1--1" => array(
'type' => 'salesrule/rule_condition_product',
'attribute' => 'category_ids',
'operator' => '!()',
'value' => '10,20,30'
)
);
$actions = array(
"1" => array(
"type" => "salesrule/rule_condition_product",
"aggregator" => "all",
"value" => "1",
"new_child" => false
),
"1--1" => array(
"type" => "salesrule/rule_condition_product",
"attribute" => "category_ids",
'operator' => '!()',
'value' => '10,20,30'
)
);
$rule->setData('conditions',$conditions);
$rule->setData("actions",$actions);

How to save a custom form image to a custom user field

I have a custom form that creates a new user and fills in a number of custom fields for that user. One of these fields is a custom image (not the system avatar image).
I can get the image uploaded to the server through the form, but can't get it into the appropriate field. Here is my (custom module) code so-far.
function newacc_freebusiness_form($form, &$form_state) {
$form['bussimage'] = array(
'#title' => t('Upload an image that shows off your business.'),
'#type' => 'managed_file',
'#description' => t('Max size of 3Mb and filetype of jpg jpeg or png'),
'#upload_location' => 'public://bussimages/',
'#upload_validators' => array(
'file_validate_extensions' => array('png jpg jpeg'),
'file_validate_size' => array(3*1024*1024),
),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
$form['#validate'][] = 'newacc_freebusiness_validate';
return $form;
}
function newacc_freebusiness_validate($form, &$form_state) {
$bussimage = $form_state['values']['bussimage'];
$file = file_load($bussimage);
$bussimage = image_load($file -> uri);
image_save($bussimage);
$bussimage = image_load($file -> uri);
$edit = array(
'name' => 'name',
'mail' => 'mail#mail.com',
'status' => 0,
'language' => 'en',
'init' => 'mail#mail.com',
'roles' => array(8 => 'Promoter'),
'field_business_image' => array(
'und' => array(
0 => array(
'value' => $bussimage,
),
),
),
);
user_save(NULL, $edit);
}
This is throwing the error message:
Notice: Undefined index: fid in file_field_presave() (line 219 of /var/www/drupal_site/modules/file/file.field.inc).
I have tried so many tricks now and googled so long that I can't even explain what I have and haven't tried anymore!
Any help please.
OK - solved this. The clue was in the error message and the solution was very simple! Here is the code:
function newacc_freebusiness_form($form, &$form_state) {
$form['bussimage'] = array(
'#title' => t('Upload an image that shows off your business.'),
'#type' => 'managed_file',
'#description' => t('Max size of 3Mb and filetype of jpg jpeg or png'),
'#upload_location' => 'public://bussimages/',
'#upload_validators' => array(
'file_validate_extensions' => array('png jpg jpeg'),
'file_validate_size' => array(3*1024*1024),
),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
$form['#validate'][] = 'newacc_freebusiness_validate';
return $form;
}
function newacc_freebusiness_validate($form, &$form_state) {
$bussimage = $form_state['values']['bussimage'];
$file = file_load($bussimage);
$edit = array(
'name' => 'name',
'mail' => 'mail#mail.com',
'status' => 0,
'language' => 'en',
'init' => 'mail#mail.com',
'roles' => array(8 => 'Promoter'),
'field_business_image' => array(
'und' => array(
0 => array(
'fid' => $file -> fid,
),
),
),
);
user_save(NULL, $edit);
}
All Drupal was looking for was the file fid in the array. Don't know why I initially assumed it had to be more complicated than this.

Why doesn't the view use the database table I defined in hook_views_data()?

I have a problem with my module views integration. I need to provide information about user who added video and timestamp. Video field is a CCK Embedded Media Field and it stores in content_field_3d_party_video table.
The schema is defined from the following code.
function MODULE_schema() {
$schema = array();
$schema['video_data'] = array(
'description' => t('Users and timestamps for video field'),
'fields' => array(
'value' => array(
'description' => t('Emfield value'),
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => t('User id'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => t('Timestamp'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('value'),
'indexes' => array(
'timestamp' => array('timestamp'),
'uid' => array('uid'),
),
);
return $schema;
}
The hook_views_data() implementation is the following.
function MODULE_views_data() {
$data = array();
$data['video_data']['table']['group'] = t('Video Data');
$data['video_data']['table']['join'] = array(
'node' => array(
'left_table' => 'content_field_3d_party_video',
'left_field' => 'field_3d_party_video_value',
'field' => 'value',
),
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
$data['video_data']['value'] = array(
'title' => t('Video value'),
'relationship' => array(
'base' => 'content_field_3d_party_video',
'base field' => 'field_3d_party_video_value',
'field' => 'value',
'handler' => 'views_handler_relationship',
'label' => t('Video value'),
),
);
$data['video_data']['uid'] = array(
'title' => t('User id'),
'relationship' => array(
'base' => 'users',
'base field' => 'uid',
'field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User id'),
),
);
$data['video_data']['timestamp'] = array(
'title' => t('Timestamp field'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
The table isn't included in the SQL query generated for the view.
SELECT node.nid AS nid,
node.title AS node_title,
node.language AS node_language,
node_data_field_3d_party_video.field_3d_party_video_embed AS node_data_field_3d_party_video_field_3d_party_video_embed,
node_data_field_3d_party_video.field_3d_party_video_value AS node_data_field_3d_party_video_field_3d_party_video_value,
...
node.type AS node_type,
node.vid AS node_vid
FROM node node
LEFT JOIN content_field_3d_party_video content_field_3d_party_video_video_data ON value = content_field_3d_party_video_video_data.field_3d_party_video_value
LEFT JOIN users users_video_data ON uid = users_video_data.uid
LEFT JOIN content_field_3d_party_video node_data_field_3d_party_video ON node.vid = node_data_field_3d_party_video.vid
WHERE ...
May you help me?
This is the solution the OP previously posted in the question.
To correctly join the table used for a CCK field, we must specify node_data_field_3d_party_video as left_table, instead of content_field_3d_party_video.
$data['video_data']['table']['join'] = array(
'node' => array(
'left_table' => 'node_data_field_3d_party_video',
'left_field' => 'field_3d_party_video_value',
'field' => 'value',
),
'users' => array(
'left table' => 'users',
'left_field' => 'uid',
'field' => 'uid',
),
);

Resources