JigoShop WordPress hidden value submission - php

I have been toiling with this issue for the past 2 days now, and I can't seem to get some functionality working on a customization for a WordPress plugin. I am using latest versions of both JigoShop and WordPress.
URL to project: http://customcasing.ca/product/ipad-case/
Current Functionality
I have 5 product SKUs on the homepage and when clicked lead to their respective product order pages. On these respective pages are a design canvas which I have implemented fabricjs to handle image manipulation. When the user is satisfied, they save the canvas, which then uses the following example code to serialize the image into a JSON object:
saving/loading canvas with JSON
The JSON object is then set as the value of a hidden input within the "Add to cart" form. Then they would be able to choose product color variations, via dropdown boxes.
Now here is where things fall apart
Submitting the "Add to cart" form is supposed to run through a number of classes and post the hidden JSON object value to an aggregated "cart" object. This is called on various pages and a key/value pair is associated with the various attributes of the product. However, all the other key/value pairs are being executed and echo'd on a subsequent order review page...except my custom variable.
Here is the directory architecture
/wp-content
...
/plugins
...
/jigoshop
jigoshop_template_functions.php
jigoshop_actions.php
/classes
jigoshop_cart.class.php
/themes
/customcasing
Here are the code blocks associated with the above structure (pastebin)
jigoshop_template_functions.php
html generator and form
jigoshop_actions.php
form $_post for hidden field
classes/jigoshop_cart.class.php
form validation and key/value pair creation
I have given as much information as I possibly can about my current conditions, if there were to be anything of help on stackoverflow it would be the following Q/A:
Trying to send a hidden input value to next page
If you need any additional information please feel free to ask and I will do my best to elaborate. Also if you need a wider scope of the code I can provide that as well. I would really appreciate any nudge in the right direction.

Related

Ajax/jquery/php: one product with different color with different pictures

I am making custom shop-cms. And at this point I am stuck, trying to make for each product possibility for picking colors and for each color 1-5 picture(s). And I just can't understand the most reasonable solution, how should the form look like. The point is that I clone the CREATE form on page load for less code purposes, making an EDIT form out of it. When I click on product's EDIT button it makes a request to DB picking all the information according to the chosen ID. The way I see it is that I have to have main hidden input where I keep all the information about all the colors and related pictures on other inputs change. That will do with creating new product. But when it comes to editing, it requires now collect the information in reverse, the main input's change fills related inputs. And the way I see it requires a lot of rows of code, which is not an option. Maybe somebody has done it before and knows a simple way.
in the DB I keep everything in one cell :
COLOR { IMG => VALUE, PRICE => VALUE }, COLOR { IMG => VALUE..etc}
You can use AngularJS kind of framework to build single page application.
OR use Ajax to call and fetch data for each action.
Loading all data and manipulate them in hidden fields, may makes things complicated.
I myself will either use MVC Framework (i.e. Angularjs) or jQuery ajax to load data according to each action.

Create paginated Drupal form. (Drupal 6)

I am trying to create a form which provide a checkbox element on each row. Problem is that I have 2000 rows which takes some time to load and also it is not easy to navigate through whole list.
Is there a way to create some kind of pagination in Drupal form ?
There's no built-in pagination of field values within the context of a larger form that I'm aware of. Instead, you'd probably want to consider a Javascript solution, where you load all 2000 form values, but you use JS and CSS to hide all but the first page. Then you create Javascript forward/back and page links which dynamically hide the first "page" of checkboxes and load the page in question.
The reason I recommend this, instead of an AJAX request that loads only the first 20 records and then dynamically loads more via a pager, is that you'd have to separately track and store which values had been checked (since the AJAX would literally throw away and reload the next 20 checkbox values). By contrast, if it doesn't slow the page down to load all 2000 checkboxes as, say, 100 individual sections behind the scenes, and then use your custom JS pager to show/hide the pages, your user could check and uncheck while paging and all the values would be remembered. (It's an often overlooked feature of HTML forms that they retain their field values even when hidden via CSS, which can be super helpful when you're aware of it).
I don't think a code snippet would be too useful here because this is a fairly open-ended problem, but the basic process would be:
Use hook_form_alter() to change the specific checkbox group field(s). Specifically, you would use markup to add the paginator controls after running the database query to retrieve the results and determine the number of pages.
Also as part of using hook_form_alter(), you would loop a page at a time and generate all 100 (or whatever number) pages of checkbox options, setting all but the first page to display:none in the <div> tags surrounding the checkbox options.
Create JS or jQuery functions in your site's custom theme, or put the code into an includes/ folder and load it dynamically through hook_form_alter (not elegant - I recommend always having a custom theme or sub-theme available). This function would listen for the link press and the current page and hide/show the proper CSS blocks.
If you wanted to get fancy, you could also create a JS-enabled page number field where you could type in a page number and hit Enter, or a search feature that would return individual results (more complex since now you'd have to be able to show/hide all individual records), and a check all/uncheck all feature for individual pages. Have fun!

Joomla Virtuemart 2 plgVmOnSelectPayment()

How can I add a form or HTML output to plgVmOnSelectPayment()?
I see no documentation about that.
I don't know this event Virtuemart payment select works.
I want add after selection a form with input fields.
Can anyone help ?
The plgVmOnSelectPayment() from what I've reversed engineered doesn't give any output to the HTML, but you can modify the cart content with that event.
I was myself in need of adding a form after a particular payment method was selected (to guarantee some additional data being supplied). Depending on where you want it you can either edit the View for the cart and add an if-statement where you see if the particular payment method is chosen. And then later access this information from plgVmConfirmedOrder() (you can access it through the $_POST global.
(This is an untested theory)
If you want to add the information to the field you can access the display form and add information there through the plgVmDisplayListFEPayment() event. Look in the vmPSPlugin class to see how they manage it there. What I did was simply copy that to get an image into that form, but you should be able to add other things there as well. And then you might be able to access the information there through plgVmOnSelectPayment() and using the $_POST global.
As a fair warning. All this I've gotten through reverse engineering VirtueMart. So it's neither pictue perfect nor might it be best practice. But the VirtueMart documentation leave not many other options :(. So if someone have a better way, I'm very interested in knowing that as well!

Access Drupal webform fields in custom page

I've placed a copy of the webform-submission page in my sites theme folder, and am modifying it to display the submissions pages how I would like. At the moment, to print an elements value, I use:
$submission->data[n]['value'][0]
Where data[n] is specific to the element in the webform. Is there any way I can use something more like $submission->data[element_key]['value'][0] to get the field info. It just makes for much easier reading, especially since I won't be the person maintaining the site.
Thanks.
p.s. this is in Drupal 7, webform 3.0
The $usbmission array is built in the function webform_get_submissions.
Notice that the table which contains the element_key data you're looking for (webform_component table) is not queried in this function.
So if you want that data, you would have to fetch the element_key information yourself and rebuild the $submission array in an implementation of hook_webform_submission_load.

Zend Form - dynamic adding subforms

I'm working with Zend Form and I need to dynamically (when filling out the form by user) add groups of elements.
For example I have form with few fields describing offer and one subform to set offer price. But offer can have more than one price and price is not only 1 element, its composed of
offer regular price
offer discount price
offer items count
So there are 3 different elements in one gruop.
I can create elements with javascript but when should I add them to Zend Form Object?
you could make each of the groupings a subform that way when you add via javascript, you could ajax that portion of the form in by just rending the subform with a 'Belongsto'. Then, you could read in your post when it comes back to you and do a foreach on it and add the elements back that way.
check out http://www.stephenrhoades.com/?p=364
Otherwise, in your ajax to get the form markup, you could be building a form object that you could save to the session, that way it will already be built at posting time.

Categories