Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shipping] Ability to hide carrier from checkout #1693

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function findForStore(StoreInterface $store): array
return $this->createQueryBuilder('o')
->innerJoin('o.stores', 's')
->andWhere('s.id = :store')
->andWhere('o.hideFromCheckout = 0')
->setParameter('store', [$store])
->getQuery()
->getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function load(ObjectManager $manager): void
$carrier = $this->container->get('coreshop.factory.carrier')->createNew();
$carrier->setIdentifier('Standard');
$carrier->setTrackingUrl('https://coreshop.at/track/%s');
$carrier->setHideFromCheckout(false);
$carrier->setIsFree(false);
$carrier->setTaxRule($this->getReference('taxRule'));
$carrier->addStore($defaultStore);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace CoreShop\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20210720212955 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add `hideFromCheckout` field in `coreshop_carrier`';
}

public function up(Schema $schema): void
{
if (!$schema->getTable('coreshop_carrier')->hasColumn('hideFromCheckout')) {
$this->addSql('
ALTER TABLE coreshop_carrier ADD hideFromCheckout TINYINT(1) NOT NULL AFTER trackingUrl;
');
}
}

public function down(Schema $schema): void
{
if ($schema->getTable('coreshop_carrier')->hasColumn('hideFromCheckout')) {
$this->addSql('
ALTER TABLE coreshop_carrier DROP hideFromCheckout;
');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder
->add('identifier', TextType::class)
->add('trackingUrl', TextType::class)
->add('hideFromCheckout', CheckboxType::class)
->add('isFree', CheckboxType::class)
->add('logo', PimcoreAssetChoiceType::class)
->add('taxCalculationStrategy', ShippingTaxCalculationStrategyChoiceType::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<field name="identifier" column="identifier" nullable="true"/>
<field name="trackingUrl" column="trackingUrl" nullable="true"/>
<field name="hideFromCheckout" column="hideFromCheckout" type="boolean"/>
<field name="isFree" column="isFree" type="boolean"/>
<field name="logo" column="logo" type="pimcoreAsset" nullable="true"/>
<field name="taxCalculationStrategy" column="taxCalculationStrategy" nullable="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ CoreShop\Component\Shipping\Model\Carrier:
expose: true
type: string
groups: [Detailed]
hideFromCheckout:
expose: true
type: boolean
groups: [Detailed]
isFree:
expose: true
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ CoreShop\Component\Shipping\Model\Carrier:
- NotBlank: { groups: [coreshop] }
isFree:
- Type: { type: boolean }
hideFromCheckout:
- Type: { type: boolean }
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ coreshop.carrier.item = Class.create(coreshop.resource.item, {
valueField: 'value',
displayField: 'label',
store: pimcore.globalmanager.get('coreshop_shipping_tax_calculation_strategies')
},
{
xtype: 'checkbox',
name: 'hideFromCheckout',
fieldLabel: t('coreshop_carrier_hideFromCheckout'),
value: this.data.hideFromCheckout
}
]
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coreshop_carrier_label: 'Label'
coreshop_carrier_trackingUrl: 'Paketverfolgungs-Url'
coreshop_carriers_stop_propagation: 'Wenn ungültig, weitere Verarbeitung unterbrechen'
coreshop_carrier_shipping_locations_and_costs: 'Versand-Gebiete und Kosten'
coreshop_carrier_hideFromCheckout: 'Hide from checkout'
coreshop_carrier_isFree: 'Gratis Versand'
coreshop_carriers_shipping_rule: 'Versandregel'
coreshop_action_price: 'Preis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coreshop_carrier_label: 'Label'
coreshop_carrier_trackingUrl: 'Tracking Url'
coreshop_carriers_stop_propagation: 'Stop Propagation if invalid'
coreshop_carrier_shipping_locations_and_costs: 'Shipping locations and costs'
coreshop_carrier_hideFromCheckout: 'Hide from checkout'
coreshop_carrier_isFree: 'Free Shipping'
coreshop_carriers_shipping_rule: 'Shipping Rule'
coreshop_action_price: 'Price'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coreshop_carrier_label: 'Etichetta'
coreshop_carrier_trackingUrl: 'URL di tracciamento'
coreshop_carriers_stop_propagation: 'Interrompi la propagazione se non valida'
coreshop_carrier_shipping_locations_and_costs: 'Località e costi di spedizione'
coreshop_carrier_hideFromCheckout: 'Nascondi dal checkout'
coreshop_carrier_isFree: 'Spedizione gratuita'
coreshop_carriers_shipping_rule: 'Regola di spedizione'
coreshop_action_price: 'Prezzo'
Expand Down
15 changes: 15 additions & 0 deletions src/CoreShop/Component/Shipping/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Carrier extends AbstractResource implements CarrierInterface
*/
private $trackingUrl;

/**
* @var bool
*/
private $hideFromCheckout = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -116,6 +121,16 @@ public function setTrackingUrl($trackingUrl)
$this->trackingUrl = $trackingUrl;
}

public function getHideFromCheckout()
{
return $this->hideFromCheckout;
}

public function setHideFromCheckout($hideFromCheckout)
{
$this->hideFromCheckout = $hideFromCheckout;
}

public function getIsFree()
{
return $this->isFree;
Expand Down
10 changes: 10 additions & 0 deletions src/CoreShop/Component/Shipping/Model/CarrierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public function getIsFree();
*/
public function setIsFree($isFree);

/**
* @return bool
*/
public function getHideFromCheckout();

/**
* @param bool $hideFromCheckout
*/
public function setHideFromCheckout($hideFromCheckout);

/**
* @return Asset|null
*/
Expand Down