12
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
13
13
use Magento \Catalog \Model \CategoryRepository ;
14
14
use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
15
+ use Magento \Framework \App \ResourceConnection ;
15
16
use Magento \Framework \DataObject ;
16
17
use Magento \Framework \EntityManager \MetadataPool ;
17
18
use Magento \Store \Model \Store ;
18
19
use Magento \Store \Model \StoreManagerInterface ;
19
20
use Magento \TestFramework \ObjectManager ;
21
+ use Magento \TestFramework \Helper \Bootstrap ;
20
22
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
21
23
use Magento \TestFramework \TestCase \GraphQlAbstract ;
22
24
@@ -587,9 +589,12 @@ public function testCategoryImage(?string $imagePrefix)
587
589
->getFirstItem ();
588
590
$ categoryId = $ categoryModel ->getId ();
589
591
592
+ /** @var ResourceConnection $resourceConnection */
593
+ $ resourceConnection = Bootstrap::getObjectManager ()->create (ResourceConnection::class);
594
+ $ connection = $ resourceConnection ->getConnection ();
595
+
590
596
if ($ imagePrefix !== null ) {
591
- // update image to account for different stored image formats
592
- $ connection = $ categoryCollection ->getConnection ();
597
+ // update image to account for different stored image format
593
598
$ productLinkField = $ this ->metadataPool
594
599
->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
595
600
->getLinkField ();
@@ -599,20 +604,20 @@ public function testCategoryImage(?string $imagePrefix)
599
604
$ imageAttributeValue = $ imagePrefix . basename ($ categoryModel ->getImage ());
600
605
601
606
if (!empty ($ imageAttributeValue )) {
602
- $ query = sprintf (
607
+ $ sqlQuery = sprintf (
603
608
'UPDATE %s SET `value` = "%s" ' .
604
609
'WHERE `%s` = %d ' .
605
610
'AND `store_id`= %d ' .
606
611
'AND `attribute_id` = ' .
607
612
'(SELECT `ea`.`attribute_id` FROM %s ea WHERE `ea`.`attribute_code` = "image" LIMIT 1) ' ,
608
- $ connection ->getTableName ('catalog_category_entity_varchar ' ),
613
+ $ resourceConnection ->getTableName ('catalog_category_entity_varchar ' ),
609
614
$ imageAttributeValue ,
610
615
$ productLinkField ,
611
616
$ categoryModel ->getData ($ productLinkField ),
612
617
$ defaultStoreId ,
613
- $ connection ->getTableName ('eav_attribute ' )
618
+ $ resourceConnection ->getTableName ('eav_attribute ' )
614
619
);
615
- $ connection ->query ($ query );
620
+ $ connection ->query ($ sqlQuery );
616
621
}
617
622
}
618
623
0 commit comments