magento Url is not working for first time - magento

when we open a site : http://ab1.domain.com/
for first time in browser, it will redirect to below url
http://ab1.domain.com/://index.php/? & give 404 Not Found 1
://index.php/? is adding as suffix. but if we open 2nd time, than its working fine.
its multi-store site, when we disabled all stores also still problem is there.
It was problem with custom module , we are using this module for displaying respective currency based on country.
Data.php
<?php
/**
* Atwix
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* #category Atwix Mod
* #package Atwix_Ipstoreswitcher
* #author Atwix Core Team
* #copyright Copyright (c) 2014 Atwix (http://www.atwix.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/* app/code/local/Atwix/Ipstoreswitcher/Helper/Data.php */
class Atwix_Ipstoreswitcher_Helper_Data extends Mage_Core_Helper_Abstract
{
const DEFAULT_STORE = 'India';
/**
* countries to store relation
* default is English
* #var array
*/
protected $_countryToStore = array(
'IN' => 'India',
'US' => 'USA',
'FR' => 'France',
'AR' => 'US dollar [$]',
// 'BO' => 'US dollar [$]'
);
/**
* get store view name by country
* #param $country
* #return bool
*/
public function getStoreByCountry($country)
{
if (isset($this->_countryToStore[$country])) {
return $this->_countryToStore[$country];
}
return self::DEFAULT_STORE;
}
}
config.xml
<config>
<modules>
<Atwix_Ipstoreswitcher>
<version>1.0.0</version>
</Atwix_Ipstoreswitcher>
</modules>
<global>
<helpers>
<atwix_ipstoreswitcher>
<class>Atwix_Ipstoreswitcher_Helper</class>
</atwix_ipstoreswitcher>
</helpers>
<models>
<atwix_ipstoreswitcher>
<class>Atwix_Ipstoreswitcher_Model</class>
</atwix_ipstoreswitcher>
</models>
</global>
<frontend>
<events>
<controller_action_postdispatch>
<observers>
<atwix_ipstoreswitcher>
<class>atwix_ipstoreswitcher/observer</class>
<method>controllerActionPostdispatch</method>
</atwix_ipstoreswitcher>
</observers>
</controller_action_postdispatch>
</events>
</frontend>
</config>
Observer.php
class Atwix_Ipstoreswitcher_Model_Observer
{
/**
* redirects customer to store view based on GeoIP
* #param $event
*/
public function controllerActionPostdispatch($event)
{
$cookie = Mage::getSingleton('core/cookie');
if ($cookie->get('geoip_processed') != 1) {
$geoIPCountry = Mage::getSingleton('geoip/country');
$countryCode = $geoIPCountry->getCountry();
if ($countryCode) {
$storeName = Mage::helper('atwix_ipstoreswitcher')->getStoreByCountry($countryCode);
if ($storeName) {
$store = Mage::getModel('core/store')->load($storeName, 'name');
if ($store->getName() != Mage::app()->getStore()->getName()) {
$event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));
}
}
}
$cookie->set('geoip_processed', '1', time() + 86400, '/');
}
}
}
Edit
What i tried is i replaced $store->getCurrentUrl(false) by Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_forced_secure' => true)) than url problem is solved. but module feature is not working.

You can can look(search) for ://index.php/? in your database and can make changes in database and there you will get an extension name as well from where it comes or from core files.

<?php
/**
* Atwix
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* #category Atwix Mod
* #package Atwix_Ipstoreswitcher
* #author Atwix Core Team
* #copyright Copyright (c) 2014 Atwix (http://www.atwix.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/* app/code/local/Atwix/Ipstoreswitcher/Model/Observer.php */
class Atwix_Ipstoreswitcher_Model_Observer
{
/**
* redirects customer to store view based on GeoIP
* #param $event
*/
public function controllerActionPostdispatch($event)
{
$geoIP = Mage::getSingleton('geoip/country');
$cnCode = $geoIP->getCountry();
// echo $cnCode='IN';
switch ($cnCode) {
case "US": {
Mage::app()->setCurrentStore('default');
break;
}
case "IN": {
Mage::app()->setCurrentStore('usa');
break;
}
case "CA": {
Mage::app()->setCurrentStore('lca');
break;
}
default: {
Mage::app()->setCurrentStore('default');
break;
}
echo Mage::app()->getCurrentStore();
}
}
}

Related

Add custom fields to payment method

I have duplicated the checkmo doing the following below
Duplicate it as follows checkmo to checkmonew. I am using Magento version 1.9.3
Step 1 : mage/payment/block/forms + info : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 2 : mage/payment/etc/config.xml + system.xml : duplicate the checkmo parts (and rename it to checkmonew)
Step 3 : mage/payment/model/method : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 4 : design/adminhtml/default/default/template/payment/form + info : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 5 : design/frontend/base/default/template/payment/form + info :
duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Now, this all seems to work but for some reason only on the backend but checkmo shows in the frontend, no problem.
I also want to add cc type option in the new payment method. I would prefer it not to be a drop down just a selection from the list of cards which are in cc type which is used in the CC payment method.
Thanks
admin inmage
code
block - info
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Payment_Block_Info_Cashmonew extends Mage_Payment_Block_Info
{
protected $_payableTo;
protected $_mailingAddress;
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/info/Cashmonew.phtml');
}
/**
* Enter description here...
*
* #return string
*/
public function getPayableTo()
{
if (is_null($this->_payableTo)) {
$this->_convertAdditionalData();
}
return $this->_payableTo;
}
protected function _prepareSpecificInformation($transport = null)
{
if (null !== $this->_paymentSpecificInformation) {
return $this->_paymentSpecificInformation;
}
$transport = parent::_prepareSpecificInformation($transport);
$data = array();
if ($ccType = $this->getCcTypeName()) {
$data[Mage::helper('payment')->__('Credit Card Type')] = $ccType;
}
if ($this->getInfo()->getCcLast4()) {
$data[Mage::helper('payment')->__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
}
if (!$this->getIsSecureMode()) {
if ($ccSsIssue = $this->getInfo()->getCcSsIssue()) {
$data[Mage::helper('payment')->__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
}
$year = $this->getInfo()->getCcSsStartYear();
$month = $this->getInfo()->getCcSsStartMonth();
if ($year && $month) {
$data[Mage::helper('payment')->__('Switch/Solo/Maestro Start Date')] = $this->_formatCardDate($year, $month);
}
}
return $transport->setData(array_merge($data, $transport->getData()));
}
/**
* Enter description here...
*
* #return string
*/
public function getMailingAddress()
{
if (is_null($this->_mailingAddress)) {
$this->_convertAdditionalData();
}
return $this->_mailingAddress;
}
/**
* Enter description here...
*
* #return Mage_Payment_Block_Info_Cashmonew
*/
protected function _convertAdditionalData()
{
$details = false;
try {
$details = Mage::helper('core/unserializeArray')
->unserialize($this->getInfo()->getAdditionalData());
} catch (Exception $e) {
Mage::logException($e);
}
if (is_array($details)) {
$this->_payableTo = isset($details['payable_to']) ? (string) $details['payable_to'] : '';
$this->_mailingAddress = isset($details['mailing_address']) ? (string) $details['mailing_address'] : '';
} else {
$this->_payableTo = '';
$this->_mailingAddress = '';
}
return $this;
}
public function toPdf()
{
$this->setTemplate('payment/info/pdf/Cashmonew.phtml');
return $this->toHtml();
}
}
block - form
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Payment_Block_Form_Cashmonew extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/form/Cashmonew.phtml');
}
}
/**
* Retrieve availables credit card types
*
* #return array
*/
public function getCcAvailableTypes()
{
$types = $this->_getConfig()->getCcTypes();
if ($method = $this->getMethod()) {
$availableTypes = $method->getConfigData('cctypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach ($types as $code=>$name) {
if (!in_array($code, $availableTypes)) {
unset($types[$code]);
}
}
}
}
return $types;
}
etc - config
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<config>
<modules>
<Mage_Payment>
<version>1.6.0.0</version>
</Mage_Payment>
</modules>
<global>
<models>
<payment>
<class>Mage_Payment_Model</class>
</payment>
</models>
<resources>
<payment_setup>
<setup>
<module>Mage_Payment</module>
</setup>
</payment_setup>
</resources>
<blocks>
<payment>
<class>Mage_Payment_Block</class>
</payment>
</blocks>
<payment>
<checkmonew>
<types>
<AE>
<code>AE</code>
<name>American Express</name>
<order>0</order>
</AE>
<VI>
<code>VI</code>
<name>Visa</name>
<order>10</order>
</VI>
<MC>
<code>MC</code>
<name>MasterCard</name>
<order>20</order>
</MC>
<DI>
<code>DI</code>
<name>Discover</name>
<order>30</order>
</DI>
<SM>
<code>SM</code>
<name>Maestro/Switch</name>
<order>40</order>
</SM>
<SO>
<code>SO</code>
<name>Solo</name>
<order>45</order>
</SO>
<JCB>
<code>JCB</code>
<name>JCB</name>
<order>50</order>
</JCB>
<OT>
<code>OT</code>
<name>Other</name>
<order>1000</order>
</OT>
</types>
</checkmonew>
<groups>
<offline>Offline Payment Methods</offline>
</groups>
</payment>
<payment>
<cc>
<types>
<AE>
<code>AE</code>
<name>American Express</name>
<order>0</order>
</AE>
<VI>
<code>VI</code>
<name>Visa</name>
<order>10</order>
</VI>
<MC>
<code>MC</code>
<name>MasterCard</name>
<order>20</order>
</MC>
<DI>
<code>DI</code>
<name>Discover</name>
<order>30</order>
</DI>
<SM>
<code>SM</code>
<name>Maestro/Switch</name>
<order>40</order>
</SM>
<SO>
<code>SO</code>
<name>Solo</name>
<order>45</order>
</SO>
<JCB>
<code>JCB</code>
<name>JCB</name>
<order>50</order>
</JCB>
<OT>
<code>OT</code>
<name>Other</name>
<order>1000</order>
</OT>
</types>
</cc>
<groups>
<offline>Offline Payment Methods</offline>
</groups>
</payment>
<events>
<sales_order_save_before>
<observers>
<payment_sales_order_save_before>
<class>payment/observer</class>
<method>salesOrderBeforeSave</method>
</payment_sales_order_save_before>
</observers>
</sales_order_save_before>
<sales_order_payment_save_before>
<observers>
<payment_before_save>
<class>payment/observer</class>
<method>beforeOrderPaymentSave</method>
</payment_before_save>
</observers>
</sales_order_payment_save_before>
<sales_order_status_unassign_before>
<observers>
<payment_order_status_unassign_before>
<class>payment/observer</class>
<method>beforeSalesOrderStatusUnassign</method>
</payment_order_status_unassign_before>
</observers>
</sales_order_status_unassign_before>
</events>
</global>
<frontend>
<translate>
<modules>
<Mage_Payment>
<files>
<default>Mage_Payment.csv</default>
</files>
</Mage_Payment>
</modules>
</translate>
<events>
<catalog_product_type_prepare_full_options>
<observers>
<payment_recurring_profile_prepare_options>
<class>payment/observer</class>
<method>prepareProductRecurringProfileOptions</method>
</payment_recurring_profile_prepare_options>
</observers>
</catalog_product_type_prepare_full_options>
</events>
<layout>
<updates>
<payment module="Mage_Payment">
<file>payment.xml</file>
</payment>
</updates>
</layout>
</frontend>
<adminhtml>
<translate>
<modules>
<Mage_Payment>
<files>
<default>Mage_Payment.csv</default>
</files>
</Mage_Payment>
</modules>
</translate>
</adminhtml>
<default>
<payment>
<ccsave>
<active>1</active>
<cctypes>AE,VI,MC,DI</cctypes>
<model>payment/method_ccsave</model>
<order_status>pending</order_status>
<title>Credit Card (saved)</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</ccsave>
<checkmo>
<active>1</active>
<model>payment/method_checkmo</model>
<order_status>pending</order_status>
<title>Check / Money order</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</checkmo>
<checkmonew>
<active>1</active>
<cctypes>AE,VI,MC,DI</cctypes>
<model>payment/method_checkmonew</model>
<order_status>pending</order_status>
<title>Card POS</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</checkmonew>
<free>
<active>1</active>
<model>payment/method_free</model>
<order_status>pending</order_status>
<title>No Payment Information Required</title>
<allowspecific>0</allowspecific>
<sort_order>1</sort_order>
<group>offline</group>
</free>
<purchaseorder>
<active>0</active>
<model>payment/method_purchaseorder</model>
<order_status>pending</order_status>
<title>Purchase Order</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</purchaseorder>
<banktransfer>
<active>0</active>
<model>payment/method_banktransfer</model>
<order_status>pending</order_status>
<title>Bank Transfer Payment</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</banktransfer>
<cashondelivery>
<active>0</active>
<model>payment/method_cashondelivery</model>
<order_status>pending</order_status>
<title>Cash On Delivery</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</cashondelivery>
</payment>
</default>
</config>

Magento2 Out of Stock Assosiated Products not showing in the dropdown options for Configurable Products

I am facing an issue with Magento2 and I am not sure whether it's a bug or not. I want to show Out of Stock Assosiated Products in the Configurable Product Dropdown.
In the admin settings, Stores -> Configuration -> Catalog -> Inventory -> Display out of stock products, this is already set to "Yes" but no luck.
I have tried several modules with integrating plugins and did a lot of research on this but could not find any solution for this.
Lets take an example - I have a Configurable Product with Child products Size - S , M , L and for instance L is out of stock. So currently I am able to see S and M in the dropdown options for my configurable product.
I want to see all the 3 Child products with the mark of "Out of Stock" like L - Out of Stock or something like that.
sorry for the late reply. I was really busy with different projects.
So for this, i used 1 module and did customized that based on my requirements. I am providing you all the files and folders so anyone who needs this, can upload the files.
Created a module - Jworks/ConfigurableProduct so the folder structure will be /app/code/Jworks/ConfigurableProduct
Create a file app/code/Jworks/ConfigurableProduct/registration.php and enter below code -
<?php
/**
*
* #category Jworks
* #package ConfigurableProduct
* #author Jitheesh V O <jitheesh#digitalboutique.co.uk>
* #copyright Copyright (c) 2018 Digital Boutique (http://www.digitalboutique.co.uk/)
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Jworks_ConfigurableProduct',
__DIR__
);
Create a file app/code/Jworks/ConfigurableProduct/composer.json and enter below code -
{
"name": "jworks/module-configurableproduct",
"description": "Jworks configurableproduct updates",
"require": {
"magento/module-catalog": "101.0.*"
},
"type": "magento2-module",
"version": "1.0.0",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Jworks\\ConfigurableProduct\\": ""
}
}
}
Create a file app/code/Jworks/ConfigurableProduct/etc/module.xml and enter below code -
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Jworks_ConfigurableProduct" setup_version="0.0.1">
<sequence>
<module name="Magento_ConfigurableProduct" />
</sequence>
</module>
</config>
Create a file app/code/Jworks/ConfigurableProduct/etc/di.xml and enter below code -
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\ConfigurableProduct\Model\ConfigurableAttributeData" type="Jworks\ConfigurableProduct\Model\Rewrite\ConfigurableAttributeData" />
</config>
Create a file app/code/Jworks/ConfigurableProduct/etc/frontend/di.xml and enter below code -
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder" type="Jworks\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder"/>
</type>
<type name="Magento\ConfigurableProduct\Model\AttributeOptionProvider">
<plugin name="Magento_ConfigurableProduct_Plugin_Model_AttributeOptionProvider" type="Jworks\ConfigurableProduct\Plugin\Model\AttributeOptionProvider"/>
</type>
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="changeAllowProductsBehaviour" type="Jworks\ConfigurableProduct\Model\ConfigurableProduct\Block\Product\View\Type\Configurable\Plugin" sortOrder="10" />
</type>
</config>
Create a file app/code/Jworks/ConfigurableProduct/Plugin/Model/AttributeOptionProvider.php and enter below code -
<?php
namespace Jworks\ConfigurableProduct\Plugin\Model;
class AttributeOptionProvider
{
public function afterGetAttributeOptions(\Magento\ConfigurableProduct\Model\AttributeOptionProvider $subject, array $result)
{
$optiondata=array();
foreach ($result as $option) {
if(isset($option['stock_status']) && $option['stock_status']==0){
$option['option_title'] = $option['option_title'].__(' - uitverkocht');
}
$optiondata[]=$option;
}
return $optiondata;
}
}
Create a file app/code/Jworks/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php and enter below code -
<?php
namespace Jworks\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute;
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
use Magento\Framework\DB\Select;
/**
* Plugin for OptionSelectBuilderInterface to add stock status filter.
*/
class InStockOptionSelectBuilder
{
/**
* CatalogInventory Stock Status Resource Model.
*
* #var Status
*/
private $stockStatusResource;
/**
* #param Status $stockStatusResource
*/
public function __construct(Status $stockStatusResource)
{
$this->stockStatusResource = $stockStatusResource;
}
/**
* Add stock status filter to select.
*
* #param OptionSelectBuilderInterface $subject
* #param Select $select
* #return Select
*
* #SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetSelect(OptionSelectBuilderInterface $subject, Select $select)
{
$select->joinInner(
['stock' => $this->stockStatusResource->getMainTable()],
'stock.product_id = entity.entity_id',
['stock.stock_status']
);
return $select;
}
}
Create a file app/code/Jworks/ConfigurableProduct/Model/Rewrite/ConfigurableAttributeData.php and enter below code -
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Model;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
/**
* Class ConfigurableAttributeData
* #api
* #since 100.0.2
*/
class ConfigurableAttributeData
{
/**
* Get product attributes
*
* #param Product $product
* #param array $options
* #return array
*/
public function getAttributesData(Product $product, array $options = [])
{
$defaultValues = [];
$attributes = [];
foreach ($product->getTypeInstance()->getConfigurableAttributes($product) as $attribute) {
$attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
if ($attributeOptionsData) {
$productAttribute = $attribute->getProductAttribute();
$attributeId = $productAttribute->getId();
$attributes[$attributeId] = [
'id' => $attributeId,
'code' => $productAttribute->getAttributeCode(),
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
'options' => $attributeOptionsData,
'position' => $attribute->getPosition(),
];
$defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
}
}
return [
'attributes' => $attributes,
'defaultValues' => $defaultValues,
];
}
/**
* #param Attribute $attribute
* #param array $config
* #return array
*/
protected function getAttributeOptionsData($attribute, $config)
{
$attributeOptionsData = [];
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData[] = [
'id' => $optionId,
'label' => $attributeOption['label'],
//'test' => $config[$attribute->getAttributeId()][$optionId],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: [],
];
}
return $attributeOptionsData;
}
/**
* #param int $attributeId
* #param Product $product
* #return mixed|null
*/
protected function getAttributeConfigValue($attributeId, $product)
{
return $product->hasPreconfiguredValues()
? $product->getPreconfiguredValues()->getData('super_attribute/' . $attributeId)
: null;
}
}
Create a file app/code/Jworks/ConfigurableProduct/Model/ConfigurableProduct/Block/Product/View/Type/Configurable/Plugin.php and enter below code -
<?php
namespace Jworks\ConfigurableProduct\Model\ConfigurableProduct\Block\Product\View\Type\Configurable;
class Plugin
{
/**
* getAllowProducts
*
* #param \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable $subject
*
* #return array
*/
public function beforeGetAllowProducts($subject)
{
if (!$subject->hasData('allow_products')) {
$products = [];
$allProducts = $subject->getProduct()->getTypeInstance()->getUsedProducts($subject->getProduct(), null);
foreach ($allProducts as $product) {
$products[] = $product;
}
$subject->setData('allow_products', $products);
}
return [];
}
}
And after all these, you can run all the commands for installing the Magento2 extension.
I hope anybody can get help with this.
open the file vendor\magento\module-catalog\Helper\Product.php
change
protected $_skipSaleableCheck = false;
to
protected $_skipSaleableCheck = true;

ZF2 fileupload not required with annotationbuilder

I'm stuck at a problem with ZendFramework 2, annotationbuilder and fileupload.
for at contact form i want user the choice to upload a file.
I got everything to work except the file upload, if there is no file a get the
error:
File was not uploaded
I'm using annotationbuilder to create the form. some annotations is cut out with a space for testing. but did not help.
the Annotation class:
<?php
/**
* #Annotation\Name("message")
* #Annotation\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
* #ORM\Entity
* #ORM\Table(name="contact_message")
*/
class Message {
/**
* #Annotation\Exclude()
*
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
* #var integer
*/
private $id;
/**
* #Annotation\Type("Zend\Form\Element\Select")
* #Annotation\Flags({"priority": 600})
* #Annotation\Required({"required":"true" })
* #Annotation\Filter({"name":"StringTrim"})
* # Annotation\Validator({"name":"StringLength"})
* #Annotation\Options({"label":"About:"})
* #Annotation\Attributes({"options":{"1":"PlaceHolder","2":"Test"}})
*
* #ORM\Column(type="string")
* #var String
*/
private $about;
/**
* #Annotation\Type("Zend\Form\Element\Text")
* #Annotation\Flags({"priority": 500})
* #Annotation\Required({"required":"true" })
* #Annotation\Filter({"name":"StripTags"})
* # Annotation\Validator({"name":"EmailAddress"})
* #Annotation\Options({"label":"Name:"})
* #Annotation\Attributes({"required": true,"placeholder": "Your name ... "})
*
* #ORM\Column(type="string")
* #var String
*/
private $name;
/**
* #Annotation\Type("Zend\Form\Element\Text")
* #Annotation\Flags({"priority": 500})
* #Annotation\Required({"required":"true" })
* #Annotation\Filter({"name":"StripTags"})
* # Annotation\Validator({"name":"EmailAddress"})
* #Annotation\Options({"label":"Subject:"})
* #Annotation\Attributes({"required": true,"placeholder": "Subject ... "})
*
* #ORM\Column(type="string")
* #var String
*/
private $subject;
/**
* #Annotation\Type("Zend\Form\Element\File")
* #Annotation\Flags({"priority": 500})
* # Annotation\Required({"required":false })
* # Annotation\Filter({"name":"StringTrim","filerenameupload":{"target": "./img","randomize":true}})
* # Annotation\Filter({"name":"StripTags"})
* # Annotation\Validator({"name":"StringLength"})
* #Annotation\Options({"label":"File:"})
* #Annotation\Attributes({"required": false})
*
* #ORM\Column(type="string")
* #var String
*/
private $file;
/**
* #Annotation\Type("Zend\Form\Element\Textarea")
* #Annotation\Flags({"priority": 500})
* # Annotation\Required({"required":"true" })
* #Annotation\Filter({"name":"StripTags"})
* # Annotation\Validator({"name":"EmailAddress"})
* #Annotation\Options({"label":"Message:"})
* #Annotation\Attributes({"required": true,"placeholder": "Message ... "})
*
* #ORM\Column(type="string")
* #var String
*/
private $message;
/**
* WARNING USING THESE IS NOT SAFE. there is no checking on the data and you need to know what
* you are doing when using these.
* But it a great function for lazy people ;)
*
* #param ANY $value
* #param ANY $key
* #return $value
*/
public function __set($value,$key){
return $this->$key = $value;
}
/**
* WARNING USING THESE IS NOT SAFE. there is no checking on the data and you need to know what
* you are doing when using these.
* But it a great function for lazy people ;)
*
* #param ANY $value
* #param ANY $key
* #return $value
*/
public function __get($key){
return $this->$key;
}
/**
* WARNING USING THESE IS NOT SAFE. there is no checking on the data and you need to know what
* you are doing when using these.
* This is used to exchange data from form and more when need to store data in the database.
* and again ist made lazy, by using foreach without data checks
*
* #param ANY $value
* #param ANY $key
* #return $value
*/
public function populate($array){
foreach ($array as $key => $var){
$this->$key = $var;
}
}
/**
* Get an array copy of object
*
* #return array
*/
public function getArrayCopy()
{
return get_object_vars($this);
}
}
?>
and the add Action in my controller:
<?php
use Zend\View\Model\ViewModel;
use Zend\Form\Annotation\AnnotationBuilder;
use Contact\Entity\Contact;
use Contact\Entity\Company;
use Contact\Entity\Message;
use Contact\Controller\EntityUsingController;
class MessageController extends EntityUsingController {
public function addAction(){
$message = new Message();
$builder = new AnnotationBuilder();
$form = $builder->createForm($message);
$form->bind($message);
$request = $this->getRequest();
if ($request->isPost()) {
$form->bind($message);
$requestData = array_merge_recursive((array) $request->getPost(),(array) $request->getFiles());
$form->setData($requestData);
var_dump($request->getFiles());
if ($form->isValid()) {
$em = $this->getEntityManager();
$em->persist($message);
$em->flush();
$this->flashMessenger()->addMessage('Contact Saved');
return $this->redirect()->toRoute('contact');
}
}
return new ViewModel(array(
'form' => $form
));
}
private function storeFile($file){
if (!$this->getConfiguration('fileupload')){
return null;
}
$fileBank = $this->getServiceLocator()->get('FileRepository');
$entity = $fileBank->save('/tmp/myfile.jpg');
}
}
?>
I hope anyone can help my get around this problem.
This seems to be a bug in the annotation builder.
I found a lot of places on the net that confirmed that i should be correct.
so i ended up hacking it by adding the file input after the form was build.
if ($this->getConfiguration('fileupload')){
$companyForm->add(array(
'name' => 'file',
'priority' => 300,
'type' => 'file',
'options' => array(
'label' => 'File:',
),
),array('priority' => 300));
}
checks if the configuration allows for file upload. an extra feature I put in now that I could not set the file upload as an annotation
If you're still interested in another way:
You can try the AllowEmpty annotation:
* #Annotation\AllowEmpty(true)
Or you can try to disable the validator for that field in the controller:
$form->getInputFilter()->remove('file');

Magento 1.6.2 Remove Paypal order statuses

I'm running Magento 1.6.2 and want to remove Paypal order statuses. They are not being used at all and they pollute my order status list. Disabling Paypal does not work.
Magento 1.6.2 does have the nice ability to manage order statuses in the admin, but the Paypal statuses are non-removable.
Is there any way to hard remove them from the database or maybe just hide them somehow?
I can tell you that you don't want to remove them, Mage_Paypal_Model_Info uses them to check if the payment is in review, fraud, processed or completed. I would recommend that you just deal with them. They exist as const for a purpose, even though you may not actually use them but they are used behind the scenes. They do more good than they really do harm.
/**
* Check whether the payment is in review state
*
* #param Mage_Payment_Model_Info $payment
* #return bool
*/
public static function isPaymentReviewRequired(Mage_Payment_Model_Info $payment)
{
$paymentStatus = $payment->getAdditionalInformation(self::PAYMENT_STATUS_GLOBAL);
if (self::PAYMENTSTATUS_PENDING === $paymentStatus) {
$pendingReason = $payment->getAdditionalInformation(self::PENDING_REASON_GLOBAL);
return !in_array($pendingReason, array('authorization', 'order'));
}
return false;
}
/**
* Check whether fraud order review detected and can be reviewed
*
* #param Mage_Payment_Model_Info $payment
* #return bool
*/
public static function isFraudReviewAllowed(Mage_Payment_Model_Info $payment)
{
return self::isPaymentReviewRequired($payment)
&& 1 == $payment->getAdditionalInformation(self::IS_FRAUD_GLOBAL);
}
/**
* Check whether the payment is completed
*
* #param Mage_Payment_Model_Info $payment
* #return bool
*/
public static function isPaymentCompleted(Mage_Payment_Model_Info $payment)
{
$paymentStatus = $payment->getAdditionalInformation(self::PAYMENT_STATUS_GLOBAL);
return self::PAYMENTSTATUS_COMPLETED === $paymentStatus;
}
/**
* Check whether the payment was processed successfully
*
* #param Mage_Payment_Model_Info $payment
* #return bool
*/
public static function isPaymentSuccessful(Mage_Payment_Model_Info $payment)
{
$paymentStatus = $payment->getAdditionalInformation(self::PAYMENT_STATUS_GLOBAL);
if (in_array($paymentStatus, array(
self::PAYMENTSTATUS_COMPLETED, self::PAYMENTSTATUS_INPROGRESS, self::PAYMENTSTATUS_REFUNDED,
self::PAYMENTSTATUS_REFUNDEDPART, self::PAYMENTSTATUS_UNREVERSED, self::PAYMENTSTATUS_PROCESSED,
))) {
return true;
}
$pendingReason = $payment->getAdditionalInformation(self::PENDING_REASON_GLOBAL);
return self::PAYMENTSTATUS_PENDING === $paymentStatus
&& in_array($pendingReason, array('authorization', 'order'));
}
/**
* Check whether the payment was processed unsuccessfully or failed
*
* #param Mage_Payment_Model_Info $payment
* #return bool
*/
public static function isPaymentFailed(Mage_Payment_Model_Info $payment)
{
$paymentStatus = $payment->getAdditionalInformation(self::PAYMENT_STATUS_GLOBAL);
return in_array($paymentStatus, array(
self::PAYMENTSTATUS_DENIED, self::PAYMENTSTATUS_EXPIRED, self::PAYMENTSTATUS_FAILED,
self::PAYMENTSTATUS_REVERSED, self::PAYMENTSTATUS_VOIDED,
));
}
If you look in app/code/core/Mage/Paypal/etc/config.xml you can find this,
<sales>
<order>
<statuses>
<pending_paypal translate="label">
<label>Pending PayPal</label>
</pending_paypal>
</statuses>
</order>
</sales>
but look at app/code/core/Mage/Sales/etc/config.xml
<!-- /**
* #depraceted after 1.4.2, statuses are saved into sales_order_status table
*/
-->
You should look in the sales_order_status table in the database if you are using version after 1.4.2, the only reason they exist in the config.xml to to ensure backwards compatibility.
This is the section that adds the Pending PayPal status, you could comment/delete and have it remove it, but I would recommend that you find out where this status is used before you remove it so that you don't have any unseen conflicts, you can use grep -r 'sales_order_status' * in app/code and lib/ to find anything that may use this table and when it might use Pending PayPal.

Zend check if view exist - class does not work

I have found this class:
https://github.com/lloydwatkin/Demos/blob/master/zendframework/renderifexists/RenderIfExists.php
The code looks like this:
<?php
/**
* View helper to render a view file if it exists
*
* #author Lloyd Watkin
* #since 12/12/2010
* #package Pro
* #subpackage View
*/
/**
* View helper to render a view file if it exists
*
* #author Lloyd Watkin
* #since 12/12/2010
* #package Pro
* #subpackage View
*/
class Pro_View_Helper_RenderIfExists
extends Zend_View_Helper_Abstract
{
/**
* Errors
*
* #var string
*/
const INVALID_FILE = 'Invalid file parameter';
/**
* Holds file name for processing
*
* #var string
*/
protected $_file;
/**
* Takes a products options array and converts to a formatted string
*
* #param string $file
* #return string
*/
public function renderIfExists($file)
{
if (!is_string($file) || empty($file)) {
throw new Zend_View_Exception(self::INVALID_FILE);
}
$this->_file = $file;
if (false === $this->_fileExists()) {
return '';
}
return $this->view->render($file);
}
/**
* Check to see if a view script exists
*
* #return boolean
*/
protected function _fileExists()
{
$paths = $this->view->getScriptPaths();
foreach ($paths as $path) {
if (file_exists($path . $this->_file)) {
return true;
}
}
return false;
}
}
I want to check if a view exists; If it does: Show it.
I have placed the file in my /library/. When I call $this->renderIfExists('info-box.phtml'); from the controller I get this error:
Message: Method "renderIfExists" does not exist and was not trapped in __call()
How can I fix this?
Thanks in advance!
to call a view helper from the controller, you should use:
$this->view->renderIfExists()
bit late to this, but the code you've got above is something I wrote. Have you registered the helper path, if w would the framework know where to load the file?

Resources