WooCommerce - change price based on product_id, width and height - height

how can I set my own price in WooCommerce, based on product ID and numbers from added 2 input fields on my single-product/price.php ?
Here is example where i can target price :
http://pastebin.com/BZUV6csG#
But what about inputs? How can i achieve something like that:
if product_id= a or d or g
and inputWidth >=40 and <=60
and inputHeight >=60 and <=80
return product_price = my Value
I try many plugins already, but i have >100products
in different price cathegory based on id/product name) and with >150 price
variation based on width and height
Would you , please help me target those 2 inputs?
I added them using this plugin:
https://github.com/nextime/woocommerce-better-product-addons

Related

How to use parameters for a report to refresh at runtime

I am calculating the score and weight of a result based on a target result and conditions for two measures. These is the dataset I have
GroupName Measure1 Measure2
Group1 0.8 0.7
Group2 0.4 0.8
Currently I am calculating the Score & Weight using two different if functions, like
Measure1 Weight Score =
var kk=IF(
'Sprints'[Velocity%_NEW] > 0.85,
"5",
IF(
'Sprints'[Velocity%_NEW] < 0.85 && 'Sprints'[Velocity%_NEW] >0.7,
"3",
If('Sprints'[Velocity%_NEW] < 0.7,"1"
)))
Return kk *0.5
What I am want is when a user use the report and asked to input the parameter for GroupName then the Score and Weight should change automatically by the value set for each GroupName and calculate the result? any help apperciated.
You can use parameters here. Refer: Create or edit a report parameter
In top header ribbon, choose Modeling and click on “What If” parameter
create a new parameter, what-if parameter screenshot to set the type and range of value that users can input. This will add a slicer to the page where user can choose.
Create a measure to interact with your report. You can add in your calculation for the result to be with your existing data and the user input(add parameter reference in your weight calculation measure).
Simple Example to multiply the source data with the input value from user:
Measure = [Parameter Value]*CALCULATE(SUM(Table1[Value]))
you can also create a measure to view the parameter selected using as below
Parameter Value = SELECTEDVALUE(Parameter[Parameter])

How to get the price and the id from request.POST.getlist()?

i tried to get two value from request.POST.getlist() what i am doing is :
for price in request.POST.getlist('price')
print(price)
what if I want to get two values with two keys i mean i want the price and the id ??
for price, id in request.POST.getlist('price','id') /something like that ???
i trying to submit the data to a form :
for prix in request.POST.getlist('prix'):
na = AssociationForm({'Prix_Unitaire':str(round(float(request.POST['prix']),2)),'Quantite':request.POST['quantite']},instance=Association())
na.save()
if your post data look like as below:
{"price":[2,3,4], "id":[1,2,3]}
for price, id in zip(request.POST.getlist('price'), reqest.POST.getlist('id')):
# do your business here

How to get custom column from MYSQL table through Django

I would like to get specific column from DV table based on input from user.
db :
animal weight height
cat 40 20
wolf 100 50
first i need to get what animal user wants
input1='cat'
and then information about the input1 like weight or height
input2='weight'
animalwho=Wildlife.objects.get(animal=input1)
So if i put animalwho.weight it give me 40
But i want to get column based on input2 as input 2 might be height or any other
I tried animalwho.input2 but it does not work.
Is that possible to get column based on input2?
Would apopreciate any help
The easiest solution would be to convert your object to a dict or get dict directly using values.
Many options to convert object to dict see here link
Then you can easily
animalwho_dict=Wildlife.objects.filter(animal=input1).values()[0]
input2_value = animalwho_dict[input2]

Include 0 to a annotate count if not found in django Queryset.?

I don't know how to phrase my question correctly but what I am doing is I am querying a table based on certain id and then getting the count of the unique field in a column and that count I am giving to matplotlib to plot but what problem I am facing is if a certain value is not found the label size mismatches with the count and plot doesn't work. Below is my query:
workshop_feedback = WorkshopFeedbackResponse.objects.filter(workshop_conducted=workshop_id)
count = workshop_feedback.values('q1').annotate(count=Count('q1'))
sizes = [item['count'] for item in count] #converting to list for matplotlib bar char
labels = [1,2,3] #option of choices for q1
fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax.axis('equal')
# Equal aspect ratio ensures that pie is drawn as a circle.
plt.savefig(os.path.join(settings.BASE_DIR, filename)) #filename is random image filename Which i am creating image of the graph
My column name is q1 and it can contain 1,2,3 as an option depending upon what user has filled but suppose if I don't have 1 or either option the count doesn't reflect that.
Exception Value:
'label' must be of length 'x'
Above is the error I get from if count of certain value is missing. So How to get count as 0 if certain label value is missing?
Edit: If I can query based on label value to get count in a column I can fix my error.

How to apply regular expression on product SKU field in magento

I have let says 3 products
P1 with SKU "xyz_1" and price "10"
P2 with SKU "xyz_2" and price "20"
P3 with SKU "xyz_3" and price "50"
I want a query in magento to get sku xyz with minimum price i.e xyz_1 only.
I want something like this select ,Regex('SKU','myexpression') as SKU to remove last part from i.e "_" part from sku and then apply filter on product collection to get product with minimum price.
Any Ideas how to handle that with Magento?
You could this regex: ^xyz. This will match any string which starts with xyz and ignore what follows.
That being said, you would need to modify your query to sort the results by price since regular expressions do not cater for numerical comparisons (less then, greater than, etc).
EDIT: As per your question, you could adapt some code from here into this:
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
// now $write is an instance of Zend_Db_Adapter_Abstract
$readresult=$write->query("SELECT SUBSTRING(sku, 0, INSTR(sku, '_')) AS SKU FROM <your table> WHERE sku REGEXP '^<your sku>' ORDER BY price asc LIMIT 1;");
SELECT INSTR('foobarbar', 'bar');