Show out of stock and quantity unit

This commit is contained in:
eraden 2022-05-12 22:10:17 +02:00
parent 1e941a4122
commit cc0f47321e
5 changed files with 86 additions and 20 deletions

View File

@ -12,6 +12,8 @@ async fn create_product(
seed: SharedState,
name: &'static str,
category: &'static str,
short_desc: Option<&'static str>,
long_desc: Option<&'static str>,
) -> crate::Result<()> {
let seed = seed.clone();
let db = db.clone();
@ -19,8 +21,12 @@ async fn create_product(
db,
database_manager::CreateProduct {
name: ProductName::from(String::from(name)),
short_description: Faker.fake(),
long_description: Faker.fake(),
short_description: short_desc
.map(|s| model::ProductShortDesc::new(s))
.unwrap_or_else(|| Faker.fake()),
long_description: long_desc
.map(|s| model::ProductLongDesc::new(s))
.unwrap_or_else(|| Faker.fake()),
category: Some(ProductCategory::new(category)),
price: Faker.fake(),
deliver_days_flag: Faker.fake(),
@ -59,72 +65,96 @@ pub(crate) async fn create_products(
seed.clone(),
"Nikon",
model::Category::CAMERAS_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Bonoid CBD",
model::Category::DRUGSTORE_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Casio Speaker",
model::Category::SPEAKERS_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Eprism Studio",
model::Category::DRUGSTORE_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Best Phones 2022",
model::Category::PHONES_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Sweet cake",
model::Category::SWEETS_NAME,
None,
Some("The packaging of a product can do so much to the brand awareness campaigns of any brand. With a good quality logo along with the color scheme of a brand added on those packaging, it can perfectly represent such brand wherever it may reach. Do you need a mockup to test your paper lock box packaging? If you do then this freebie will make you feel lucky. It features 2 paper lock boxes with the one top of the other. Apparently, each of the boxes comes with smart object layer for inserting your own branding. You can use this for bread, donuts and similar products.")
),
create_product(
db.clone(),
seed.clone(),
"Lexal 128G",
model::Category::MEMORY_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Fujifilm X-T10",
model::Category::CAMERAS_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Sweet Tower",
model::Category::SWEETS_NAME,
None,
Some("If youre currently designing a label for your product packaging using pouch, you can opt for this Plastic Pouch Product Mockup Free PSD. Before you finalize your designs, it would be best to have a product mockup to help you see the flaws and polish it well. This mockup will aid you with your label designs for soy sauce, tomato sauce, coffee or any pouch products. Apparently, this mockup lets you add a design for the surface of the pouch via smart object layer; change the color of the pouch to represent the kind of flavor of the product inside and the background color to match with your designs.")
),
create_product(
db.clone(),
seed.clone(),
"Nikon Lenses",
model::Category::CAMERAS_NAME,
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Venus HD Professional",
model::Category::DRUGSTORE_NAME,
None,
Some("Cosmetic products have always been hot and in demand. Thats why many entrepreneurs in this line of business always seek for the best cosmetic products to meet the demands. Hence, cosmetic businesses need to craft their labels with keenness to for effective branding. If youre a designer working with cosmetic products packaging, this free mockup is useful to you. It features a cosmetic pump bottle and a cream pot to showcase your logo, branding and marketing designs. You can easily add your own graphics into the scene via the smart object layer. With this mockup, you can impress a client with a photorealistic product packaging in no time!")
),
create_product(
db.clone(),
seed.clone(),
"Fancy Plate",
model::Category::PLATES_NAME,
None,
None
)
);
results.0.unwrap();

View File

@ -26,7 +26,13 @@ impl<T> fake::Dummy<T> for ProductShortDesc {
impl<T> fake::Dummy<T> for ProductLongDesc {
fn dummy_with_rng<R: Rng + ?Sized>(_config: &T, _rng: &mut R) -> Self {
use fake::faker::lorem::en::Paragraphs;
let words: Vec<String> = Paragraphs(10..20).fake();
let words: Vec<String> = (3..5)
.into_iter()
.map(|_| {
let words: Vec<String> = Paragraphs(4..8).fake();
words.join(" ").to_string()
})
.collect();
Self(words.join("\n"))
}
}

View File

@ -681,12 +681,24 @@ pub struct ProductName(String);
#[serde(transparent)]
pub struct ProductShortDesc(String);
impl ProductShortDesc {
pub fn new<S: Into<String>>(s: S) -> Self {
Self(s.into())
}
}
#[cfg_attr(feature = "db", derive(sqlx::Type))]
#[cfg_attr(feature = "db", sqlx(transparent))]
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Deref, Display, From)]
#[serde(transparent)]
pub struct ProductLongDesc(String);
impl ProductLongDesc {
pub fn new<S: Into<String>>(s: S) -> Self {
Self(s.into())
}
}
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
#[cfg_attr(feature = "db", derive(sqlx::Type))]
#[cfg_attr(feature = "db", sqlx(transparent))]

View File

@ -20,5 +20,15 @@ pub fn define(i18n: &mut I18n) {
.define("Memory", "Pamięć")
.define("Pants", "Spodnie")
.define("Clothes", "Ubrania")
.define("Plates", "Talerze");
.define("Plates", "Talerze")
.define("Price per", "Cena za")
.define("g", "g")
.define("dkg", "dkg")
.define("kg", "kg")
.define("piece", "szt")
.define("Gram", "Gram")
.define("Decagram", "Decagram")
.define("Kilogram", "Kilogram")
.define("Piece", "Sztukę")
.define("Out of stock", "Brak na stanie");
}

View File

@ -95,10 +95,28 @@ pub fn view(model: &crate::Model, page: &ProductPage) -> Node<crate::Msg> {
C!["mb-2 leading-tight tracking-tight font-bold text-gray-800 text-2xl md:text-3xl"],
product.name.as_str()
],
div![model.i18n.t("Price per"), ": ", model.i18n.t(product.quantity_unit.short_name())],
div![model.i18n.t("Price per"), " ", model.i18n.t(product.quantity_unit.name()).to_lowercase()],
div![
delivery
],
action_section(product, model)
],
],
div![
C!["-mx-4"],
attrs!["id" => "product-header"],
div![description]
]
].map_msg(map_to_global);
div![
crate::shared::view::public_navbar(model),
super::layout::view(model, content, None)
]
}
fn action_section(product: &model::api::Product, model: &crate::Model) -> Node<Msg> {
if product.available {
div![
C!["flex py-4 space-x-4"],
div![
@ -120,19 +138,9 @@ pub fn view(model: &crate::Model, page: &ProductPage) -> Node<crate::Msg> {
})
]
]
],
],
div![
C!["-mx-4"],
attrs!["id" => "product-header"],
div![description]
]
].map_msg(map_to_global);
div![
crate::shared::view::public_navbar(model),
super::layout::view(model, content, None)
]
} else {
div![C!["text-sm text-gray-400 "], model.i18n.t("Out of stock")]
}
}
fn delivery_available(product: &model::api::Product, model: &crate::Model) -> Node<Msg> {
@ -161,7 +169,7 @@ fn small_image(idx: usize, selected: usize, img: &model::api::Photo) -> Node<Msg
C!["focus:outline-none w-full rounded-lg h-24 md:h-32 bg-gray-100 flex items-center justify-center ring-indigo-300 ring-inset"],
IF![selected == idx => C!["ring-2"]],
img![
C!["h-24 md:h-32"],
C!["h-24 md:h-31"],
attrs!["src" => img.url.as_str()]
],
ev("click", move |ev| {