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
fb3768c9
Commit
fb3768c9
authored
Oct 19, 2022
by
lmf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化添加购物车成功后不显示消息
parent
6fe66039
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
237 additions
and
26 deletions
+237
-26
app/code/Magento/Checkout/Controller/Cart/Add.php
+0
-8
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/view/addtocart.phtml
+2
-18
app/design/frontend/Joshine/breeze/Magento_Catalog/web/js/catalog-add-to-cart.js
+235
-0
No files found.
app/code/Magento/Checkout/Controller/Cart/Add.php
View file @
fb3768c9
...
@@ -143,14 +143,6 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
...
@@ -143,14 +143,6 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
$product
->
getName
()
$product
->
getName
()
);
);
$this
->
messageManager
->
addSuccessMessage
(
$message
);
$this
->
messageManager
->
addSuccessMessage
(
$message
);
}
else
{
$this
->
messageManager
->
addComplexSuccessMessage
(
'addCartSuccessMessage'
,
[
'product_name'
=>
$product
->
getName
(),
'cart_url'
=>
$this
->
getCartUrl
(),
]
);
}
}
if
(
$this
->
cart
->
getQuote
()
->
getHasError
())
{
if
(
$this
->
cart
->
getQuote
()
->
getHasError
())
{
$errors
=
$this
->
cart
->
getQuote
()
->
getErrors
();
$errors
=
$this
->
cart
->
getQuote
()
->
getErrors
();
...
...
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/view/addtocart.phtml
View file @
fb3768c9
...
@@ -238,21 +238,4 @@
...
@@ -238,21 +238,4 @@
.area-content
{
padding
:
10px
;
max-width
:
max-content
;
width
:
600px
;}
.area-content
{
padding
:
10px
;
max-width
:
max-content
;
width
:
600px
;}
.mask
{
display
:
none
;
position
:
fixed
;
top
:
0
;
left
:
0
;
z-index
:
100
;
width
:
100%
;
height
:
100%
;
background-color
:
rgba
(
0
,
0
,
0
,
.5
);
}
.mask
{
display
:
none
;
position
:
fixed
;
top
:
0
;
left
:
0
;
z-index
:
100
;
width
:
100%
;
height
:
100%
;
background-color
:
rgba
(
0
,
0
,
0
,
.5
);
}
}
}
</style>
</style>
<script>
\ No newline at end of file
require
([
'jquery'
],
function
(
$
)
{
$
(
document
).
on
(
'click'
,
'.tocart'
,
function
(
event
){
var
minicart
=
$
(
'[data-block="minicart"]'
);
setTimeout
(
function
()
{
minicart
.
find
(
'[data-role="dropdownDialog"]'
).
dropdownDialog
(
'open'
);
},
3000
);
setTimeout
(
function
()
{
minicart
.
find
(
'[data-role="dropdownDialog"]'
).
dropdownDialog
(
'close'
);
},
10000
);
event
.
stopPropagation
();
});
setTimeout
(
function
()
{
$
(
"#product-intro-size-chart"
).
show
();
},
3000
);
});
</script>
app/design/frontend/Joshine/breeze/Magento_Catalog/web/js/catalog-add-to-cart.js
0 → 100644
View file @
fb3768c9
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define
([
'jquery'
,
'mage/translate'
,
'underscore'
,
'Magento_Catalog/js/product/view/product-ids-resolver'
,
'Magento_Catalog/js/product/view/product-info-resolver'
,
'jquery-ui-modules/widget'
],
function
(
$
,
$t
,
_
,
idsResolver
,
productInfoResolver
)
{
'use strict'
;
$
.
widget
(
'mage.catalogAddToCart'
,
{
options
:
{
processStart
:
null
,
processStop
:
null
,
bindSubmit
:
true
,
minicartSelector
:
'[data-block="minicart"]'
,
messagesSelector
:
'[data-placeholder="messages"]'
,
productStatusSelector
:
'.stock.available'
,
addToCartButtonSelector
:
'.action.tocart'
,
addToCartButtonDisabledClass
:
'disabled'
,
addToCartButtonTextWhileAdding
:
''
,
addToCartButtonTextAdded
:
''
,
addToCartButtonTextDefault
:
''
,
productInfoResolver
:
productInfoResolver
},
/** @inheritdoc */
_create
:
function
()
{
if
(
this
.
options
.
bindSubmit
)
{
this
.
_bindSubmit
();
}
$
(
this
.
options
.
addToCartButtonSelector
).
attr
(
'disabled'
,
false
);
},
/**
* @private
*/
_bindSubmit
:
function
()
{
var
self
=
this
;
if
(
this
.
element
.
data
(
'catalog-addtocart-initialized'
))
{
return
;
}
this
.
element
.
data
(
'catalog-addtocart-initialized'
,
1
);
this
.
element
.
on
(
'submit'
,
function
(
e
)
{
e
.
preventDefault
();
self
.
submitForm
(
$
(
this
));
});
},
/**
* @private
*/
_redirect
:
function
(
url
)
{
var
urlParts
,
locationParts
,
forceReload
;
urlParts
=
url
.
split
(
'#'
);
locationParts
=
window
.
location
.
href
.
split
(
'#'
);
forceReload
=
urlParts
[
0
]
===
locationParts
[
0
];
window
.
location
.
assign
(
url
);
if
(
forceReload
)
{
window
.
location
.
reload
();
}
},
/**
* @return {Boolean}
*/
isLoaderEnabled
:
function
()
{
return
this
.
options
.
processStart
&&
this
.
options
.
processStop
;
},
/**
* Handler for the form 'submit' event
*
* @param {jQuery} form
*/
submitForm
:
function
(
form
)
{
this
.
ajaxSubmit
(
form
);
},
/**
* @param {jQuery} form
*/
ajaxSubmit
:
function
(
form
)
{
var
self
=
this
,
productIds
=
idsResolver
(
form
),
productInfo
=
self
.
options
.
productInfoResolver
(
form
),
formData
;
$
(
self
.
options
.
minicartSelector
).
trigger
(
'contentLoading'
);
self
.
disableAddToCartButton
(
form
);
formData
=
new
FormData
(
form
[
0
]);
$
.
ajax
({
url
:
form
.
attr
(
'action'
),
data
:
formData
,
type
:
'post'
,
dataType
:
'json'
,
cache
:
false
,
contentType
:
false
,
processData
:
false
,
/** @inheritdoc */
beforeSend
:
function
()
{
if
(
self
.
isLoaderEnabled
())
{
$
(
'body'
).
trigger
(
self
.
options
.
processStart
);
}
},
/** @inheritdoc */
success
:
function
(
res
)
{
var
eventData
,
parameters
;
$
(
document
).
trigger
(
'ajax:addToCart'
,
{
'sku'
:
form
.
data
().
productSku
,
'productIds'
:
productIds
,
'productInfo'
:
productInfo
,
'form'
:
form
,
'response'
:
res
});
if
(
self
.
isLoaderEnabled
())
{
$
(
'body'
).
trigger
(
self
.
options
.
processStop
);
}
if
(
res
.
backUrl
)
{
eventData
=
{
'form'
:
form
,
'redirectParameters'
:
[]
};
// trigger global event, so other modules will be able add parameters to redirect url
$
(
'body'
).
trigger
(
'catalogCategoryAddToCartRedirect'
,
eventData
);
if
(
eventData
.
redirectParameters
.
length
>
0
&&
window
.
location
.
href
.
split
(
/
[
?#
]
/
)[
0
]
===
res
.
backUrl
)
{
parameters
=
res
.
backUrl
.
split
(
'#'
);
parameters
.
push
(
eventData
.
redirectParameters
.
join
(
'&'
));
res
.
backUrl
=
parameters
.
join
(
'#'
);
}
self
.
_redirect
(
res
.
backUrl
);
return
;
}
if
(
res
.
messages
)
{
$
(
self
.
options
.
messagesSelector
).
html
(
res
.
messages
);
}
if
(
res
.
minicart
)
{
$
(
self
.
options
.
minicartSelector
).
replaceWith
(
res
.
minicart
);
$
(
self
.
options
.
minicartSelector
).
trigger
(
'contentUpdated'
);
}
if
(
res
.
product
&&
res
.
product
.
statusText
)
{
$
(
self
.
options
.
productStatusSelector
)
.
removeClass
(
'available'
)
.
addClass
(
'unavailable'
)
.
find
(
'span'
)
.
html
(
res
.
product
.
statusText
);
}
self
.
enableAddToCartButton
(
form
);
},
/** @inheritdoc */
error
:
function
(
res
)
{
$
(
document
).
trigger
(
'ajax:addToCart:error'
,
{
'sku'
:
form
.
data
().
productSku
,
'productIds'
:
productIds
,
'productInfo'
:
productInfo
,
'form'
:
form
,
'response'
:
res
});
},
/** @inheritdoc */
complete
:
function
(
res
)
{
if
(
res
.
state
()
===
'rejected'
)
{
location
.
reload
();
}
}
});
},
/**
* @param {String} form
*/
disableAddToCartButton
:
function
(
form
)
{
var
addToCartButtonTextWhileAdding
=
this
.
options
.
addToCartButtonTextWhileAdding
||
$t
(
'Adding...'
),
addToCartButton
=
$
(
form
).
find
(
this
.
options
.
addToCartButtonSelector
);
addToCartButton
.
addClass
(
this
.
options
.
addToCartButtonDisabledClass
);
addToCartButton
.
find
(
'span'
).
text
(
addToCartButtonTextWhileAdding
);
addToCartButton
.
attr
(
'title'
,
addToCartButtonTextWhileAdding
);
},
/**
* @param {String} form
*/
enableAddToCartButton
:
function
(
form
)
{
var
addToCartButtonTextAdded
=
this
.
options
.
addToCartButtonTextAdded
||
$t
(
'Added'
),
self
=
this
,
addToCartButton
=
$
(
form
).
find
(
this
.
options
.
addToCartButtonSelector
);
addToCartButton
.
find
(
'span'
).
text
(
addToCartButtonTextAdded
);
addToCartButton
.
attr
(
'title'
,
addToCartButtonTextAdded
);
setTimeout
(
function
()
{
var
addToCartButtonTextDefault
=
self
.
options
.
addToCartButtonTextDefault
||
$t
(
'Add to Cart'
);
addToCartButton
.
removeClass
(
self
.
options
.
addToCartButtonDisabledClass
);
addToCartButton
.
find
(
'span'
).
text
(
addToCartButtonTextDefault
);
addToCartButton
.
attr
(
'title'
,
addToCartButtonTextDefault
);
$
(
'[data-block="minicart"]'
).
find
(
'[data-role="dropdownDialog"]'
).
dropdownDialog
(
'open'
);
},
1000
);
setTimeout
(
function
()
{
$
(
'[data-block="minicart"]'
).
find
(
'[data-role="dropdownDialog"]'
).
dropdownDialog
(
'open'
);
},
3000
);
}
});
return
$
.
mage
.
catalogAddToCart
;
});
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