Jump to content

YoJoe

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by YoJoe

  1. I'll answer myself as I doubt anyone will propose anything. I sticked to my first idea of getting all categories to which the product is bound if the main category is set to "home", and showing the last category info from the array as at last I found a way of getting needed data. The most important snippet to get category name: {assign var='ProductLastCatName' value=Category::getCategoryInformations(array(Product::getProductCategories($product.id)|@end))} {$ProductLastCatName[Product::getProductCategories($product.id)|@end].name|lower} Better such solution, than none.
  2. try using (int)$id_customization, there's no space after bracket in latest PS version. After you got rid of this value check if changes work with product combinations as this value is afaik responsible for additional product attributes. Unless you don't sell product with combinations. Second thing is that you should check if updateQty function doesn't use $cartProductQuantity elsewhere, as changes use it's own $getCountInCart instead of $cartProductQuantity. Just switch it and check. I don't know the differences in latest PS version but you should notice what's going on. Try enabling debug mode.
  3. The changes won't block adding to cart directly from category listing or homepage as the shop I was implementing those changes doesn't offer such functions. Thus I cannot tell you in which template file you should look for. But it shouldn't let the visitor adding more than 1 (or any other fixed value) same products to the cart, letting know the visitor that product is already in to cart. Basically you need to make 3 changes, 1. as Zon3d described /classes/cart.php Make an override of this file by copying it to /override/classes/ not to work on a core file inside this file, as mentioned above, make changes after the lines: /* Check if the product is already in the cart */ $cartProductQuantity = $this->getProductQuantity ... by adding below code //limit maximum product quantity a user can add to cart $totalLimitOnProducts = 1; // this is the max amount of same products you want to limit in cart $getCountInCart = $this->getProductQuantity( $id_product, $id_product_attribute, (int)$id_customization ); $countInCart += $getCountInCart['quantity']; //counts amount of each of those products already in the cart and sums it up if ($operator == 'up') { // make sure it's an increase to the quantity, not a decrease if($countInCart >= $totalLimitOnProducts) { /// if already reached limit on amount of products return false; } else if($quantity > ($totalLimitOnProducts-$countInCart)) { /// if quantity desired is more than amount allowed return false; } 2. hide arrow buttons allowing to change product quantity on product page and inside cart yourtheme//templates/checkout/_partials/cart-detailed-product-line.tpl Find: <!-- product left body: description --> And change this: <div class="row"> {if isset($product.is_gift) && $product.is_gift} <div class="col-md-6 col-xs-6 qty"> <span class="gift-quantity">{$product.quantity}</span> </div> {/if} <div class="col-md-6 col-xs-2 price"> into this <div class="row"> <div class="col-md-6 col-xs-6 qty"> {if isset($product.is_gift) && $product.is_gift} <span class="gift-quantity">{$product.quantity}</span> {else} <input class="js-cart-line-product-quantity" data-down-url="{$product.down_quantity_url}" data-up-url="{$product.up_quantity_url}" data-update-url="{$product.update_quantity_url}" data-product-id="{$product.id_product}" type="text" value="{$product.quantity}" name="product-quantity-spin" min="{$product.minimal_quantity}" /> {/if} </div> <div class="col-md-6 col-xs-2 price"> since I don't remember the reason of making changes in this file I can't tell you now what for I made them. Make a backup before making changes and see if this one is truly needed. 3. file: yourtheme/templates/catalog/_partials/product-add-to-cart.tpl check the tutorial linked by the end of my earlier post you need to do this otherwise visitors will still be able to raise the amount of product in cart just by clicking multiple times on "add to cart" button in this file you also need to get rid of <> quantity change buttons. Below is the code of all changes I made in this file taking also in the account changes from the tutorial. I just commented out code of the buttons so compare with your template file <div class="product-add-to-cart"> {if !$configuration.is_catalog} <span class="control-label">{l s='Quantity' d='Shop.Theme.Catalog'}</span> {if $product.availability == 'available' || $product.availability == 'last_remaining_items'} {block name='product_quantity'} <div class="product-quantity clearfix"> {* hide product quantity input field <div class="qty"> <input type="text" name="qty" id="quantity_wanted" value="{$product.quantity_wanted}" class="input-group" min="{$product.minimal_quantity}" aria-label="{l s='Quantity' d='Shop.Theme.Actions'}" > </div> *} <div class="add"> {$in_cart = 0} {foreach from=$cart['products'] item='cart_product' } {*if $cart_product['id_product'] == $product.id*} {if $cart_product['id_product'] == $product.id && $cart_product['id_product_attribute'] == $product.id_product_attribute} {$in_cart = 1} {/if} {/foreach} <button class="btn btn-primary add-to-cart" data-button-action="add-to-cart" type="submit" {* disable button after adding product to cart or when product is already in cart *} {if !$product.add_to_cart_url || $in_cart} disabled style="filter: grayscale(0.5);box-shadow: inset 2px 2px 4px 0 rgba(0,0,0,.2);" {/if} > <i class="material-icons shopping-cart">&#xE547;</i> {* default addtocart button {l s='Add to cart' d='Shop.Theme.Actions'} *} {if $in_cart} {l s='Already in cart' d='Shop.Theme.Actions'} {else} {l s='Add to cart' d='Shop.Theme.Actions'} {/if} </button> </div> </div> {/block} {/if} {block name='product_availability'} <p id="product-availability"> {if $product.show_availability && $product.availability_message} {if $product.availability == 'available'} <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i> <span class="d-inline-block">{$product.availability_message}</span> {elseif $product.availability == 'last_remaining_items'} <i class="material-icons product-last-items">&#xE002;</i> <span class="d-inline-block">{l s='Last Item In Stock' d='Shop.Theme.Actions'}{*$product.availability_message*}</span> {else} <i class="material-icons product-unavailable">&#xE14B;</i> <span class="d-inline-block">{l s='Sold out' d='Shop.Theme.Actions'}</span> {/if} {*$product.availability_message*} {/if} </p> {/block} {block name='product_minimal_quantity'} <p class="product-minimal-quantity"> {if $product.minimal_quantity > 1} {l s='The minimum purchase order quantity for the product is %quantity%.' d='Shop.Theme.Checkout' sprintf=['%quantity%' => $product.minimal_quantity] } {/if} </p> {/block} {/if} </div> this should do, at least in PS 1.7.4 in which I was implementing all needed changes
  4. Sounds like a possible problem with presta cache refreshing after this time.
  5. If product page stays visible there will be no 404. Just set products visibility to nowhere, and reactivate them. It will show visitors coming from SERPs that product is unavailable, but it won't be searchable and visible in the shop directly.
  6. I'm struggling with a seemingly simple thing of displaying a category meta_title inside product's H1 header to which the product is bound in prestashop v1.7.4. If such category doesn't have meta title field set, then showing category name would be a fallback. I thought implementation is as simple as it sounds, and all one has to use are these two variables: $category->name $category->meta_title within a conditional statement, checking of course if meta title isset. It's true for products bound to only 1 category. The problem arises when a product is bound to multiple categories with "home" category among them. Especially when "home" is set as default, making the use of $product.id_category_default completely useless. The more, above mentioned vars show category name or meta title depending on the place from which visitor enters the product page. And this complicates getting the category data pretty much. I won't go into details not to make this topic too long. I thought of grabbing all categories to which the product is bound, then checking what sits in fetched array and just display what I need. No matter which category, let it be second or even last one as "home" category is always the first in array. One of my examples for the last category that is bound to product: {foreach from=Product::getProductCategories($product.id) item=catitem name=catname} {if $smarty.foreach.catname.last} {$catitem.name} {/if} {/foreach} but getProductCategories method gets only id_category, name, link_rewrite and id_lang. No matter the method I use - for example Category::getCategoryInformations - I cannot find a way to fetch whole category data, and get into meta data fields, even using category's ID. Does somebody know a way of getting whole category meta data from those bound to a product? Multilang solution isn't needed, but would be appreciated. I'm not even sure if it is possible to do purely in theme templates without changing core files nor using overrides.
  7. Your simple module works perfectly fine. I wanted to add a custom text block to carrier /templates/checkout/_partials/steps/shipping.tpl but I thought that using hookDisplayAfterCarrier or hookDisplayBeforeCarrier would be simpler, as I could grab a custom html widget to have multilanguage managed text and insert above/below carrier info in checkout process. But after adding proper installation and trying to show custom text within function public function hookDisplayAfterCarrier() { return "customtext"; } I don't get any text in carrier information window I'm not sure if I use proper hook, nor if I'm even able to simply insert a text using such hook? Or should I prepare a view template file in this module? Could you give me a hand with this? edit: dropped trying to hook text within this module, and stay with using only html widget
  8. To nie jest tak, że nikt nie używa bo nie chce. Presta1.7 ma wbudowane wsparcie wyłącznie dla memcached; pozostałe opcje pomijam. Poza jednym modułem xtremecache są wyłącznie odpłatne. A ten darmowy moduł działa w magiczny sposób, bo był tworzony pod 1.5 i jeden z forumowiczów zaktualizował tylko funkcje aby działały w v1.7. Ja nie zaryzykuję kupna modułu, który nie wiem czy w ogóle zadziała a jak zadziała to nie będzie się gryzł z prestą, a co moduł w tej platformie to kolejne utrapienie. Jeśli masz jakieś doświadczenia z PS+redis to chętnie powiększę horyzont wiedzy w tym temacie. Bo niegdysiejsze choć bardzo płytkie testy wykazały, że redis ciut szybszy. Ale to dość subiektywna opinia.
  9. I'm wondering how can I display a hook in template file using default method, but pass to it parameters to get the desired block. I have couple html blocks assigned to certain hooks, lets assume they stay within displayNav hook. They have automatically asigned ID during creation, and possible position value. What I'd like to achieve with {hook h='displayNav'} is to pass an ID or position value to get the desired html block. I don't know if default {hook} smarty constant allows to pass more paramaters than only hook name. Like for example {hook h='displayNav' id=1} or {hook h='displayNav' position=1} I was looking for such info or similar question but seems that I can't find the function responsible for it, and make an override or use builtin parameters. Anyone could enlighten me a bit?
  10. Hello I found your module and wanted to check if it works in the same way as my own small, raw module. Since you use the same methods: Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); I wonder it this solution really works. After launching this by invoking proper url or through cron, the /var/cache/prod isn't flushed, and all files inside remain. The only difference is index file that is being somehow refreshed or reindexed. Is that supposed to be so? According to clear cache button in backoffice this isn't working the same, as it doesn't flush the var/cache/[prod] directory. I'm wondering about adding a onliner bash script and invoke it through cron, or just delete the directory using php. But still I'm not sure how above mentioned methods work.
  11. I faced identical problem but haven't found any out of box solution. Oh well, a man needs sometimes to roll up his own sleeves 😎 A bit of debugging to check what sort of data we can get from product object, and voilla. Simple as it's possible. We just need to check if product id matches the one in cart along with its attribute, thus: {if $cart_product['id_product'] == $product.id && $cart_product['id_product_attribute'] == $product.id_product_attribute}
  12. Hi After couple changes in your published code I've managed to limit all products of the same type in cart to a fixed value. Works tremendously, but that's one of needed changes to implement to make it fully working. In next step I need to hide that + - buttons but that's an easy peasy thingy. The problem I'm facing is a notice in modal window after adding the product that mentions: "Product successfully added to your cart". Do you have any ideas how could I change content of this notice, or even better disable the cart button once a visitor adds the product to cart? I checked the function that blocks the button after raising the product's quantity over its stock value, but that's not so easy to trigger as I thought. edit: k, I've found a great tutor solving my problem in 100% those interested in solution might find it on below page: myprestamodules.com/blog/prestashop-17/mark-product-is-already-in-cart-in-prestashop-17.html
×
×
  • Create New...