Here is what i'm gonna do with CartTrhob.
I want to sell a product that can be sold in different material. Every product has it's own volume in cm3, and every material has a Price per cm3.
So for example:
PRODUCT_A has a VOLUME of 10 cm3
In a channel called "MATERIAL" i have saved all the available material that can be applied to every PRODUCT. Every material has this fixed values:
MATERIAL_A - PRICE/CM3=2 - PRODUCTION_FEE=3; MATERIAL_B - PRICE/CM3=8 - PRODUCTION_FEE=2; MATERIAL_C - PRICE/CM3=6 - PRODUCTION_FEE=5;
The price is made by this formula:
MATERIAL_PRICE = (PRODUCT_VOLUME * MATERIAL_PRICE/CM3) + MATERIAL_PRODUCTION_FEE
So in this case i'll have:
PRODUCT_A:
- MATERIA_A_PRICE = (10 * 2) + 3 = 23$
- MATERIA_B_PRICE = (10 * 8) + 2 = 82$
- MATERIA_C_PRICE = (10 * 6) + 5 = 65$
I would that every single material price for every single product is automatically calculated by the above formula. So every time i'll add new product i have to add only the VOLUME variable and EE does the rest.
At the end, after all material prices are calculated, i would that MATERIAL_A_PRICE is shown by default, as it is the default PRODUCT PRICE.
I think that the matrix price modifiers is the solution but i can't find the solution to make this MAGIC and store all that value in entries.
Some brave man can help me?
--- ADDED LATER ---
I found that question here:
Pre-fill matrix field when creating new entry?
and the script to add in the instruction is this:
<script>
$(function() {
// Make sure that this is the publish form
if (!EE.publish)
return;
// Only proceed when creating a new entry
var entryId = $('#publishForm').find('input[name="entry_id"]').val();
if (entryId != 0)
return;
function initLabels(id, labels) {
var addEntryButton = $('#sub_hold_field_' + id + ' .matrix-btn.matrix-add');
if (!addEntryButton.length)
return;
// Need to wait after `document.ready` has finished executing!
setTimeout(function() {
var field = $('#sub_hold_field_' + id);
// Only proceed if matrix is empty
// Note: This is not the case if a validation error occurs!
if (!field.find('.matrix-norows').is(':visible'))
return;
// Create one row for each label
for (var i = 0; i < labels.length; ++i)
addEntryButton.click();
// Skip the placeholder row for "No rows have been added yet..."
field.find('tbody tr:not(.matrix-norows)').each(function(i) {
$(this).find('.matrix-firstcell textarea').val(labels[i]);
});
}, 0);
}
// Check that this is an entry of the expected channel field group
if (EE.publish.field_group == 2) {
// "Custom Parameters"
initLabels('23', [
'Lens Type',
'Focal Length',
'Manufacturer',
'Model',
'Serial Number'
]);
// "Track Information"
initLabels('17', [
'Artist',
'Title',
'Label',
'Artwork'
]);
}
})
</script>
But i have no idea on how to customize for me. How i can auto-fill with material name, price/cm3 and commission_fee hidden value in script to make the operations?