View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0003148 | OXID eShop (all versions) | 1.01. Products (product, categories, manufacturer, promotions etc.) | public | 2011-08-16 14:29 | 2012-12-07 14:28 |
Reporter | d3 | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 4.5.1 revision 38045 | ||||
Fixed in Version | 4.5.2 revision 38481 | ||||
Summary | 0003148: save-function causes fatal error | ||||
Description | oxarticle save-function causes fatal error. V4.5.0: Fatal error: Call to a member function setValue() on a non-object in /this/is/shop-root/core/oxarticle.php on line 1951 | ||||
Steps To Reproduce | public function save() { $myConfig = $this->getConfig(); $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW); $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW); $iPicCount = $myConfig->getConfigParam( 'iPicCount'); for ($i=1; $i <= $iPicCount; $i++) { if ( isset($this->{'oxarticles__oxpic'.$i}) ) { $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value)); } } if ( ( $blRet = parent::save() ) ) { // saving long descrition $this->_saveArtLongDesc(); } return $blRet; } | ||||
Additional Information | should be: public function save() { $myConfig = $this->getConfig(); $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW); $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW); $iPicCount = $myConfig->getConfigParam( 'iPicCount'); for ($i=1; $i <= $iPicCount; $i++) { if ( $this->getFieldData("oxpic$i") ) { $sFieldName = $this->getFieldLongName("oxpic$i"); $this->$sFieldName = oxNew("oxField", basename($this->getFieldData("oxpic$i"))); } } if ( ( $blRet = parent::save() ) ) { // saving long descrition $this->_saveArtLongDesc(); } return $blRet; } | ||||
Tags | Products | ||||
Theme | Both | ||||
Browser | All | ||||
PHP Version | any | ||||
Database Version | any | ||||
|
function getFieldLongName (_getFieldLongName) is protected should be public |
|
@developers please investigate it |
|
function setFieldData (_setFieldData) is protected too should also be public |
|
correct fix: for ( $i = 1; $i <= $iPicCount; $i++ ) { $sFieldName = 'oxarticles__oxpic' . $i; if ( isset( $this->$sFieldName ) ) { $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW ); } } and why do you need these getters/setters to be public? |
|
oxBase::_getFieldLongName() and especially oxBase::_setFieldData() are not the part of public class interface and are not intended to be called from outside, therefore they are declared as protected. You should use public interface methods (eg. oxBase::assign() or oxField::setValue()) in order to init field values. |
|
@ tomas_liubinas Because there is no documentation, tutorial or best practice guideline for the correct usage of the api. Most of the usage is copied from existing oxid code. Just search for 'new oxField' in the shop souces... you will find many examples of inconsequent api usage (oxNew, oxBase::assign() etc..) Agreed, oxBase::assign() is the correct method for those purposes. One question: in the following line of your fix: "$this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );" why the usage of "$this->$sFieldName->value" and not "$this->getFieldData($sFieldName)" ? Also the usage of oxBase::assign() would be consequent. |
|
"why the usage of "$this->$sFieldName->value" and not "$this->getFieldData($sFieldName)" ?" in this case just only due to performace reasons (and because this code is now deprecated), as field name is known (also checked by isset()), so there is no need to call getter. But third party module writers should use oxArticle::_setFieldData()/oxArticle::getFieldData()/oxArticle::_getFieldLongName() |