Skip to content

Commit

Permalink
v1.0.4 Added is_qwqer_available attribute to products
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew committed Mar 6, 2024
1 parent 7b68591 commit 2b66725
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Model/Carrier/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public function collectRates(RateRequest $request)
if (!$this->getConfigFlag('active')) {
return false;
}
$available = $this->checkAvailableProduct();
if(!$available) {
return false;
}

/** @var Method $method */
$method = $this->rateMethodFactory->create();
Expand All @@ -130,6 +134,25 @@ public function collectRates(RateRequest $request)
return $result;
}

/**
* @return false|void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function checkAvailableProduct()
{
$items = $this->_checkoutSession->getQuote()->getItems();
foreach ($items as $item) {
$isAvailable = intval($item->getProduct()->getData(ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY));
if($isAvailable) {
continue;
} else {
return false;
}
}
return true;
}

/**
* Calculate Price
*
Expand Down
24 changes: 24 additions & 0 deletions Model/Carrier/ScheduledToDoor.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public function collectRates(RateRequest $request)
return false;
}

$available = $this->checkAvailableProduct();
if(!$available) {
return false;
}

/** @var Method $method */
$method = $this->rateMethodFactory->create();

Expand All @@ -130,6 +135,25 @@ public function collectRates(RateRequest $request)
return $result;
}

/**
* @return false|void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function checkAvailableProduct()
{
$items = $this->_checkoutSession->getQuote()->getItems();
foreach ($items as $item) {
$isAvailable = intval($item->getProduct()->getData(ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY));
if($isAvailable) {
continue;
} else {
return false;
}
}
return true;
}

/**
* Calculate Price
*
Expand Down
24 changes: 24 additions & 0 deletions Model/Carrier/ScheduledToParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public function collectRates(RateRequest $request)
return false;
}

$available = $this->checkAvailableProduct();
if(!$available) {
return false;
}

/** @var Method $method */
$method = $this->rateMethodFactory->create();

Expand All @@ -130,6 +135,25 @@ public function collectRates(RateRequest $request)
return $result;
}

/**
* @return false|void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function checkAvailableProduct()
{
$items = $this->_checkoutSession->getQuote()->getItems();
foreach ($items as $item) {
$isAvailable = intval($item->getProduct()->getData(ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY));
if($isAvailable) {
continue;
} else {
return false;
}
}
return true;
}

/**
* Calculate Price
*
Expand Down
1 change: 1 addition & 0 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ConfigurationProvider
public const DELIVERY_ORDER_REAL_TYPE = "ExpressDelivery";
public const DELIVERY_ORDER_REAL_TYPE_DOOR = "ScheduledDelivery";
public const DELIVERY_ORDER_REAL_TYPE_PARCEL = "OmnivaParcelTerminal";
public const ATTRIBUTE_CODE_AVAILABILITY = 'is_qwqer_available';

/**
* @var ScopeConfigInterface
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

##### For Magento / Adobe Commerce 2.4.x

### How to Install Magento SMTP Extension
### How to QWQER Express Delivery Extension

##### Install the extension using a zipped file

Expand All @@ -26,12 +26,15 @@ After successfully placed order, you can print shipping label in admin panel dur

QWQER Order id saved in database table "sales_order"

### Main Configurations

Need setup store owner information:
* Stores -> General -> Store Email Addresses -> General Contact -> Sender Email
* Stores -> General -> Store Information -> Store Name
* Stores -> General -> Store Information -> Store Phone Number

### Main Configurations
QWQER delivery is available for products only:
- "Available Qwqer Delivery" product attribute value is "Yes"

#### QWQER Express

Expand Down
109 changes: 109 additions & 0 deletions Setup/Patch/Data/AddQwqerIsAvailableAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace Qwqer\Express\Setup\Patch\Data;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Qwqer\Express\Provider\ConfigurationProvider;
class AddQwqerIsAvailableAttribute implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var \Magento\Framework\Setup\ModuleDataSetupInterface
*/
private ModuleDataSetupInterface $moduleDataSetup;

/**
* @var \Magento\Eav\Setup\EavSetupFactory
*/
private EavSetupFactory $eavSetupFactory;

/**
* @param EavSetupFactory $eavSetupFactory
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(
EavSetupFactory $eavSetupFactory,
ModuleDataSetupInterface $moduleDataSetup
)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* @inheritdoc
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();

/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$attributeId = $eavSetup->getAttributeId(
Product::ENTITY,
ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY
);

if (!$attributeId) {
$eavSetup->addAttribute(
Product::ENTITY,
ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY,
[
'type' => 'int',
'label' => 'Available Qwqer Delivery',
'input' => 'boolean',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => Attribute::SCOPE_WEBSITE,
'visible' => true,
'frontend' => '',
'required' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'group' => 'General',
'position' => 60
]
);
}

$this->moduleDataSetup->getConnection()->endSetup();
}

/**
* @inheritdoc
*/
public function revert()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(Product::ENTITY, ConfigurationProvider::ATTRIBUTE_CODE_AVAILABILITY);
$this->moduleDataSetup->getConnection()->endSetup();
}

/**
* @inheritdoc
*/
public static function getDependencies(): array
{
return [];
}

/**
* @inheritdoc
*/
public function getAliases(): array
{
return [];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"magento/module-store": "101.0.*"
},
"type": "magento2-module",
"version": "1.0.3",
"version": "1.0.4",
"autoload": {
"files": [
"registration.php"
Expand Down
6 changes: 6 additions & 0 deletions etc/catalog_attributes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
<group name="quote_item">
<attribute name="is_qwqer_available"/>
</group>
</config>

0 comments on commit 2b66725

Please sign in to comment.