Call to a member function getSKU() on null
Permalink 1 user found helpful
I am using C5.7.5.13.
I am trying to pull data from a different block to put it in my form block.
http://www.mytinytown.com/products/pump-duty-float-switch-10-foot-n...
Right side in the form area where is says SKU, I want that to be filled with the SKU at the top of the page. I just cannot figure out hoe to call to the table the SKU is in.
I am trying to pull data from a different block to put it in my form block.
http://www.mytinytown.com/products/pump-duty-float-switch-10-foot-n...
Right side in the form area where is says SKU, I want that to be filled with the SKU at the top of the page. I just cannot figure out hoe to call to the table the SKU is in.
You are very correct! Yes, the product SKU I need will be on the same page as the form is too.
So I added the info you suggested.
http://www.mytinytown.com/products/pump-duty-float-switch-10-foot-n...
At the top of the page I now have:
Then in the form I have:
I still get:
Call to a member function getSKU() on null
I also tried
and then
This rendered no errors, but no SKU either.
So I added the info you suggested.
http://www.mytinytown.com/products/pump-duty-float-switch-10-foot-n...
At the top of the page I now have:
namespace Concrete\Block\Form; use Core; use Database; use Request; use Page; use Config; $cID = Page::getCurrentPage()->getCollectionID(); $product = \Concrete\Package\CommunityStore\Src\CommunityStore\Product\Product::getByCollectionID($cID); class MiniSurvey
Then in the form I have:
return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" class="form-control" type="text" value="'.$product->getSKU().'" />';
I still get:
Call to a member function getSKU() on null
I also tried
namespace Concrete\Block\Form; use Core; use Database; use Request; use Page; use Config; $cID = Page::getCurrentPage()->getCollectionID(); $product = \Concrete\Package\CommunityStore\Src\CommunityStore\Product\Product::getByCollectionID($cID); $GetSKU = $product->getSKU(); class MiniSurvey
and then
return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" class="form-control" type="text" value="'.$GetSKU.'" />';
This rendered no errors, but no SKU either.
you have to put everything I gave you in the form, not in the page.
And you should be using a template for your form, not edit the block directly.
And you should be using a template for your form, not edit the block directly.
HA!!!!!
I got it!!!
I had to put the info you gave me down the page a bit, around line 258 in the mini_survey.php page.
Thank you VERY much, I would have never figured it out without your help.
I got it!!!
I had to put the info you gave me down the page a bit, around line 258 in the mini_survey.php page.
public function loadInputType($questionData, $showEdit) { $options = explode('%%', $questionData['options']); $defaultDate = $questionData['defaultDate']; $msqID = intval($questionData['msqID']); $datetime = Core::make('helper/form/date_time'); $html = ''; $cID = Page::getCurrentPage()->getCollectionID(); $product = \Concrete\Package\CommunityStore\Src\CommunityStore\Product\Product::getByCollectionID($cID); $GetSKU = $product->getSKU(); switch ($questionData['inputType']) { case 'checkboxlist':
Thank you VERY much, I would have never figured it out without your help.
You really shouldn't do it that way. Next time you update Concrete5 you are going to lose all your modifications.
You should create a template for your form, make your modifications there and use the template
You should create a template for your form, make your modifications there and use the template
Oh
I never thought of that.
Thank you for your advice again.
I never thought of that.
Thank you for your advice again.
I know this is from last year, but I just upgraded from 5.7 to 5.8 and had to re-setup this SKU thing. I did get it all set up, but decided to do it right this time tried to do a couple things. I tried to add it to the application/blocks and make it is template.
1st I added it to my application/blocks/form folder, I needed to put the following files:
form_setup_html.php
mini_survey.php
view.php
This would not load the SKU info this way, it looks like the mini_survey.php file is overlooked doing it this way. The SKU info is not added to the page and that all comes from the mini_survey.php file.
So...
2nd I tried to make a template. Mostly same results. The template did not load the mini_survey.php and I need a custom form_setup_html.php file. The template would not load that either.
The only thing left is to make it a package. I have made custom packages from stock blocks. So, it should be possible. I'll post my results.
1st I added it to my application/blocks/form folder, I needed to put the following files:
form_setup_html.php
mini_survey.php
view.php
This would not load the SKU info this way, it looks like the mini_survey.php file is overlooked doing it this way. The SKU info is not added to the page and that all comes from the mini_survey.php file.
So...
2nd I tried to make a template. Mostly same results. The template did not load the mini_survey.php and I need a custom form_setup_html.php file. The template would not load that either.
The only thing left is to make it a package. I have made custom packages from stock blocks. So, it should be possible. I'll post my results.
You are using Community Store so I'm going to assume that you are using the product block to show product information and that the form on the right is a separate block.
The following way will allow you to get the SKU from within the form block only if your products are attached to pages (so if your product block is set to work per location). If yes, do this:
The you can do your normal