Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
5b3b07c7
Commit
5b3b07c7
authored
Apr 06, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix : fix base image
parent
412b1882
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
19 deletions
+17
-19
app/code/Joshine/Script/Console/Command/ProductFirstImageAsBaseFixer.php
+4
-18
app/code/Joshine/Script/Model/ImageQueryResource.php
+13
-1
No files found.
app/code/Joshine/Script/Console/Command/ProductFirstImageAsBaseFixer.php
View file @
5b3b07c7
...
@@ -43,11 +43,9 @@ class ProductFirstImageAsBaseFixer extends Command
...
@@ -43,11 +43,9 @@ class ProductFirstImageAsBaseFixer extends Command
foreach
(
$collection
as
$item
)
{
foreach
(
$collection
as
$item
)
{
$pid
=
$item
->
getId
();
$pid
=
$item
->
getId
();
if
(
$pid
==
'8822'
)
{
$this
->
fixBaseImage
(
$input
,
$output
,
$pid
);
$this
->
fixBaseImage
(
$input
,
$output
,
$pid
);
}
}
}
}
}
protected
function
fixBaseImage
(
$input
,
$output
,
$productId
)
protected
function
fixBaseImage
(
$input
,
$output
,
$productId
)
{
{
...
@@ -55,25 +53,12 @@ class ProductFirstImageAsBaseFixer extends Command
...
@@ -55,25 +53,12 @@ class ProductFirstImageAsBaseFixer extends Command
$firstImage
=
$this
->
imageQueryResource
->
getFirstImages
(
$productId
);
$firstImage
=
$this
->
imageQueryResource
->
getFirstImages
(
$productId
);
$output
->
writeln
(
'first image'
.
$firstImage
);
$output
->
writeln
(
'first image'
.
$firstImage
);
$output
->
writeln
(
"main image"
.
$mainImage
);
if
(
$mainImage
!=
$firstImage
)
{
if
(
$mainImage
!=
$firstImage
)
{
$output
->
writeln
(
'fix product '
.
$mainImage
.
' product id: '
.
$productId
);
$output
->
writeln
(
'fix product '
.
$mainImage
.
' product id: '
.
$productId
);
$otherImages
=
$this
->
imageQueryResource
->
getAllImages
(
$productId
);
//change main image
foreach
(
$otherImages
as
$image
)
{
$this
->
imageQueryResource
->
changeBaseImageTo
(
$productId
,
$firstImage
);
$position
=
1
;
if
(
$image
[
'value'
]
==
$mainImage
)
{
$this
->
imageQueryResource
->
updatePosition
((
int
)
$image
[
'value_id'
],
$position
);
}
}
reset
(
$otherImages
);
foreach
(
$otherImages
as
$image
)
{
if
(
$image
[
'value'
]
!=
$mainImage
)
{
$position
++
;
$this
->
imageQueryResource
->
updatePosition
((
int
)
$image
[
'value_id'
],
$position
);
}
}
}
}
}
}
}
}
\ No newline at end of file
app/code/Joshine/Script/Model/ImageQueryResource.php
View file @
5b3b07c7
...
@@ -90,10 +90,22 @@ class ImageQueryResource
...
@@ -90,10 +90,22 @@ class ImageQueryResource
public
function
updatePosition
(
int
$valueId
,
int
$position
)
public
function
updatePosition
(
int
$valueId
,
int
$position
)
{
{
$this
->
resourceConnection
->
getConnection
()
->
update
(
/*
$this->resourceConnection->getConnection()->update(
$this->resourceConnection->getTableName('catalog_product_entity_media_gallery_value'),
$this->resourceConnection->getTableName('catalog_product_entity_media_gallery_value'),
['position' => $position],
['position' => $position],
['value_id=?' => $valueId]
['value_id=?' => $valueId]
);*/
}
public
function
changeBaseImageTo
(
$productId
,
$firstImage
)
{
$this
->
resourceConnection
->
getConnection
()
->
update
(
$this
->
resourceConnection
->
getTableName
(
'catalog_product_entity_varchar'
),
[
'value'
=>
$firstImage
],
[
'entity_id=?'
=>
$productId
,
'attribute_id=?'
=>
87
],
);
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment