Giter Club home page Giter Club logo

commerce-bundles's Introduction

Bundles plugin for Craft CMS 3.x

Create a bundle purchasable of existing commerce products.

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require webdna/commerce-bundles
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Bundles.

Bundles Overview

Bundles allows you to create a bundle containing a combination of different products (or a single product with multiple quantities). Set an overall price for the bundle, giving you the option to offer a discount or promotion (for example 3 for 2).

Configuring Bundles

Bundle Types

Bundle Types is where you can define the template and URL for bundle. You can add any custom fields to your bundle types.

Screenshot

Screenshot

Bundles

Here is where you setup your Bundle, select the products and quantities of the product that make up the Bundle. Similar to Commerce Products add an SKU and price for the Bundle.

Screenshot

Using Bundles

You can access your bundles from your templates using a bundle query:

{% set myBundleQuery = craft.bundles() %}

When you access a bundle directly via it's URL the bundle variable is available.


Available Methods

Once you have your bundle there are methods for accessing the bundles products and quanities, and for checking stock.

Products

{# Returns an array of the bundles products (Commerce Variant object) #}

bundle.getProducts()

Quantities

{# Returns an array of quantites with the key set to the variantId #}

bundle.getQtys()

Stock

{# checks to see if all the products in the bundle have stock #}

bundle.hasStock()

Fields

Bundles also includes a Bundles field type.

Screenshot

Example

Display a list of products and quantities that make up the bundle.

{% for id,qty in bundle.getQtys() %}
   {{ qty ~ ' x ' ~ craft.variants.id(id).one.description }}
{% endfor %}

Brought to you by webdna

commerce-bundles's People

Contributors

charliegentle avatar gijsstegehuis avatar mcjackson18 avatar samuelbirch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

commerce-bundles's Issues

Beta version stability

This plugin is still showing as a beta release, but is it considered stable now for Craft 4 sites?

Fix Composer 2 compatibility

When installing this plugin with Composer 1, the following deprecation notice is output:

Deprecation Notice: Class kuriousagency\commerce\bundles\assetbundles\Bundles\BundlesAsset located in ./vendor/kuriousagency/commerce-bundles/src/assetbundles/bundles/BundlesAsset.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0.

Composer 2 was released on October 24, and is now the default version that will be installed, so it’s critical that this gets resolved ASAP, or people will start getting Class not found errors.

To fix, run the following command:

> git mv src/assetbundles/bundles src/assetbundles/Bundles

Then commit your change and tag a new release.

(Note that you must use the git mv command, as Git tends to not notice case-sensitive file renames otherwise.)

Get related bundles from on a product page

Hi,

I have a product page which displays a dropdown of different variants, in order to add the product to the cart.

These variants are also sometimes a part of a bundle, so I'd like to display the related bundles on this page too, but I can't figure out how to do it.

Any ideas would be appreciated.

I've tried the following (looping through the variants) without any luck.

                        {% set bundles = bundles.relatedTo({
                            sourceElement: variant,
                            field: 'purchaseables.purchasableId'
                        }).all() %}

Invalid purchasable ID

I have Craft 4.7, Commerce 4.4 and Commerce Bundles 2.0.0-beta.7 installed. When I click on add to basket on a bundle I get the following error "Invalid purchasable ID". I'll paste my basket code below as I might be missing something that isn't documented.

{% for bundle in craft.bundles.purchasables(product.variants).with(['bundleImage']).all()|unique %}

{{ csrfInput() }} {{ actionInput('commerce/cart/update-cart') }} {{ hiddenInput('purchasableId', bundle.id) }}
    <div class="row">
        <div class="col-xs-12 col-md-6 col-md-push-6">
            {% if bundle.bundleImage is defined and bundle.bundleImage|length %}
                <img src="{{ bundle.bundleImage[0].getUrl() }}" alt="{{ bundle.bundleImage[0].title }}" class="books-bundles-bundle-image">
            {% endif %}
        </div>

        <div class="col-xs-12 col-md-6 col-md-pull-6">
            <h3>
                {{ bundle.title }}
            </h3>

            <div class="row row-flex items-end">
                <div class="col-xs-12 col-md-5">
                    <div class="books-bundles-bundle-price">
                        <p>
                            Total price:
                        </p>

                        <h4>
                            &pound;{{ bundle.price|number_format(2) }}
                        </h4>
                    </div>
                </div>

                <div class="col-xs-12 col-md-7">
                    <button id="bundle-to-cart" type="submit" class="bundle-submit">
                        Add all to basket
                    </button>
                </div>
            </div>
        </div>
    </div>
</form>

{% set bundlePrice = bundlePrice + bundle.price %}
{% endfor %}

Any help would greatly be appriciated.

Error on save, after upgrade, "must be of the type float, string returned"

Since upgrading to the latest commerce bundles we have been getting the following error while trying to save a bundle:

Return value of kuriousagency\commerce\bundles\elements\Bundle::getPrice() must be of the type float, string returned

For the purpose of saving the bundle we've made a temporary fix to line 460 of Bundle.php:

return floatvar($this->price);

Can you please advise if there is a proper way to address this issue, or if there will be an update available?

Versions:

Commerce Bundles: 1.2.1
Craft Commerce Pro: 3.2.14.1
Craft: 3.6.2
PHP: 7.4.14

How to get bundles related to a product

I feel like I must be missing something... I don't want to show bundles on their own page, I want to show any bundles that include the product currently being viewed. Getting the bundles that include the current product looks like this:

{# Get the default product variant #}
{% set variant = product.defaultVariant %}
{# Get any bundles associated with this variant #}
{% set bundles = [] %}
{% set allBundles = craft.bundles() ?? null %}
{% for bundle in allBundles.all() %}
	{% set bundleProducts = bundle.getProducts() %}
	{% for bundleProduct in bundleProducts %}
		{% if bundleProduct.id == variant.id %}
			{% set bundles = bundles|merge([bundle]) %}
		{% endif %}
	{% endfor %}
{% endfor %}

That seems like a very long way to go. I see there is no record for the bundles in the craft_relations table, so I can't use

{% set bundles = craft.bundles().relatedTo(variant) ?? null %}

but something short like that would be desired. Is there a better way?

Postgres error after updating to 1.2

The filed db/BundleQuery.php is throwing an error when running the inner join command.

Instead of using the bundles_purchasables.bundeId field it is trying to use "bundleid" (all lower case).
The reason for that is because the field name is not between quotes and Postgres is changing it.
In order to avoid it I made a small adjustment to the file on line 188 with this change:

Original:
"bundles_bundles.id = bundles_purchasables.bundleId"

Update
'bundles_bundles.id = bundles_purchasables."bundleId"'

System Info:

PHP version | 7.4.13
OS version | Linux 4.19.121-linuxkit
Database driver & version | PostgreSQL 12.5

Craft edition & version | Craft Pro 3.5.17.1
Craft Commerce | 3.2.13.2
Bundles | 1.2

yii\base\InvalidConfigException: Failed to instantiate component or class

I have been getting an error on production when I go to the bundles plugin, but not on dev.

Craft CMS 3.5.11.1
Bundles 1.1.4

Local is php 7.3.15
Production is php 7.4.11

Any idea what this error means?

Next yii\base\InvalidConfigException: Failed to instantiate component or class "kuriousagency\commerce\bundles\assetbundles\bundles\BundlesAsset". in /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/di/Container.php:455
Stack trace:
#0 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/di/Container.php(380): yii\di\Container->getDependencies('kuriousagency\\c...')
#1 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/di/Container.php(165): yii\di\Container->build('kuriousagency\\c...', Array, Array)
#2 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('kuriousagency\\c...', Array, Array)
#3 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/web/AssetManager.php(264): yii\BaseYii::createObject(Array)
#4 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/web/AssetManager.php(237): yii\web\AssetManager->loadBundle('kuriousagency\\c...', Array, true)
#5 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/web/View.php(287): yii\web\AssetManager->getBundle('kuriousagency\\c...')
#6 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Extension/CoreExtension.php(1499): yii\web\View->registerAssetBundle('kuriousagency\\c...')
#7 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/helpers/Template.php(92): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\web\View), 'registerAssetBu...', Array, 'method', false, false)
#8 /srv/users/scradmin/apps/production/storage/runtime/compiled_templates/8c/8cecc20069d7eea9227d7bfb2038b047de843f83154739e1ee336f778d9a963c.php(96): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\web\View), 'registerAssetBu...', Array, 'method')
#9 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Template.php(405): __TwigTemplate_e9210a7d670ee12fade609d193f1fea50d2c47707b56f702aa540d8afcca5a18->doDisplay(Array, Array)
#10 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#11 /srv/users/scradmin/apps/production/storage/runtime/compiled_templates/c6/c64ec0ecb1bd71dae8d92f328a72937215c14ad327baad6526860a66b6e99df9.php(38): Twig\Template->display(Array)
#12 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Template.php(405): __TwigTemplate_39ec66be56c751b70eb3fc1f098dbbc180edba51e11cc13ebcd923d88db11724->doDisplay(Array, Array)
#13 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#14 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#15 /srv/users/scradmin/apps/production/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#16 /srv/users/scradmin/apps/production/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#17 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/View.php(392): Twig\Environment->render('commerce-bundle...', Array)
#18 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/View.php(453): craft\web\View->renderTemplate('commerce-bundle...', Array)
#19 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/Controller.php(251): craft\web\View->renderPageTemplate('commerce-bundle...', Array, 'cp')
#20 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/controllers/TemplatesController.php(100): craft\web\Controller->renderTemplate('commerce-bundle...', Array)
#21 [internal function]: craft\controllers\TemplatesController->actionRender('commerce-bundle...', Array)
#22 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#23 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#24 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/Controller.php(189): yii\base\Controller->runAction('render', Array)
#25 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#26 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/Application.php(285): yii\base\Module->runAction('templates/rende...', Array)
#27 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#28 /srv/users/scradmin/apps/production/vendor/craftcms/cms/src/web/Application.php(270): yii\web\Application->handleRequest(Object(craft\web\Request))
#29 /srv/users/scradmin/apps/production/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /srv/users/scradmin/apps/production/public_html/index.php(21): yii\base\Application->run()
#31 {main}
2020-11-03 20:49:36 [-][1][cf243396014b66b91edfb57a49f12323][info][application] $_GET = [
    'p' => 'admin/commerce-bundles'
]

Add isBundle()

Is it possible to add a variable I can use in places like the shopping cart:

{% for item in cart.lineItems %}
    {%if item.isBundle() %}
        do something...
    {% endif %}
{% endfor %}

edit: Both Events and Gift Vouchers by Verbb have this variable, if you need some direction on how to implement.

Events

Gift Vouchers

Bundle::hasUnlimitedStock

I've got a commerce site using bundles that uses hasUnlimitedStock for quite a bit of logic throughout the checkout process. It appears that Bundle elements don't have this property currently, which, when checking out, allows the order to be placed, but throws this error and doesn't take the customer from the payment page to the order summary page.

Getting unknown property: kuriousagency\commerce\bundles\elements\Bundle::hasUnlimitedStock

View example

By hacking the elements/Bundle.php file and adding public $hasUnlimitedStock; after line 75, the error goes away and order completes as expected. Is it possible you could add this property so I don't have to hack future versions of this plugin?

TypeError when saving new product bundle

Hello,
When trying to save any new product bundle, there is an Type error saying that the return value of BundlesController::actionSave() must be of type yiilweb\Response, but null returned (please see screenshot attached).
Is anyone else have encountered the same issue, any workaround to fix this?
Thanks!

Plugin version: 2.0.0-beta.3
Craft version: 4.5.7

Screenshot 2023-10-20 at 14 59 00

Craft Commerce 4

Do you have any intention or timeline of updating this plugin for Craft Commerce 4?

Bundle not getting saved values

Once the bundle created, all other fields layout did save, but cannot display in the Edit page in CMS.

Added following before the form render works in BundlesController
if($bundleId&&!$bundle) $bundle = Bundle::findOne($bundleId);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.