@@ -483,28 +483,32 @@ protected function _updateAttributeOption($object, $optionId, $option)
483483 * @param int $optionId
484484 * @return void
485485 */
486- private function clearSelectedOptionInEntities ($ object , $ optionId )
486+ private function clearSelectedOptionInEntities (AbstractModel $ object , int $ optionId )
487487 {
488488 $ backendTable = $ object ->getBackendTable ();
489489 $ attributeId = $ object ->getAttributeId ();
490490 if (!$ backendTable || !$ attributeId ) {
491491 return ;
492492 }
493493
494- $ where = 'attribute_id = ' . $ attributeId ;
494+ $ connection = $ this ->getConnection ();
495+ $ where = $ connection ->quoteInto ('attribute_id = ? ' , $ attributeId );
495496 $ update = [];
496497
497498 if ($ object ->getBackendType () === 'varchar ' ) {
498- $ where .= " AND FIND_IN_SET(' $ optionId',value) " ;
499- $ update ['value ' ] = new \Zend_Db_Expr (
500- "TRIM(BOTH ',' FROM REPLACE(CONCAT(',',value,','),', $ optionId,',',')) "
499+ $ where .= ' AND ' . $ connection ->prepareSqlCondition ('value ' , ['finset ' => $ optionId ]);
500+ $ concat = $ connection ->getConcatSql (["',' " , 'value ' , "',' " ]);
501+ $ expr = $ connection ->quoteInto (
502+ "TRIM(BOTH ',' FROM REPLACE( $ concat,',?,',',')) " ,
503+ $ optionId
501504 );
505+ $ update ['value ' ] = new \Zend_Db_Expr ($ expr );
502506 } else {
503- $ where .= ' AND value = ' . $ optionId ;
507+ $ where .= $ connection -> quoteInto ( ' AND value = ? ' , $ optionId) ;
504508 $ update ['value ' ] = null ;
505509 }
506510
507- $ this -> getConnection () ->update ($ backendTable , $ update , $ where );
511+ $ connection ->update ($ backendTable , $ update , $ where );
508512 }
509513
510514 /**
0 commit comments